Skip to content

Commit 0b9819c

Browse files
committed
Upgrade Protobuf C++ to 22.3
1 parent 8aa2547 commit 0b9819c

9 files changed

+67
-31
lines changed

COMPILING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ This section is only necessary if you are making changes to the code
4444
generation. Most users only need to use `skipCodegen=true` as discussed above.
4545

4646
### Build Protobuf
47-
The codegen plugin is C++ code and requires protobuf 21.7 or later.
47+
The codegen plugin is C++ code and requires protobuf 22.3 or later.
4848

4949
For Linux, Mac and MinGW:
5050
```
51-
$ PROTOBUF_VERSION=21.7
51+
$ PROTOBUF_VERSION=22.3
5252
$ curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOBUF_VERSION/protobuf-all-$PROTOBUF_VERSION.tar.gz
5353
$ tar xzf protobuf-all-$PROTOBUF_VERSION.tar.gz
5454
$ cd protobuf-$PROTOBUF_VERSION
+7-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
FROM centos:7.9.2009
22

3-
RUN yum install -y \
4-
autoconf \
5-
automake \
6-
gcc-c++ \
7-
gcc-c++.i686 \
3+
RUN yum install -y centos-release-scl && \
4+
yum install -y \
5+
devtoolset-7-gcc-c++ \
86
glibc-devel \
97
glibc-devel.i686 \
108
java-1.8.0-openjdk-devel \
@@ -19,7 +17,9 @@ RUN yum install -y \
1917
&& \
2018
yum clean all
2119

22-
# Install Maven
20+
RUN curl -Ls https://github.com/Kitware/CMake/releases/download/v3.26.3/cmake-3.26.3-linux-x86_64.tar.gz | \
21+
tar xz -C /var/local
2322
RUN curl -Ls http://dlcdn.apache.org/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz | \
2423
tar xz -C /var/local
25-
ENV PATH /var/local/apache-maven-3.3.9/bin:$PATH
24+
25+
ENV PATH /var/local/cmake-3.26.3-linux-x86_64/bin:/var/local/apache-maven-3.3.9/bin:$PATH

buildscripts/grpc-java-artifacts/Dockerfile.multiarch.base

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
44
apt-get update && \
55
apt-get upgrade -y && \
66
apt-get install -y --no-install-recommends \
7+
cmake \
78
build-essential \
89
ca-certificates \
910
curl \

buildscripts/grpc-java-artifacts/Dockerfile.ubuntu2004.base

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
44
apt-get update && \
55
apt-get upgrade -y && \
66
apt-get install -y --no-install-recommends \
7+
cmake \
78
build-essential \
89
ca-certificates \
910
curl \

buildscripts/kokoro/linux_artifacts.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ readonly GRPC_JAVA_DIR="$(cd "$(dirname "$0")"/../.. && pwd)"
1111
trap spongify_logs EXIT
1212

1313
"$GRPC_JAVA_DIR"/buildscripts/build_docker.sh
14-
"$GRPC_JAVA_DIR"/buildscripts/run_in_docker.sh grpc-java-artifacts-x86 /grpc-java/buildscripts/build_artifacts_in_docker.sh
14+
"$GRPC_JAVA_DIR"/buildscripts/run_in_docker.sh grpc-java-artifacts-x86 scl enable devtoolset-7 /grpc-java/buildscripts/build_artifacts_in_docker.sh
1515

1616
# grpc-android, grpc-cronet and grpc-binder require the Android SDK, so build outside of Docker and
1717
# use --include-build for its grpc-core dependency

buildscripts/make_dependencies.bat

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
set PROTOBUF_VER=21.7
2-
set CMAKE_NAME=cmake-3.3.2-win32-x86
2+
@rem set PROTOBUF_VER=22.3
3+
set ABSL_VERSION=20230125.2
4+
set CMAKE_NAME=cmake-3.26.3-windows-x86_64
35

46
if not exist "protobuf-%PROTOBUF_VER%\build\Release\" (
57
call :installProto || exit /b 1
@@ -20,9 +22,14 @@ if not exist "%CMAKE_NAME%" (
2022
set PATH=%PATH%;%cd%\%CMAKE_NAME%\bin
2123
:hasCmake
2224
@rem GitHub requires TLSv1.2, and for whatever reason our powershell doesn't have it enabled
23-
powershell -command "$ErrorActionPreference = 'stop'; & { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; iwr https://github.com/google/protobuf/archive/v%PROTOBUF_VER%.zip -OutFile protobuf.zip }" || exit /b 1
25+
powershell -command "$ErrorActionPreference = 'stop'; & { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; iwr https://github.com/google/protobuf/releases/download/v%PROTOBUF_VER%/protobuf-%PROTOBUF_VER%.zip -OutFile protobuf.zip }" || exit /b 1
2426
powershell -command "$ErrorActionPreference = 'stop'; & { Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory('protobuf.zip', '.') }" || exit /b 1
2527
del protobuf.zip
28+
powershell -command "$ErrorActionPreference = 'stop'; & { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; iwr https://github.com/abseil/abseil-cpp/archive/refs/tags/%ABSL_VERSION%.zip -OutFile absl.zip }" || exit /b 1
29+
powershell -command "$ErrorActionPreference = 'stop'; & { Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory('absl.zip', '.') }" || exit /b 1
30+
del absl.zip
31+
@rem rmdir protobuf-%PROTOBUF_VER%\third_party\abseil-cpp
32+
@rem rename abseil-cpp-%ABSL_VERSION% protobuf-%PROTOBUF_VER%\third_party\abseil-cpp
2633
mkdir protobuf-%PROTOBUF_VER%\build
2734
pushd protobuf-%PROTOBUF_VER%\build
2835

buildscripts/make_dependencies.sh

+36-18
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
# Build protoc
44
set -evux -o pipefail
55

6-
PROTOBUF_VERSION=21.7
6+
PROTOBUF_VERSION=22.3
7+
ABSL_VERSION=20230125.2
78

89
# ARCH is x86_64 bit unless otherwise specified.
910
ARCH="${ARCH:-x86_64}"
1011
DOWNLOAD_DIR=/tmp/source
1112
INSTALL_DIR="/tmp/protobuf-cache/$PROTOBUF_VERSION/$(uname -s)-$ARCH"
13+
BUILDSCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd)"
1214
mkdir -p $DOWNLOAD_DIR
15+
cd "$DOWNLOAD_DIR"
1316

1417
# Start with a sane default
1518
NUM_CPU=4
@@ -26,27 +29,42 @@ if [ -f ${INSTALL_DIR}/bin/protoc ]; then
2629
echo "Not building protobuf. Already built"
2730
# TODO(ejona): swap to `brew install --devel protobuf` once it is up-to-date
2831
else
29-
if [[ ! -d "$DOWNLOAD_DIR"/protobuf-"${PROTOBUF_VERSION}" ]]; then
30-
curl -Ls https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-all-${PROTOBUF_VERSION}.tar.gz | tar xz -C $DOWNLOAD_DIR
32+
if [[ ! -d "protobuf-${PROTOBUF_VERSION}" ]]; then
33+
curl -Ls "https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-${PROTOBUF_VERSION}.tar.gz" | tar xz
34+
curl -Ls "https://github.com/abseil/abseil-cpp/archive/refs/tags/${ABSL_VERSION}.tar.gz" | tar xz
35+
rmdir "protobuf-$PROTOBUF_VERSION/third_party/abseil-cpp"
36+
mv "abseil-cpp-$ABSL_VERSION" "protobuf-$PROTOBUF_VERSION/third_party/abseil-cpp"
3137
fi
32-
pushd $DOWNLOAD_DIR/protobuf-${PROTOBUF_VERSION}
38+
# the same source dir is used for 32 and 64 bit builds, so we need to clean stale data first
39+
rm -rf "$DOWNLOAD_DIR/protobuf-${PROTOBUF_VERSION}/build"
40+
mkdir "$DOWNLOAD_DIR/protobuf-${PROTOBUF_VERSION}/build"
41+
pushd "$DOWNLOAD_DIR/protobuf-${PROTOBUF_VERSION}/build"
3342
# install here so we don't need sudo
3443
if [[ "$ARCH" == x86* ]]; then
35-
./configure CFLAGS=-m${ARCH#*_} CXXFLAGS=-m${ARCH#*_} --disable-shared \
36-
--prefix="$INSTALL_DIR"
37-
elif [[ "$ARCH" == aarch* ]]; then
38-
./configure --disable-shared --host=aarch64-linux-gnu --prefix="$INSTALL_DIR"
39-
elif [[ "$ARCH" == ppc* ]]; then
40-
./configure --disable-shared --host=powerpc64le-linux-gnu --prefix="$INSTALL_DIR"
41-
elif [[ "$ARCH" == s390* ]]; then
42-
./configure --disable-shared --host=s390x-linux-gnu --prefix="$INSTALL_DIR"
43-
elif [[ "$ARCH" == loongarch* ]]; then
44-
./configure --disable-shared --host=loongarch64-unknown-linux-gnu --prefix="$INSTALL_DIR"
44+
CFLAGS=-m${ARCH#*_} CXXFLAGS=-m${ARCH#*_} cmake .. \
45+
-DCMAKE_CXX_STANDARD=14 -Dprotobuf_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF \
46+
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR"
47+
else
48+
if [[ "$ARCH" == aarch_64 ]]; then
49+
GCC_ARCH=aarch64-linux-gnu
50+
elif [[ "$ARCH" == ppcle_64 ]]; then
51+
GCC_ARCH=powerpc64le-linux-gnu
52+
elif [[ "$ARCH" == s390_64 ]]; then
53+
GCC_ARCH=s390x-linux-gnu
54+
elif [[ "$ARCH" == loongarch_64 ]]; then
55+
GCC_ARCH=loongarch64-unknown-linux-gnu
56+
else
57+
echo "Unknown architecture: $ARCH"
58+
exit 1
59+
fi
60+
cmake .. \
61+
-DCMAKE_CXX_STANDARD=14 -Dprotobuf_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF \
62+
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" -Dcrosscompile_ARCH="$GCC_ARCH" \
63+
-DCMAKE_TOOLCHAIN_FILE=$BUILDSCRIPTS_DIR/toolchain.cmake
4564
fi
46-
# the same source dir is used for 32 and 64 bit builds, so we need to clean stale data first
47-
make clean
48-
make V=0 -j$NUM_CPU
49-
make install
65+
cmake --build . -j "$NUM_CPU"
66+
cmake --install .
67+
[ -d "$INSTALL_DIR/lib64" ] && mv "$INSTALL_DIR/lib64" "$INSTALL_DIR/lib"
5068
popd
5169
fi
5270

buildscripts/toolchain.cmake

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
set(CMAKE_SYSTEM_NAME Linux)
2+
3+
set(CMAKE_C_COMPILER "${crosscompile_ARCH}-gcc")
4+
set(CMAKE_CXX_COMPILER "${crosscompile_ARCH}-g++")
5+
set(CMAKE_FIND_ROOT_PATH "/usr/${crosscompile_ARCH}/")
6+
7+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
8+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
9+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

compiler/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ model {
9999
all {
100100
if (toolChain in Gcc || toolChain in Clang) {
101101
cppCompiler.define("GRPC_VERSION", version)
102-
cppCompiler.args "--std=c++0x"
102+
cppCompiler.args "--std=c++14"
103103
addEnvArgs("CXXFLAGS", cppCompiler.args)
104104
addEnvArgs("CPPFLAGS", cppCompiler.args)
105105
if (osdetector.os == "osx") {

0 commit comments

Comments
 (0)