[opentelemetry-cpp] unvendor absl polyfills (#30720)

* [opentelemetry-cpp] unvendor absl polyfills

By default opentelemetry vendors-in a copy of some Abseil polyfills
(e.g. `absl::variant`). That makes it hard (I would claim nearly
impossible) to use both the abseil and the opentelemetry-cpp ports at
the same time, as both define `absl::variant` in some of their headers.

It seems better to always use the `-DHAVE_ABSEIL=ON` CMake option and
depend on the abseil port.  Outside vcpkg it may be useful to use such
vendored-in copies of the code, as that "simplifies" dependency
management. In the context of vcpkg that is just wasteful.

Simplified how to support `abseil[cxx17]` by removing some code in
opentelemetry that forcibly downgraded the compiler to use C++11. Add a
missing dependency for gRPC generated code. This code indirectly depends
on Abseil too.

* Opentelemetry is missing a find_dependency() when -DHAVE_ABSEIL=ON
This commit is contained in:
Carlos O'Ryan 2023-04-10 15:50:22 -04:00 committed by GitHub
parent 45b0e4b585
commit 43401f5835
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 71 additions and 19 deletions

View File

@ -0,0 +1,15 @@
diff --git a/cmake/opentelemetry-proto.cmake b/cmake/opentelemetry-proto.cmake
index 1aa1ba0..10e2f58 100644
--- a/cmake/opentelemetry-proto.cmake
+++ b/cmake/opentelemetry-proto.cmake
@@ -285,6 +285,10 @@ else() # cmake 3.8 or lower
target_link_libraries(opentelemetry_proto INTERFACE ${Protobuf_LIBRARIES})
endif()
+if(TARGET gRPC::grpc++)
+ target_link_libraries(opentelemetry_proto PUBLIC gRPC::grpc++)
+endif()
+
if(BUILD_SHARED_LIBS)
set_property(TARGET opentelemetry_proto PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()

View File

@ -0,0 +1,12 @@
diff --git a/cmake/opentelemetry-cpp-config.cmake.in b/cmake/opentelemetry-cpp-config.cmake.in
index adae58d..21baab7 100644
--- a/cmake/opentelemetry-cpp-config.cmake.in
+++ b/cmake/opentelemetry-cpp-config.cmake.in
@@ -69,6 +69,7 @@ set(OPENTELEMETRY_VERSION
# ##############################################################################
find_package(Threads)
+find_dependency(absl)
set_and_check(OPENTELEMETRY_CPP_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIR@")
set_and_check(OPENTELEMETRY_CPP_LIBRARY_DIRS "@PACKAGE_CMAKE_INSTALL_LIBDIR@")

View File

@ -9,7 +9,15 @@ vcpkg_from_github(
SHA512 eb7dde38134fd9f51f22a2288a3a1db9eeec3dce3889c02fea82e20738a697449be73d632c3d1889ff159f0274d57bfd066db506149b221fe6ced8f18fdc1237
HEAD_REF main
PATCHES
support_absl_cxx17.patch
# Use the compiler's default C++ version. Picking a version with
# CMAKE_CXX_STANDARD is not needed as the Abseil port already picked
# one and propagates that version across all its downstream deps.
use-default-cxx-version.patch
# When compiling code generated by gRPC we need to link the gRPC library
# too.
add-missing-dependencies.patch
# Missing find_dependency for Abseil
add-missing-find-dependency.patch
)
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
@ -49,6 +57,7 @@ vcpkg_cmake_configure(
-DWITH_EXAMPLES=OFF
-DWITH_LOGS_PREVIEW=ON
-DOPENTELEMETRY_INSTALL=ON
-DWITH_ABSEIL=ON
${FEATURE_OPTIONS}
)

View File

@ -1,16 +0,0 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9df8f5ca..f68830cc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -344,6 +344,11 @@ if(WITH_OTLP)
endif()
include(CMakeDependentOption)
+ if (ABSL_USE_CXX17)
+ message(STATUS "Found absl uses CXX17, enable CXX17 feature.")
+ set(CMAKE_CXX_STANDARD 17)
+ set(WITH_STL ON)
+ endif()
cmake_dependent_option(
WITH_OTLP_GRPC "Whether to include the OTLP gRPC exporter in the SDK" ON
"gRPC_FOUND" OFF)

View File

@ -0,0 +1,26 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f4fa064..a868106 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -126,21 +126,6 @@ endif()
option(OPENTELEMETRY_INSTALL "Whether to install opentelemetry targets"
${OPENTELEMETRY_INSTALL_default})
-if(NOT DEFINED CMAKE_CXX_STANDARD)
- if(WITH_STL)
- # Require at least C++17. C++20 is needed to avoid gsl::span
- if(CMAKE_VERSION VERSION_GREATER 3.11.999)
- # Ask for 20, may get anything below
- set(CMAKE_CXX_STANDARD 20)
- else()
- # Ask for 17, may get anything below
- set(CMAKE_CXX_STANDARD 17)
- endif()
- else()
- set(CMAKE_CXX_STANDARD 11)
- endif()
-endif()
-
if(WITH_STL)
# These definitions are needed for test projects that do not link against
# opentelemetry-api library directly. We ensure that variant implementation

View File

@ -2,7 +2,7 @@
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
"name": "opentelemetry-cpp",
"version-semver": "1.8.3",
"port-version": 2,
"port-version": 3,
"description": [
"OpenTelemetry is a collection of tools, APIs, and SDKs.",
"You use it to instrument, generate, collect, and export telemetry data (metrics, logs, and traces) for analysis in order to understand your software's performance and behavior."
@ -10,6 +10,7 @@
"homepage": "https://github.com/open-telemetry/opentelemetry-cpp",
"license": "Apache-2.0",
"dependencies": [
"abseil",
"curl",
"nlohmann-json",
{

View File

@ -5882,7 +5882,7 @@
},
"opentelemetry-cpp": {
"baseline": "1.8.3",
"port-version": 2
"port-version": 3
},
"opentracing": {
"baseline": "1.6.0",

View File

@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "ce4bc10a4f0ebad5cafd14de836017b281cba1f9",
"version-semver": "1.8.3",
"port-version": 3
},
{
"git-tree": "152ee0a0f79c1fc26d81291c9d1eb0417f9deeeb",
"version-semver": "1.8.3",