-
Notifications
You must be signed in to change notification settings - Fork 511
Support build proto as shared lib on Windows #3714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6e341d0
5df3754
6f25e6b
2122214
51f309e
f1cde89
3df0e30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,8 +174,10 @@ foreach(IMPORT_DIR ${PROTOBUF_IMPORT_DIRS}) | |
| list(APPEND PROTOBUF_INCLUDE_FLAGS "-I${IMPORT_DIR}") | ||
| endforeach() | ||
|
|
||
| set(PROTOBUF_COMMON_FLAGS "--proto_path=${PROTO_PATH}" | ||
| "--cpp_out=${GENERATED_PROTOBUF_PATH}") | ||
| set(PROTOBUF_COMMON_FLAGS | ||
| "--proto_path=${PROTO_PATH}" | ||
| "--cpp_out=dllexport_decl=OPENTELEMETRY_PROTO_API:${GENERATED_PROTOBUF_PATH}" | ||
| ) | ||
| # --experimental_allow_proto3_optional is available from 3.13 and be stable and | ||
| # enabled by default from 3.16 | ||
| if(Protobuf_VERSION AND Protobuf_VERSION VERSION_LESS "3.16") | ||
|
|
@@ -276,13 +278,13 @@ add_custom_command( | |
| DEPENDS ${PROTOBUF_GENERATE_DEPENDS}) | ||
|
|
||
| unset(OTELCPP_PROTO_TARGET_OPTIONS) | ||
| if(CMAKE_SYSTEM_NAME MATCHES "Windows|MinGW|WindowsStore") | ||
| list(APPEND OTELCPP_PROTO_TARGET_OPTIONS STATIC) | ||
| elseif((NOT protobuf_lib_type STREQUAL "STATIC_LIBRARY") | ||
| AND (NOT DEFINED BUILD_SHARED_LIBS OR BUILD_SHARED_LIBS)) | ||
| if((NOT protobuf_lib_type STREQUAL "STATIC_LIBRARY") | ||
| AND (NOT DEFINED BUILD_SHARED_LIBS OR BUILD_SHARED_LIBS)) | ||
| list(APPEND OTELCPP_PROTO_TARGET_OPTIONS SHARED) | ||
| set(OTELCPP_PROTO_LIB_TYPE "SHARED_LIBRARY") | ||
| else() | ||
| list(APPEND OTELCPP_PROTO_TARGET_OPTIONS STATIC) | ||
| set(OTELCPP_PROTO_LIB_TYPE "STATIC_LIBRARY") | ||
| endif() | ||
|
|
||
| set(OPENTELEMETRY_PROTO_TARGETS opentelemetry_proto) | ||
|
|
@@ -299,13 +301,26 @@ add_library( | |
| ${METRICS_SERVICE_PB_CPP_FILE}) | ||
| set_target_version(opentelemetry_proto) | ||
|
|
||
| if(OTELCPP_PROTO_LIB_TYPE STREQUAL "SHARED_LIBRARY") | ||
| project_build_tools_set_shared_library_declaration(OPENTELEMETRY_PROTO_API | ||
| opentelemetry_proto) | ||
| else() | ||
| project_build_tools_set_static_library_declaration(OPENTELEMETRY_PROTO_API | ||
| opentelemetry_proto) | ||
| endif() | ||
|
|
||
| target_include_directories( | ||
| opentelemetry_proto PUBLIC "$<BUILD_INTERFACE:${GENERATED_PROTOBUF_PATH}>" | ||
| "$<INSTALL_INTERFACE:include>") | ||
|
|
||
| # Disable include-what-you-use and clang-tidy on generated code. | ||
| set_target_properties(opentelemetry_proto PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "" | ||
| CXX_CLANG_TIDY "") | ||
| set_target_properties( | ||
| opentelemetry_proto | ||
| PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "" | ||
| CXX_CLANG_TIDY "" | ||
| C_VISIBILITY_PRESET "hidden" | ||
| CXX_VISIBILITY_PRESET "hidden" | ||
| VISIBILITY_INLINES_HIDDEN OFF) | ||
| if(NOT Protobuf_INCLUDE_DIRS AND TARGET protobuf::libprotobuf) | ||
| get_target_property(Protobuf_INCLUDE_DIRS protobuf::libprotobuf | ||
| INTERFACE_INCLUDE_DIRECTORIES) | ||
|
|
@@ -323,10 +338,33 @@ if(WITH_OTLP_GRPC) | |
| ${LOGS_SERVICE_GRPC_PB_CPP_FILE} ${METRICS_SERVICE_GRPC_PB_CPP_FILE}) | ||
| set_target_version(opentelemetry_proto_grpc) | ||
|
|
||
| if(OTELCPP_PROTO_LIB_TYPE STREQUAL "SHARED_LIBRARY") | ||
| if(CMAKE_SYSTEM_NAME MATCHES "Windows|MinGW|WindowsStore") | ||
| # The codes generated by gRPC plugin do not support dll export/import | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gRPC does not seem well supported when built as a windows dll. See https://chromium.googlesource.com/external/github.com/grpc/grpc/+/HEAD/BUILDING.md#windows_a-note-on-building-shared-libs-dlls Should this be something the project tries to support and if so can it be a separate PR? It is unclear if we can/should support gRPC as a windows dll and test it in CI.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’ve reviewed the gRPC-generated code and confirmed it doesn’t contain global variables, so forcing it to build as static libraries should be safe. However, this might confuse users, create many duplicate symbols, and increase linker workload, similar to #3620. We should discuss whether to build the gRPC code as a DLL or keep it as static libraries. I can rarely attend the SIG meeting due to the time zone, so could we discuss this on GitHub or Slack, or could someone share the outcome of the discussion with me afterward? |
||
| # declarations. To work around this, we enable WINDOWS_EXPORT_ALL_SYMBOLS | ||
| # property to export all symbols when building a shared library. | ||
| # TODO: This can be removed once gRPC plugin supports dll export/import. | ||
| set_target_properties(opentelemetry_proto_grpc | ||
| PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Concerned about this - this will increase the DLL size, export internal implementation details, and also potential symbol conflict - better to document these limitations as TODO to revisit in future.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments have been added. We can either use the static otel-cpp libraries directly or enable With static otel-cpp libraries, each linked DLL/EXE gets its own copy of the symbols. Using Once gRPC supports export declarations, we can further optimize this. See also: googleapis/google-cloud-cpp#5849 and grpc/grpc#33032 |
||
| endif() | ||
| endif() | ||
|
|
||
| # Disable include-what-you-use and clang-tidy on generated code. | ||
| # The codes generated by gRPC plugin do not support symbol visibility | ||
| # declarations for public APIs. To work around this, we set visibility | ||
| # to default and disable hidden inline visibility. Otherwise, building | ||
| # a shared library will fail when user changes the default visibility | ||
| # to hidden (e.g., via -fvisibility=hidden compiler flag). | ||
| # TODO: C_VISIBILITY_PRESET, CXX_VISIBILITY_PRESET, and | ||
| # VISIBILITY_INLINES_HIDDEN can be removed once gRPC plugin supports symbol | ||
| # visibility declarations. | ||
| set_target_properties( | ||
| opentelemetry_proto_grpc PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "" | ||
| CXX_CLANG_TIDY "") | ||
| opentelemetry_proto_grpc | ||
| PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "" | ||
| CXX_CLANG_TIDY "" | ||
| C_VISIBILITY_PRESET "default" | ||
| CXX_VISIBILITY_PRESET "default" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting visibility to "default" might export more symbols than intended. Is this intended? If yes, please document as comment why do we need it.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is default value on Unix like system. And this is for users who change the default settings by |
||
| VISIBILITY_INLINES_HIDDEN OFF) | ||
|
|
||
| list(APPEND OPENTELEMETRY_PROTO_TARGETS opentelemetry_proto_grpc) | ||
| target_link_libraries(opentelemetry_proto_grpc PUBLIC opentelemetry_proto) | ||
|
|
@@ -338,7 +376,8 @@ if(WITH_OTLP_GRPC) | |
| # opentelemetry_exporter_otlp_grpc_client as a static library. | ||
| get_target_property(grpc_lib_type gRPC::grpc++ TYPE) | ||
|
|
||
| if(grpc_lib_type STREQUAL "SHARED_LIBRARY") | ||
| if(grpc_lib_type STREQUAL "SHARED_LIBRARY" OR OTELCPP_PROTO_LIB_TYPE STREQUAL | ||
| "SHARED_LIBRARY") | ||
| target_link_libraries(opentelemetry_proto_grpc PUBLIC gRPC::grpc++) | ||
| endif() | ||
| set_target_properties(opentelemetry_proto_grpc PROPERTIES EXPORT_NAME | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.