Skip to content

Commit

Permalink
Using installed protobuf to build gRPC when using modern protobuf and…
Browse files Browse the repository at this point in the history
… gRPC

Signed-off-by: owent <admin@owent.net>
  • Loading branch information
owent committed May 27, 2023
1 parent 7b5f955 commit f95fd57
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
41 changes: 28 additions & 13 deletions ci/setup_grpc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,26 @@ 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 <gcc-version>] [-i <install_dir>"] 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}
;;
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}
;;
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand Down

0 comments on commit f95fd57

Please sign in to comment.