From f95fd57ea7ddf2d1759f56cded7dd29e9f33084b Mon Sep 17 00:00:00 2001 From: owent Date: Sat, 27 May 2023 17:27:10 +0800 Subject: [PATCH] Using installed protobuf to build gRPC when using modern protobuf and gRPC Signed-off-by: owent --- .github/workflows/ci.yml | 2 +- ci/setup_grpc.sh | 41 +++++++++++++++++++++++++++------------- exporters/otlp/BUILD | 2 +- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c618f1688c..f193802258 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -407,7 +407,7 @@ jobs: env: WITH_ABSEIL: 'ON' run: | - sudo ./ci/setup_grpc.sh -r v1.54.2 + sudo ./ci/setup_grpc.sh -r v1.54.2 -p protobuf -p abseil-cpp ./ci/do_ci.sh cmake.exporter.otprotocol.test cmake_do_not_install_test: diff --git a/ci/setup_grpc.sh b/ci/setup_grpc.sh index e1002b6616..2cedba285e 100755 --- a/ci/setup_grpc.sh +++ b/ci/setup_grpc.sh @@ -12,9 +12,11 @@ std_version='14' install_grpc_version=${new_grpc_version} install_dir='/usr/local/' build_shared_libs='' +build_internal_abseil_cpp=1 +GRPC_BUILD_OPTIONS=() usage() { echo "Usage: $0 [-v ] [-i "] 1>&2; exit 1;} -while getopts ":v:i:r:s:TH" o; do +while getopts ":v:i:p:r:s:TH" o; do case "${o}" in v) gcc_version=${OPTARG} @@ -22,6 +24,14 @@ while getopts ":v:i:r:s:TH" o; do i) install_dir=${OPTARG} ;; + p) + if [[ "${OPTARG}" == "protobuf" ]]; then + GRPC_BUILD_OPTIONS=(${GRPC_BUILD_OPTIONS[@]} "-DgRPC_PROTOBUF_PROVIDER=package") + elif [[ "${OPTARG}" == "abseil-cpp" ]]; then + GRPC_BUILD_OPTIONS=(${GRPC_BUILD_OPTIONS[@]} "-DgRPC_ABSL_PROVIDER=package") + build_internal_abseil_cpp=0 + fi + ;; r) install_grpc_version=${OPTARG} ;; @@ -39,6 +49,7 @@ while getopts ":v:i:r:s:TH" o; do ;; esac done + if [ -z "${gcc_version}" ]; then gcc_version=`gcc --version | awk '/gcc/ {print $NF}'` fi @@ -59,22 +70,26 @@ git clone --depth=1 -b ${install_grpc_version} https://github.com/grpc/grpc pushd grpc git submodule init git submodule update --depth 1 -mkdir -p "third_party/abseil-cpp/build" && pushd "third_party/abseil-cpp/build" -set -x -ABSEIL_CPP_BUILD_OPTIONS=( - -DCMAKE_BUILD_TYPE=Release - -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE - -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -) -if [ ! -z "$build_shared_libs" ]; then - ABSEIL_CPP_BUILD_OPTIONS=(${ABSEIL_CPP_BUILD_OPTIONS[@]} "-DBUILD_SHARED_LIBS=$build_shared_libs") +if [[ $build_internal_abseil_cpp -ne 0 ]]; then + mkdir -p "third_party/abseil-cpp/build" && pushd "third_party/abseil-cpp/build" + set -x + + ABSEIL_CPP_BUILD_OPTIONS=( + -DCMAKE_BUILD_TYPE=Release + -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE + -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR + ) + if [ ! -z "$build_shared_libs" ]; then + ABSEIL_CPP_BUILD_OPTIONS=(${ABSEIL_CPP_BUILD_OPTIONS[@]} "-DBUILD_SHARED_LIBS=$build_shared_libs") + fi + cmake ${ABSEIL_CPP_BUILD_OPTIONS[@]} .. + cmake --build . -j${nproc} --target install && popd fi -cmake ${ABSEIL_CPP_BUILD_OPTIONS[@]} .. -cmake --build . -j${nproc} --target install && popd mkdir -p build && pushd build GRPC_BUILD_OPTIONS=( + ${GRPC_BUILD_OPTIONS[@]} -DgRPC_INSTALL=ON -DCMAKE_CXX_STANDARD=${std_version} -DgRPC_BUILD_TESTS=OFF @@ -85,7 +100,7 @@ if [ ! -z "$build_shared_libs" ]; then GRPC_BUILD_OPTIONS=(${GRPC_BUILD_OPTIONS[@]} "-DBUILD_SHARED_LIBS=$build_shared_libs") fi -cmake ${GRPC_BUILD_OPTIONS[@]} .. +cmake ${GRPC_BUILD_OPTIONS[@]} "$@" .. cmake --build . -j$(nproc) cmake --install . popd diff --git a/exporters/otlp/BUILD b/exporters/otlp/BUILD index a5d86df774..7da4a18c49 100644 --- a/exporters/otlp/BUILD +++ b/exporters/otlp/BUILD @@ -131,8 +131,8 @@ cc_library( "//ext/src/http/client/curl:http_client_curl", "//sdk:headers", "@com_github_opentelemetry_proto//:common_proto_cc", - "@github_nlohmann_json//:json", "@com_google_absl//absl/strings", + "@github_nlohmann_json//:json", ], )