33# Build protoc
44set -evux -o pipefail
55
6- PROTOBUF_VERSION=26 .1
6+ PROTOBUF_VERSION=33 .1
77ABSL_VERSION=20250127.1
8- CMAKE_VERSION=3.26.3
98
109# ARCH is x86_64 bit unless otherwise specified.
1110ARCH=" ${ARCH:- x86_64} "
1211DOWNLOAD_DIR=/tmp/source
1312INSTALL_DIR=" /tmp/protobuf-cache/$PROTOBUF_VERSION /$( uname -s) -$ARCH "
1413BUILDSCRIPTS_DIR=" $( cd " $( dirname " $0 " ) " && pwd) "
15- mkdir -p $DOWNLOAD_DIR
16- cd " $DOWNLOAD_DIR "
17-
18- # Start with a sane default
19- NUM_CPU=4
20- if [[ $( uname) == ' Linux' ]]; then
21- NUM_CPU=$( nproc)
22- fi
23- if [[ $( uname) == ' Darwin' ]]; then
24- NUM_CPU=$( sysctl -n hw.ncpu)
25- fi
2614
27- # Make protoc
28- # Can't check for presence of directory as cache auto-creates it.
29- if [ -f ${INSTALL_DIR} /bin/protoc ]; then
30- echo " Not building protobuf. Already built"
31- # TODO(ejona): swap to `brew install --devel protobuf` once it is up-to-date
32- else
33- if [[ ! -d " protobuf-${PROTOBUF_VERSION} " ]]; then
34- curl -Ls " https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION} /protobuf-${PROTOBUF_VERSION} .tar.gz" | tar xz
35- curl -Ls " https://github.com/abseil/abseil-cpp/archive/refs/tags/${ABSL_VERSION} .tar.gz" | tar xz
36- rmdir " protobuf-$PROTOBUF_VERSION /third_party/abseil-cpp"
37- mv " abseil-cpp-$ABSL_VERSION " " protobuf-$PROTOBUF_VERSION /third_party/abseil-cpp"
15+ function build_and_install() {
16+ if [[ " $1 " == " abseil" ]]; then
17+ TESTS_OFF_ARG=ABSL_BUILD_TEST_HELPERS
18+ else
19+ TESTS_OFF_ARG=protobuf_BUILD_TESTS
3820 fi
39- # the same source dir is used for 32 and 64 bit builds, so we need to clean stale data first
40- rm -rf " $DOWNLOAD_DIR /protobuf-${PROTOBUF_VERSION} /build"
41- mkdir " $DOWNLOAD_DIR /protobuf-${PROTOBUF_VERSION} /build"
42- pushd " $DOWNLOAD_DIR /protobuf-${PROTOBUF_VERSION} /build"
43- # install here so we don't need sudo
4421 if [[ " $( uname -s) " == " Darwin" ]]; then
4522 cmake .. \
46- -DCMAKE_CXX_STANDARD=14 -Dprotobuf_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF \
47- -DCMAKE_INSTALL_PREFIX=" $INSTALL_DIR " -DABSL_INTERNAL_AT_LEAST_CXX17=0 \
23+ -DCMAKE_CXX_STANDARD=17 -D${TESTS_OFF_ARG} =OFF -DBUILD_SHARED_LIBS=OFF \
24+ -DCMAKE_INSTALL_PREFIX=" $INSTALL_DIR " \
25+ -DCMAKE_PREFIX_PATH=" $INSTALL_DIR " \
4826 -DCMAKE_OSX_ARCHITECTURES=" arm64;x86_64" \
4927 -B. || exit 1
5028 elif [[ " $ARCH " == x86* ]]; then
5129 CFLAGS=-m${ARCH#* _} CXXFLAGS=-m${ARCH#* _} cmake .. \
52- -DCMAKE_CXX_STANDARD=14 -Dprotobuf_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF \
53- -DCMAKE_INSTALL_PREFIX=" $INSTALL_DIR " -DABSL_INTERNAL_AT_LEAST_CXX17=0 \
30+ -DCMAKE_CXX_STANDARD=17 -D${TESTS_OFF_ARG} =OFF -DBUILD_SHARED_LIBS=OFF \
31+ -DCMAKE_INSTALL_PREFIX=" $INSTALL_DIR " \
32+ -DCMAKE_PREFIX_PATH=" $INSTALL_DIR " \
5433 -B. || exit 1
5534 else
5635 if [[ " $ARCH " == aarch_64 ]]; then
6645 exit 1
6746 fi
6847 cmake .. \
69- -DCMAKE_CXX_STANDARD=14 -Dprotobuf_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF \
70- -DCMAKE_INSTALL_PREFIX=" $INSTALL_DIR " -DABSL_INTERNAL_AT_LEAST_CXX17=0 \
48+ -DCMAKE_CXX_STANDARD=17 -D${TESTS_OFF_ARG} =OFF -DBUILD_SHARED_LIBS=OFF \
49+ -DCMAKE_INSTALL_PREFIX=" $INSTALL_DIR " \
50+ -DCMAKE_PREFIX_PATH=" $INSTALL_DIR " \
7151 -Dcrosscompile_ARCH=" $GCC_ARCH " \
7252 -DCMAKE_TOOLCHAIN_FILE=$BUILDSCRIPTS_DIR /toolchain.cmake \
7353 -B. || exit 1
7454 fi
7555 export CMAKE_BUILD_PARALLEL_LEVEL=" $NUM_CPU "
7656 cmake --build . || exit 1
57+ # install here so we don't need sudo
7758 cmake --install . || exit 1
78- [ -d " $INSTALL_DIR /lib64" ] && mv " $INSTALL_DIR /lib64" " $INSTALL_DIR /lib"
59+ }
60+
61+ mkdir -p $DOWNLOAD_DIR
62+ cd " $DOWNLOAD_DIR "
63+
64+ # Start with a sane default
65+ NUM_CPU=4
66+ if [[ $( uname) == ' Linux' ]]; then
67+ NUM_CPU=$( nproc)
68+ fi
69+ if [[ $( uname) == ' Darwin' ]]; then
70+ NUM_CPU=$( sysctl -n hw.ncpu)
71+ fi
72+ export CMAKE_BUILD_PARALLEL_LEVEL=" $NUM_CPU "
73+
74+ # Make protoc
75+ # Can't check for presence of directory as cache auto-creates it.
76+ if [ -f ${INSTALL_DIR} /bin/protoc ]; then
77+ echo " Not building protobuf. Already built"
78+ # TODO(ejona): swap to `brew install --devel protobuf` once it is up-to-date
79+ else
80+ if [[ ! -d " protobuf-${PROTOBUF_VERSION} " ]]; then
81+ curl -Ls " https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION} /protobuf-${PROTOBUF_VERSION} .tar.gz" | tar xz
82+ curl -Ls " https://github.com/abseil/abseil-cpp/archive/refs/tags/${ABSL_VERSION} .tar.gz" | tar xz
83+ fi
84+ # the same source dir is used for 32 and 64 bit builds, so we need to clean stale data first
85+ rm -rf " $DOWNLOAD_DIR /abseil-cpp-${ABSL_VERSION} /build"
86+ mkdir " $DOWNLOAD_DIR /abseil-cpp-${ABSL_VERSION} /build"
87+ pushd " $DOWNLOAD_DIR /abseil-cpp-${ABSL_VERSION} /build"
88+ build_and_install " abseil"
89+ popd
90+
91+ rm -rf " $DOWNLOAD_DIR /protobuf-${PROTOBUF_VERSION} /build"
92+ mkdir " $DOWNLOAD_DIR /protobuf-${PROTOBUF_VERSION} /build"
93+ pushd " $DOWNLOAD_DIR /protobuf-${PROTOBUF_VERSION} /build"
94+ build_and_install " protobuf"
7995 popd
96+
97+ [ -d " $INSTALL_DIR /lib64" ] && mv " $INSTALL_DIR /lib64" " $INSTALL_DIR /lib"
8098fi
8199
82100# If /tmp/protobuf exists then we just assume it's a symlink created by us.
@@ -94,3 +112,4 @@ export CXXFLAGS="$(PKG_CONFIG_PATH=/tmp/protobuf/lib/pkgconfig pkg-config --cfla
94112export LIBRARY_PATH=/tmp/protobuf/lib
95113export LD_LIBRARY_PATH=/tmp/protobuf/lib
96114EOF
115+
0 commit comments