Skip to content

Commit

Permalink
Support protobuf 3.22 or upper (#2163)
Browse files Browse the repository at this point in the history
  • Loading branch information
owent authored Aug 11, 2023
1 parent b7fd057 commit 0d1326a
Show file tree
Hide file tree
Showing 23 changed files with 895 additions and 164 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ jobs:
env:
CC: /usr/bin/gcc-4.8
CXX: /usr/bin/g++-4.8
CXX_STANDARD: '11'
run: ./ci/do_ci.sh cmake.legacy.test

cmake_gcc_48_otlp_exporter_test:
Expand Down Expand Up @@ -329,8 +330,12 @@ jobs:
sudo -E ./ci/setup_ci_environment.sh
sudo -E ./ci/setup_cmake.sh
- name: run tests
env:
CXX_STANDARD: '20'
run: ./ci/do_ci.sh cmake.c++20.test
- name: run tests (enable stl)
env:
CXX_STANDARD: '20'
run: ./ci/do_ci.sh cmake.c++20.stl.test

cmake_test_cxx20_clang:
Expand All @@ -354,12 +359,14 @@ jobs:
CC: /usr/bin/clang
CXX: /usr/bin/clang++
CXXFLAGS: "-stdlib=libc++"
CXX_STANDARD: '20'
run: ./ci/do_ci.sh cmake.c++20.test
- name: run tests (enable stl)
env:
CC: /usr/bin/clang
CXX: /usr/bin/clang++
CXXFLAGS: "-stdlib=libc++"
CXX_STANDARD: '20'
run: ./ci/do_ci.sh cmake.c++20.stl.test

cmake_otprotocol_test:
Expand All @@ -378,6 +385,31 @@ jobs:
sudo ./ci/setup_grpc.sh
./ci/do_ci.sh cmake.exporter.otprotocol.test
cmake_modern_protobuf_grpc_with_abseil_test:
name: CMake test (with modern protobuf,grpc and abseil)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: setup
env:
PROTOBUF_VERSION: '23.3'
ABSEIL_CPP_VERSION: '20230125.3'
CXX_STANDARD: '14'
run: |
sudo ./ci/setup_cmake.sh
sudo ./ci/setup_ci_environment.sh
sudo -E ./ci/install_abseil.sh
sudo -E ./ci/install_protobuf.sh
- name: run otlp exporter tests
env:
WITH_ABSEIL: 'ON'
CXX_STANDARD: '14'
run: |
sudo -E ./ci/setup_grpc.sh -m -p protobuf -p abseil-cpp
./ci/do_ci.sh cmake.exporter.otprotocol.test
cmake_do_not_install_test:
name: CMake do not install test (with otlp-exporter)
runs-on: ubuntu-20.04
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Increment the:

## [Unreleased]

* [EXPORTER] Support protobuf 3.22 or upper
[#2163](https://github.com/open-telemetry/opentelemetry-cpp/pull/2163)
* [SDK] Mark logs signal as stable API/SDK
[#2229](https://github.com/open-telemetry/opentelemetry-cpp/pull/2229)

Expand Down
55 changes: 45 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ project(opentelemetry-cpp)
# Mark variables as used so cmake doesn't complain about them
mark_as_advanced(CMAKE_TOOLCHAIN_FILE)

# Prefer cmake CONFIG to auto resolve dependencies.
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)

# Don't use customized cmake modules if vcpkg is used to resolve dependence.
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/")
Expand Down Expand Up @@ -125,6 +128,8 @@ endif()
option(OPENTELEMETRY_INSTALL "Whether to install opentelemetry targets"
${OPENTELEMETRY_INSTALL_default})

include("${PROJECT_SOURCE_DIR}/cmake/tools.cmake")

if(NOT DEFINED CMAKE_CXX_STANDARD)
if(WITH_STL)
# Require at least C++17. C++20 is needed to avoid gsl::span
Expand Down Expand Up @@ -340,9 +345,21 @@ if(WITH_PROMETHEUS)
endif()
endif()

if(WITH_ABSEIL)
find_package(absl CONFIG REQUIRED)
endif()

if(WITH_OTLP_GRPC OR WITH_OTLP_HTTP)
set(protobuf_MODULE_COMPATIBLE ON)
find_package(Protobuf)
if(Protobuf_VERSION AND Protobuf_VERSION VERSION_GREATER_EQUAL "3.22.0")
if(NOT WITH_ABSEIL)
message(
FATAL_ERROR
"Protobuf 3.22 or upper require abseil-cpp(Recommended version: 20230125 or upper)"
)
endif()
endif()

if(WITH_OTLP_GRPC)
find_package(gRPC)
endif()
Expand Down Expand Up @@ -372,10 +389,14 @@ if(WITH_OTLP_GRPC OR WITH_OTLP_HTTP)
)
endif()
endif()
# Latest Protobuf uses mixed case instead of uppercase
if(Protobuf_PROTOC_EXECUTABLE)
set(PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE})
endif()
endif()
# Latest Protobuf imported targets and without legacy module support
if(TARGET protobuf::protoc)
project_build_tools_get_imported_location(PROTOBUF_PROTOC_EXECUTABLE
protobuf::protoc)
elseif(Protobuf_PROTOC_EXECUTABLE)
# Some versions of FindProtobuf.cmake uses mixed case instead of uppercase
set(PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE})
endif()
include(CMakeDependentOption)

