Skip to content

Commit 6d68cb5

Browse files
committed
Upgrade Protobuf C++ to 22.5
1 parent ca4819a commit 6d68cb5

File tree

11 files changed

+59
-32
lines changed

11 files changed

+59
-32
lines changed

COMPILING.md

Lines changed: 2 additions & 2 deletions
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.5 or later.
4848

4949
For Linux, Mac and MinGW:
5050
```
51-
$ PROTOBUF_VERSION=21.7
51+
$ PROTOBUF_VERSION=22.5
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

buildscripts/grpc-java-artifacts/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ FROM almalinux:8
33
RUN yum install -y \
44
autoconf \
55
automake \
6+
cmake \
67
diffutils \
78
gcc-c++ \
89
glibc-devel \

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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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/android-interop.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ set -exu -o pipefail
77

88
cd github/grpc-java
99

10-
export LDFLAGS=-L/tmp/protobuf/lib
11-
export CXXFLAGS=-I/tmp/protobuf/include
10+
export LDFLAGS="$(PKG_CONFIG_PATH=/tmp/protobuf/lib/pkgconfig pkg-config --libs protobuf)"
11+
export CXXFLAGS="$(PKG_CONFIG_PATH=/tmp/protobuf/lib/pkgconfig pkg-config --cflags protobuf)"
1212
export LD_LIBRARY_PATH=/tmp/protobuf/lib
1313
export OS_NAME=$(uname)
1414

buildscripts/kokoro/android.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ BASE_DIR="$(pwd)"
99

1010
cd "$BASE_DIR/github/grpc-java"
1111

12-
export LDFLAGS=-L/tmp/protobuf/lib
13-
export CXXFLAGS=-I/tmp/protobuf/include
12+
export LDFLAGS="$(PKG_CONFIG_PATH=/tmp/protobuf/lib/pkgconfig pkg-config --libs protobuf)"
13+
export CXXFLAGS="$(PKG_CONFIG_PATH=/tmp/protobuf/lib/pkgconfig pkg-config --cflags protobuf)"
1414
export LD_LIBRARY_PATH=/tmp/protobuf/lib
1515
export OS_NAME=$(uname)
1616

buildscripts/kokoro/unix.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ fi
5151
export GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx1g'"
5252

5353
# Make protobuf discoverable by :grpc-compiler
54+
export LDFLAGS="$(PKG_CONFIG_PATH=/tmp/protobuf/lib/pkgconfig pkg-config --libs protobuf)"
55+
export CXXFLAGS="$(PKG_CONFIG_PATH=/tmp/protobuf/lib/pkgconfig pkg-config --cflags protobuf)"
5456
export LD_LIBRARY_PATH=/tmp/protobuf/lib
55-
export LDFLAGS=-L/tmp/protobuf/lib
56-
export CXXFLAGS="-I/tmp/protobuf/include"
5757

5858
./gradlew grpc-compiler:clean $GRADLE_FLAGS
5959

buildscripts/make_dependencies.bat

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
set PROTOBUF_VER=21.7
2-
set CMAKE_NAME=cmake-3.3.2-win32-x86
1+
@rem set PROTOBUF_VER=21.7
2+
set PROTOBUF_VER=22.5
3+
set CMAKE_NAME=cmake-3.26.3-windows-x86_64
34

45
if not exist "protobuf-%PROTOBUF_VER%\build\Release\" (
56
call :installProto || exit /b 1
@@ -20,7 +21,7 @@ if not exist "%CMAKE_NAME%" (
2021
set PATH=%PATH%;%cd%\%CMAKE_NAME%\bin
2122
:hasCmake
2223
@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
24+
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
2425
powershell -command "$ErrorActionPreference = 'stop'; & { Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory('protobuf.zip', '.') }" || exit /b 1
2526
del protobuf.zip
2627
mkdir protobuf-%PROTOBUF_VER%\build

buildscripts/make_dependencies.sh

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
# Build protoc
44
set -evux -o pipefail
55

6-
PROTOBUF_VERSION=21.7
6+
PROTOBUF_VERSION=22.5
77

88
# ARCH is x86_64 bit unless otherwise specified.
99
ARCH="${ARCH:-x86_64}"
1010
DOWNLOAD_DIR=/tmp/source
1111
INSTALL_DIR="/tmp/protobuf-cache/$PROTOBUF_VERSION/$(uname -s)-$ARCH"
12+
BUILDSCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd)"
1213
mkdir -p $DOWNLOAD_DIR
14+
cd "$DOWNLOAD_DIR"
1315

1416
# Start with a sane default
1517
NUM_CPU=4
@@ -26,27 +28,39 @@ if [ -f ${INSTALL_DIR}/bin/protoc ]; then
2628
echo "Not building protobuf. Already built"
2729
# TODO(ejona): swap to `brew install --devel protobuf` once it is up-to-date
2830
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
31+
if [[ ! -d "protobuf-${PROTOBUF_VERSION}" ]]; then
32+
curl -Ls "https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-${PROTOBUF_VERSION}.tar.gz" | tar xz
3133
fi
32-
pushd $DOWNLOAD_DIR/protobuf-${PROTOBUF_VERSION}
34+
# the same source dir is used for 32 and 64 bit builds, so we need to clean stale data first
35+
rm -rf "$DOWNLOAD_DIR/protobuf-${PROTOBUF_VERSION}/build"
36+
mkdir "$DOWNLOAD_DIR/protobuf-${PROTOBUF_VERSION}/build"
37+
pushd "$DOWNLOAD_DIR/protobuf-${PROTOBUF_VERSION}/build"
3338
# install here so we don't need sudo
3439
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"
40+
CFLAGS=-m${ARCH#*_} CXXFLAGS=-m${ARCH#*_} cmake .. \
41+
-DCMAKE_CXX_STANDARD=14 -Dprotobuf_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF \
42+
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" -DABSL_INTERNAL_AT_LEAST_CXX17=0
43+
else
44+
if [[ "$ARCH" == aarch_64 ]]; then
45+
GCC_ARCH=aarch64-linux-gnu
46+
elif [[ "$ARCH" == ppcle_64 ]]; then
47+
GCC_ARCH=powerpc64le-linux-gnu
48+
elif [[ "$ARCH" == s390_64 ]]; then
49+
GCC_ARCH=s390x-linux-gnu
50+
elif [[ "$ARCH" == loongarch_64 ]]; then
51+
GCC_ARCH=loongarch64-unknown-linux-gnu
52+
else
53+
echo "Unknown architecture: $ARCH"
54+
exit 1
55+
fi
56+
cmake .. \
57+
-DCMAKE_CXX_STANDARD=14 -Dprotobuf_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF \
58+
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" -Dcrosscompile_ARCH="$GCC_ARCH" \
59+
-DCMAKE_TOOLCHAIN_FILE=$BUILDSCRIPTS_DIR/toolchain.cmake
4560
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
61+
cmake --build . -j "$NUM_CPU"
62+
cmake --install .
63+
[ -d "$INSTALL_DIR/lib64" ] && mv "$INSTALL_DIR/lib64" "$INSTALL_DIR/lib"
5064
popd
5165
fi
5266

@@ -60,7 +74,7 @@ ln -s "$INSTALL_DIR" /tmp/protobuf
6074
cat <<EOF
6175
To compile with the build dependencies:
6276
63-
export LDFLAGS=-L/tmp/protobuf/lib
64-
export CXXFLAGS=-I/tmp/protobuf/include
77+
export LDFLAGS="$(PKG_CONFIG_PATH=/tmp/protobuf/lib/pkgconfig pkg-config --libs protobuf)"
78+
export CXXFLAGS="$(PKG_CONFIG_PATH=/tmp/protobuf/lib/pkgconfig pkg-config --cflags protobuf)"
6579
export LD_LIBRARY_PATH=/tmp/protobuf/lib
6680
EOF

buildscripts/toolchain.cmake

Lines changed: 9 additions & 0 deletions
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)

0 commit comments

Comments
 (0)