Skip to content
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

[BUILD] Allow shared opentelemetry_proto on non-Windows platform. #2097

Merged
merged 13 commits into from
May 17, 2023
Merged
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Increment the:
[#2123](https://github.com/open-telemetry/opentelemetry-cpp/pull/2123)
* [BUILD] Build break with old curl, macro CURL_VERSION_BITS unknown
[#2102](https://github.com/open-telemetry/opentelemetry-cpp/pull/2102)
* [BUILD] Allow build shared opentelemetry_proto on non-Windows platform.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should mentioned this PR potential breaking change here in changelog, as we have are introducing a new library?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should mentioned this PR potential breaking change here in changelog, as we have are introducing a new library?
Sure, the changelog is added now.

Just curious the motive of this change - was there any build error with WITH_ABSEIL?

Yes, the related CI job is here https://github.com/open-telemetry/opentelemetry-cpp/actions/runs/4707416429/jobs/8349260349 .

[#2097](https://github.com/open-telemetry/opentelemetry-cpp/pull/2097)
* [API] Add user facing Logging API and Benchmarks
[#2094](https://github.com/open-telemetry/opentelemetry-cpp/pull/2094)

Expand Down
73 changes: 47 additions & 26 deletions cmake/opentelemetry-proto.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -229,31 +229,40 @@ endif()

include_directories("${GENERATED_PROTOBUF_PATH}")

if(WITH_OTLP_GRPC)
add_library(
opentelemetry_proto STATIC
${COMMON_PB_CPP_FILE}
${RESOURCE_PB_CPP_FILE}
${TRACE_PB_CPP_FILE}
${LOGS_PB_CPP_FILE}
${METRICS_PB_CPP_FILE}
${TRACE_SERVICE_PB_CPP_FILE}
${TRACE_SERVICE_GRPC_PB_CPP_FILE}
${LOGS_SERVICE_PB_CPP_FILE}
${LOGS_SERVICE_GRPC_PB_CPP_FILE}
${METRICS_SERVICE_PB_CPP_FILE}
${METRICS_SERVICE_GRPC_PB_CPP_FILE})
unset(OTELCPP_PROTO_TARGET_OPTIONS)
if(CMAKE_SYSTEM_NAME MATCHES "Windows|MinGW|WindowsStore")
list(APPEND OTELCPP_PROTO_TARGET_OPTIONS STATIC)
elseif(NOT DEFINED BUILD_SHARED_LIBS OR BUILD_SHARED_LIBS)
list(APPEND OTELCPP_PROTO_TARGET_OPTIONS SHARED)
else()
list(APPEND OTELCPP_PROTO_TARGET_OPTIONS STATIC)
endif()

set(OPENTELEMETRY_PROTO_TARGETS opentelemetry_proto)
add_library(
opentelemetry_proto
${OTELCPP_PROTO_TARGET_OPTIONS}
${COMMON_PB_CPP_FILE}
${RESOURCE_PB_CPP_FILE}
${TRACE_PB_CPP_FILE}
${LOGS_PB_CPP_FILE}
${METRICS_PB_CPP_FILE}
${TRACE_SERVICE_PB_CPP_FILE}
${LOGS_SERVICE_PB_CPP_FILE}
${METRICS_SERVICE_PB_CPP_FILE})

if(WITH_OTLP_GRPC)
add_library(
opentelemetry_proto STATIC
${COMMON_PB_CPP_FILE}
${RESOURCE_PB_CPP_FILE}
${TRACE_PB_CPP_FILE}
${LOGS_PB_CPP_FILE}
${METRICS_PB_CPP_FILE}
${TRACE_SERVICE_PB_CPP_FILE}
${LOGS_SERVICE_PB_CPP_FILE}
${METRICS_SERVICE_PB_CPP_FILE})
opentelemetry_proto_grpc
${OTELCPP_PROTO_TARGET_OPTIONS} ${TRACE_SERVICE_GRPC_PB_CPP_FILE}
${LOGS_SERVICE_GRPC_PB_CPP_FILE} ${METRICS_SERVICE_GRPC_PB_CPP_FILE})

list(APPEND OPENTELEMETRY_PROTO_TARGETS opentelemetry_proto_grpc)
target_link_libraries(opentelemetry_proto_grpc PUBLIC opentelemetry_proto)

set_target_properties(opentelemetry_proto_grpc PROPERTIES EXPORT_NAME
proto_grpc)
patch_protobuf_targets(opentelemetry_proto_grpc)
endif()

if(needs_proto_download)
Expand All @@ -264,7 +273,7 @@ patch_protobuf_targets(opentelemetry_proto)

if(OPENTELEMETRY_INSTALL)
install(
TARGETS opentelemetry_proto
TARGETS ${OPENTELEMETRY_PROTO_TARGETS}
EXPORT "${PROJECT_NAME}-target"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand All @@ -282,9 +291,21 @@ if(TARGET protobuf::libprotobuf)
else() # cmake 3.8 or lower
target_include_directories(opentelemetry_proto
PUBLIC ${Protobuf_INCLUDE_DIRS})
target_link_libraries(opentelemetry_proto INTERFACE ${Protobuf_LIBRARIES})
target_link_libraries(opentelemetry_proto PUBLIC ${Protobuf_LIBRARIES})
endif()

if(WITH_OTLP_GRPC)
if(WITH_ABSEIL)
find_package(absl CONFIG)
if(TARGET absl::synchronization)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the target absl::synchronization optional, or error out if it doesn't exist?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if absl::synchronization can be turn off.I'm not familar with abseil-cpp.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious the motive of this change - was there any build error with WITH_ABSEIL?

target_link_libraries(opentelemetry_proto_grpc
PRIVATE absl::synchronization)
endif()
endif()
endif()

if(BUILD_SHARED_LIBS)
set_property(TARGET opentelemetry_proto PROPERTY POSITION_INDEPENDENT_CODE ON)
foreach(proto_target ${OPENTELEMETRY_PROTO_TARGETS})
set_property(TARGET ${proto_target} PROPERTY POSITION_INDEPENDENT_CODE ON)
endforeach()
endif()
18 changes: 12 additions & 6 deletions exporters/otlp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ target_include_directories(
"$<INSTALL_INTERFACE:include>")

set(OPENTELEMETRY_OTLP_TARGETS opentelemetry_otlp_recordable)
target_link_libraries(
opentelemetry_otlp_recordable
PUBLIC opentelemetry_trace opentelemetry_resources opentelemetry_proto)

if(WITH_LOGS_PREVIEW)
target_link_libraries(opentelemetry_otlp_recordable PUBLIC opentelemetry_logs)
Expand All @@ -34,13 +31,18 @@ if(WITH_OTLP_GRPC)
PROPERTIES EXPORT_NAME otlp_grpc_client)
set_target_version(opentelemetry_exporter_otlp_grpc_client)

# Because opentelemetry_proto_grpc depends on gRPC, and gRPC can only be
# linked in one dynamic library or executable (otherwise, there may be
# conflicts with some global variables in certain versions of gRPC), we have
# switched the link for opentelemetry_exporter_otlp_grpc_client into all
# targets that depend on opentelemetry_proto_grpc.
target_link_libraries(
opentelemetry_exporter_otlp_grpc_client
PUBLIC opentelemetry_sdk opentelemetry_common opentelemetry_ext
opentelemetry_proto)
# gRPC::grpc++ must be linked before opentelemetry_proto_grpc.
opentelemetry_proto_grpc
PRIVATE gRPC::grpc++)

target_link_libraries(opentelemetry_exporter_otlp_grpc_client
PRIVATE gRPC::grpc++)
get_target_property(GRPC_INCLUDE_DIRECTORY gRPC::grpc++
INTERFACE_INCLUDE_DIRECTORIES)
if(GRPC_INCLUDE_DIRECTORY)
Expand Down Expand Up @@ -174,6 +176,10 @@ if(WITH_OTLP_HTTP)
opentelemetry_exporter_otlp_http_metric)
endif()

target_link_libraries(
opentelemetry_otlp_recordable
PUBLIC opentelemetry_trace opentelemetry_resources opentelemetry_proto)

if(OPENTELEMETRY_INSTALL)
install(
TARGETS ${OPENTELEMETRY_OTLP_TARGETS}
Expand Down