Expand Down Expand Up @@ -524,10 +545,14 @@ if(BUILD_TESTING)
set(GTEST_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/third_party/googletest/googletest/include
${CMAKE_CURRENT_SOURCE_DIR}/third_party/googletest/googlemock/include)
set(GTEST_BOTH_LIBRARIES
${CMAKE_BINARY_DIR}/lib/libgtest.a
${CMAKE_BINARY_DIR}/lib/libgtest_main.a
${CMAKE_BINARY_DIR}/lib/libgmock.a)
if(TARGET gtest)
set(GTEST_BOTH_LIBRARIES gtest gtest_main gmock)
else()
set(GTEST_BOTH_LIBRARIES
${CMAKE_BINARY_DIR}/lib/libgtest.a
${CMAKE_BINARY_DIR}/lib/libgtest_main.a
${CMAKE_BINARY_DIR}/lib/libgmock.a)
endif()
elseif(WIN32)
# Make sure we are always bootsrapped with vcpkg on Windows
find_package(GTest)
Expand All @@ -540,7 +565,17 @@ if(BUILD_TESTING)
# Prefer GTest installed by OS distro, brew or vcpkg package manager
find_package(GTest REQUIRED)
endif()
include_directories(SYSTEM ${GTEST_INCLUDE_DIRS})
if(NOT GTEST_BOTH_LIBRARIES)
# New GTest package names
if(TARGET GTest::gtest)
set(GTEST_BOTH_LIBRARIES GTest::gtest GTest::gtest_main GTest::gmock)
elseif(TARGET GTest::GTest)
set(GTEST_BOTH_LIBRARIES GTest::GTest GTest::Main)
endif()
endif()
if(GTEST_INCLUDE_DIRS)
include_directories(SYSTEM ${GTEST_INCLUDE_DIRS})
endif()
message("GTEST_INCLUDE_DIRS = ${GTEST_INCLUDE_DIRS}")
message("GTEST_BOTH_LIBRARIES = ${GTEST_BOTH_LIBRARIES}")
enable_testing()
Expand Down
1 change: 1 addition & 0 deletions api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ cc_library(
deps = select({
":with_external_abseil": [
"@com_google_absl//absl/base",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:variant",
],
"//conditions:default": [],
Expand Down
2 changes: 0 additions & 2 deletions api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ endif()

if(WITH_ABSEIL)

find_package(absl CONFIG REQUIRED)

target_compile_definitions(opentelemetry_api INTERFACE HAVE_ABSEIL)
target_link_libraries(
opentelemetry_api INTERFACE absl::bad_variant_access absl::any absl::base
Expand Down
60 changes: 28 additions & 32 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,19 @@ BAZEL_MACOS_TEST_OPTIONS="$BAZEL_MACOS_OPTIONS --test_output=errors"

BAZEL_STARTUP_OPTIONS="--output_user_root=$HOME/.cache/bazel"

CMAKE_OPTIONS=(-DCMAKE_BUILD_TYPE=Debug)
if [ ! -z "${CXX_STANDARD}" ]; then
CMAKE_OPTIONS=(${CMAKE_OPTIONS[@]} "-DCMAKE_CXX_STANDARD=${CXX_STANDARD}")
else
CMAKE_OPTIONS=(${CMAKE_OPTIONS[@]} "-DCMAKE_CXX_STANDARD=14")
fi

export CTEST_OUTPUT_ON_FAILURE=1

if [[ "$1" == "cmake.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_STANDARD=14 \
cmake ${CMAKE_OPTIONS[@]} \
-DWITH_PROMETHEUS=ON \
-DWITH_ZIPKIN=ON \
-DWITH_ELASTICSEARCH=ON \
Expand All @@ -102,8 +108,7 @@ if [[ "$1" == "cmake.test" ]]; then
elif [[ "$1" == "cmake.maintainer.sync.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_STANDARD=14 \
cmake ${CMAKE_OPTIONS[@]} \
-DWITH_OTLP_HTTP=ON \
-DWITH_OTLP_HTTP_SSL_PREVIEW=ON \
-DWITH_OTLP_HTTP_SSL_TLS_PREVIEW=ON \
Expand All @@ -126,8 +131,7 @@ elif [[ "$1" == "cmake.maintainer.sync.test" ]]; then
elif [[ "$1" == "cmake.maintainer.async.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_STANDARD=14 \
cmake ${CMAKE_OPTIONS[@]} \
-DWITH_OTLP_HTTP=ON \
-DWITH_OTLP_HTTP_SSL_PREVIEW=ON \
-DWITH_OTLP_HTTP_SSL_TLS_PREVIEW=ON \
Expand All @@ -150,7 +154,7 @@ elif [[ "$1" == "cmake.maintainer.async.test" ]]; then
elif [[ "$1" == "cmake.maintainer.cpp11.async.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
cmake ${CMAKE_OPTIONS[@]} \
-DCMAKE_CXX_STANDARD=11 \
-DWITH_OTLP_HTTP=ON \
-DWITH_OTLP_HTTP_SSL_PREVIEW=ON \
Expand All @@ -173,8 +177,7 @@ elif [[ "$1" == "cmake.maintainer.cpp11.async.test" ]]; then
elif [[ "$1" == "cmake.with_async_export.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_STANDARD=14 \
cmake ${CMAKE_OPTIONS[@]} \
-DWITH_PROMETHEUS=ON \
-DWITH_ZIPKIN=ON \
-DWITH_ELASTICSEARCH=ON \
Expand All @@ -188,8 +191,7 @@ elif [[ "$1" == "cmake.with_async_export.test" ]]; then
elif [[ "$1" == "cmake.abseil.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_STANDARD=14 \
cmake ${CMAKE_OPTIONS[@]} \
-DWITH_METRICS_EXEMPLAR_PREVIEW=ON \
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
Expand All @@ -201,8 +203,7 @@ elif [[ "$1" == "cmake.abseil.test" ]]; then
elif [[ "$1" == "cmake.opentracing_shim.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_STANDARD=14 \
cmake ${CMAKE_OPTIONS[@]} \
-DCMAKE_CXX_FLAGS="-Werror -Wno-error=redundant-move $CXXFLAGS" \
-DWITH_OPENTRACING=ON \
"${SRC_DIR}"
Expand All @@ -212,8 +213,7 @@ elif [[ "$1" == "cmake.opentracing_shim.test" ]]; then
elif [[ "$1" == "cmake.c++20.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_STANDARD=20 \
cmake ${CMAKE_OPTIONS[@]} \
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
${IWYU} \
Expand All @@ -224,8 +224,7 @@ elif [[ "$1" == "cmake.c++20.test" ]]; then
elif [[ "$1" == "cmake.c++20.stl.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_STANDARD=20 \
cmake ${CMAKE_OPTIONS[@]} \
-DWITH_METRICS_EXEMPLAR_PREVIEW=ON \
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
Expand All @@ -240,8 +239,7 @@ elif [[ "$1" == "cmake.legacy.test" ]]; then
rm -rf *
export BUILD_ROOT="${BUILD_DIR}"
${SRC_DIR}/tools/build-benchmark.sh
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_STANDARD=11 \
cmake ${CMAKE_OPTIONS[@]} \
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
"${SRC_DIR}"
make -j $(nproc)
Expand All @@ -252,7 +250,7 @@ elif [[ "$1" == "cmake.legacy.exporter.otprotocol.test" ]]; then
rm -rf *
export BUILD_ROOT="${BUILD_DIR}"
${SRC_DIR}/tools/build-benchmark.sh
cmake -DCMAKE_BUILD_TYPE=Debug \
cmake ${CMAKE_OPTIONS[@]} \
-DCMAKE_CXX_STANDARD=11 \
-DWITH_OTLP_GRPC=ON \
-DWITH_OTLP_HTTP=ON \
Expand All @@ -267,8 +265,10 @@ elif [[ "$1" == "cmake.legacy.exporter.otprotocol.test" ]]; then
elif [[ "$1" == "cmake.exporter.otprotocol.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_STANDARD=14 \
if [[ ! -z "${WITH_ABSEIL}" ]]; then
CMAKE_OPTIONS=(${CMAKE_OPTIONS[@]} "-DWITH_ABSEIL=${WITH_ABSEIL}")
fi
cmake ${CMAKE_OPTIONS[@]} \
-DWITH_OTLP_GRPC=ON \
-DWITH_OTLP_HTTP=ON \
-DWITH_OTLP_GRPC_SSL_MTLS_PREVIEW=ON \
Expand All @@ -282,8 +282,7 @@ elif [[ "$1" == "cmake.exporter.otprotocol.test" ]]; then
elif [[ "$1" == "cmake.exporter.otprotocol.shared_libs.with_static_grpc.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_STANDARD=14 \
cmake ${CMAKE_OPTIONS[@]} \
-DWITH_OTLP_GRPC=ON \
-DWITH_OTLP_HTTP=ON \
-DBUILD_SHARED_LIBS=ON \
Expand All @@ -297,8 +296,7 @@ elif [[ "$1" == "cmake.exporter.otprotocol.shared_libs.with_static_grpc.test" ]]
elif [[ "$1" == "cmake.exporter.otprotocol.with_async_export.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_STANDARD=14 \
cmake ${CMAKE_OPTIONS[@]} \
-DWITH_OTLP_GRPC=ON \
-DWITH_OTLP_HTTP=ON \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
Expand All @@ -312,8 +310,7 @@ elif [[ "$1" == "cmake.exporter.otprotocol.with_async_export.test" ]]; then
elif [[ "$1" == "cmake.do_not_install.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_STANDARD=14 \
cmake ${CMAKE_OPTIONS[@]} \
-DWITH_OTLP_GRPC=ON \
-DWITH_OTLP_HTTP=ON \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
Expand Down Expand Up @@ -346,7 +343,7 @@ EOF
-static-libgcc \
-Wl,--version-script=${PWD}/export.map \
"
cmake -DCMAKE_BUILD_TYPE=Debug \
cmake ${CMAKE_OPTIONS[@]} \
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
-DCMAKE_EXE_LINKER_FLAGS="$LINKER_FLAGS" \
-DCMAKE_SHARED_LINKER_FLAGS="$LINKER_FLAGS" \
Expand All @@ -357,7 +354,7 @@ EOF
# Verify we can load the plugin
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
cmake ${CMAKE_OPTIONS[@]} \
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
"${SRC_DIR}"
make load_plugin_example
Expand Down Expand Up @@ -439,8 +436,7 @@ elif [[ "$1" == "format" ]]; then
elif [[ "$1" == "code.coverage" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_STANDARD=14 \
cmake ${CMAKE_OPTIONS[@]} \
-DCMAKE_CXX_FLAGS="-Werror --coverage $CXXFLAGS" \
"${SRC_DIR}"
make
Expand Down
Loading

0 comments on commit 0d1326a

Please sign in to comment.