Minimal changes to expose DLL entry points on Windows

pull/35484/head
David Chamberlin 12 months ago
parent 20e5b2c4bb
commit f8f244da99
  1. 4940
      CMakeLists.txt
  2. 2
      include/grpcpp/support/proto_buffer_reader.h
  3. 1
      src/core/lib/event_engine/windows/grpc_polled_fd_windows.cc
  4. 103
      templates/CMakeLists.txt.template

4940
CMakeLists.txt generated

File diff suppressed because it is too large Load Diff

@ -148,7 +148,7 @@ class ProtoBufferReader : public grpc::protobuf::io::ZeroCopyInputStream {
*slice(), GRPC_SLICE_LENGTH(*slice()) - backup_count(),
GRPC_SLICE_LENGTH(*slice()) - backup_count() + count)));
}
int64_t take = std::min(backup_count(), static_cast<int64_t>(count));
int64_t take = (std::min)(backup_count(), static_cast<int64_t>(count));
set_backup_count(backup_count() - take);
count -= take;
if (count == 0) {

@ -24,6 +24,7 @@
#include "absl/functional/any_invocable.h"
#include "absl/status/status.h"
#include "absl/strings/str_format.h"
#include <grpc/support/log_windows.h>

@ -29,6 +29,11 @@
third_party_proto_prefixes = {lib.proto_prefix for lib in external_proto_libraries}
gpr_libs = ['gpr']
grpc_libs = ['grpc', 'grpc_unsecure']
grpcxx_libs = ['grpc++', 'grpc++_unsecure']
protoc_libs = ['benchmark_helpers', 'grpc++_reflection', 'grpcpp_channelz']
def third_party_proto_import_path(path):
"""Removes third_party prefix to match ProtoBuf's relative import path."""
for prefix in third_party_proto_prefixes:
@ -158,7 +163,7 @@
return ' SHARED'
# upb always compiles as a static library on Windows
elif lib_name in ['upb','upb_collections_lib','upb_json_lib','upb_textformat_lib']:
elif lib_name in ['upb','upb_collections_lib','upb_json_lib','upb_textformat_lib'] + protoc_libs:
return ' ${_gRPC_STATIC_WIN32}'
else:
@ -192,6 +197,19 @@
deps.append(d)
return deps
def get_all_deps(target_dict, all_libs):
ret = set()
get_all_deps_recurse(target_dict, all_libs, ret)
return ret
def get_all_deps_recurse(target_dict, all_libs, all_deps):
for d in target_dict.get('deps', []):
if not d in all_deps:
all_deps.add(d)
for other_lib in all_libs:
if other_lib.name == d:
get_all_deps_recurse(other_lib, all_libs, all_deps)
def is_generate_cmake_target(lib_or_target):
"""Returns True if a cmake target should be generated for given library/target."""
# TODO(jtattermusch): extract the metadata to a centralized location.
@ -250,12 +268,6 @@
return '\n'.join(lines)
return _func
def add_dll_annotation_macros(lib, prefix):
return """set_target_properties(%s PROPERTIES DEFINE_SYMBOL "%s_DLL_EXPORTS")
if(BUILD_SHARED_LIBS)
target_compile_definitions(%s INTERFACE %s_DLL_IMPORTS)
endif()""" % (lib, prefix, lib, prefix)
%>
<%
# These files are added to a set so that they are not duplicated if multiple
@ -286,6 +298,10 @@
set(PACKAGE_BUGREPORT "https://github.com/grpc/grpc/issues/")
project(<%text>${PACKAGE_NAME}</%text> LANGUAGES C CXX)
if(BUILD_SHARED_LIBS AND MSVC)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()
set(gRPC_INSTALL_BINDIR "bin" CACHE STRING "Installation directory for executables")
set(gRPC_INSTALL_LIBDIR "lib" CACHE STRING "Installation directory for libraries")
set(gRPC_INSTALL_INCLUDEDIR "include" CACHE STRING "Installation directory for headers")
@ -410,6 +426,8 @@
set(_gRPC_C_CXX_FLAGS "<%text>${_gRPC_C_CXX_FLAGS}</%text> /wd4503")
# Tell MSVC to build grpc using utf-8
set(_gRPC_C_CXX_FLAGS "<%text>${_gRPC_C_CXX_FLAGS}</%text> /utf-8")
# Inconsistent object sizes can cause stack corruption and should be treated as an error
set(_gRPC_C_CXX_FLAGS "<%text>${_gRPC_C_CXX_FLAGS}</%text> /we4789")
endif()
if (MINGW)
add_definitions(-D_WIN32_WINNT=0x600)
@ -517,7 +535,7 @@
# Currently for shared lib on Windows (i.e. a DLL) certain bits of source code
# are generated from protobuf definitions by upbc. This source code does not include
# annotations needed to export these functions from gprc.lib so we have to
# annotations needed to export these functions from grpc.lib so we have to
# re-include a small subset of these.
#
# This is not an ideal situation because these functions will be unavailable
@ -530,9 +548,18 @@
src/core/ext/upb-gen/src/proto/grpc/health/v1/health.upb_minitable.c
src/core/ext/upb-gen/src/proto/grpc/gcp/transport_security_common.upb_minitable.c
)
set(gRPC_ADDITIONAL_DLL_SRC
src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.cc
src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc
src/core/lib/security/credentials/tls/grpc_tls_certificate_verifier.cc
src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc
)
set(gRPC_ADDITIONAL_DLL_CXX_SRC
src/cpp/common/tls_certificate_provider.cc
src/cpp/common/tls_certificate_verifier.cc
src/cpp/common/tls_credentials_options.cc
)
endif() # BUILD_SHARED_LIBS AND WIN32
@ -792,10 +819,13 @@
% endif
% endfor
% if lib.name in ['grpc++_alts', 'grpc++_unsecure', 'grpc++']:
${'${gRPC_UPB_GEN_DUPL_SRC}'}
<%text>${gRPC_UPB_GEN_DUPL_SRC}</%text>
% endif
% if lib.name in ['grpc_unsecure']:
${'${gRPC_ADDITIONAL_DLL_SRC}'}
<%text>${gRPC_ADDITIONAL_DLL_SRC}</%text>
% endif
% if lib.name in ['grpc++_unsecure']:
<%text>${gRPC_ADDITIONAL_DLL_CXX_SRC}</%text>
% endif
)
@ -814,17 +844,30 @@
if(WIN32 AND MSVC)
set_target_properties(${lib.name} PROPERTIES COMPILE_PDB_NAME "${lib.name}"
COMPILE_PDB_OUTPUT_DIRECTORY <%text>"${CMAKE_BINARY_DIR}</%text>"
)<%
dll_annotations = []
if lib.name in gpr_libs:
dll_annotations.append("GPR_DLL_EXPORTS")
if lib.name in grpc_libs:
dll_annotations.append("GRPC_DLL_EXPORTS")
if lib.name in grpcxx_libs:
dll_annotations.append("GRPCXX_DLL_EXPORTS")
if set(gpr_libs) & set(get_all_deps(lib, libs)):
dll_annotations.append("GPR_DLL_IMPORTS")
if set(grpc_libs) & set(get_all_deps(lib, libs)):
dll_annotations.append("GRPC_DLL_IMPORTS")
if set(grpcxx_libs) & set(get_all_deps(lib, libs)):
dll_annotations.append("GRPCXX_DLL_IMPORTS")
%>
% if dll_annotations:
if(BUILD_SHARED_LIBS)
target_compile_definitions(${lib.name}
PRIVATE
% for definition in dll_annotations:
"${definition}"
% endfor
)
% if lib.name == 'gpr':
${add_dll_annotation_macros(lib.name, 'GPR')}
% elif lib.name == 'grpc':
${add_dll_annotation_macros(lib.name, 'GRPC')}
% elif lib.name == 'grpc_unsecure':
${add_dll_annotation_macros(lib.name, 'GRPC')}
% elif lib.name == 'grpc++':
${add_dll_annotation_macros(lib.name, 'GRPCXX')}
% elif lib.name == 'grpc++_unsecure':
${add_dll_annotation_macros(lib.name, 'GRPCXX')}
endif()
% endif
if(gRPC_INSTALL)
install(FILES <%text>${CMAKE_CURRENT_BINARY_DIR}/</%text>${lib.name}.pdb
@ -907,8 +950,28 @@
${proto_replace_ext(src, '.pb.h')}
${proto_replace_ext(src, '.grpc.pb.h')}
% endif
% endfor
)<%
dll_annotations = []
if set(gpr_libs) & set(get_all_deps(tgt, libs)):
dll_annotations.append("GPR_DLL_IMPORTS")
if set(grpc_libs) & set(get_all_deps(tgt, libs)):
dll_annotations.append("GRPC_DLL_IMPORTS")
if set(grpcxx_libs) & set(get_all_deps(tgt, libs)):
dll_annotations.append("GRPCXX_DLL_IMPORTS")
%>
% if dll_annotations:
if(WIN32 AND MSVC)
if(BUILD_SHARED_LIBS)
target_compile_definitions(${tgt.name}
PRIVATE
% for definition in dll_annotations:
"${definition}"
% endfor
)
endif()
endif()
% endif
target_compile_features(${tgt.name} PUBLIC cxx_std_14)
target_include_directories(${tgt.name}
PRIVATE

Loading…
Cancel
Save