3
3
# Build protoc
4
4
set -evux -o pipefail
5
5
6
- PROTOBUF_VERSION=21.7
6
+ PROTOBUF_VERSION=22.3
7
+ ABSL_VERSION=20230125.2
7
8
8
9
# ARCH is x86_64 bit unless otherwise specified.
9
10
ARCH=" ${ARCH:- x86_64} "
10
11
DOWNLOAD_DIR=/tmp/source
11
12
INSTALL_DIR=" /tmp/protobuf-cache/$PROTOBUF_VERSION /$( uname -s) -$ARCH "
13
+ BUILDSCRIPTS_DIR=" $( cd " $( dirname " $0 " ) " && pwd) "
12
14
mkdir -p $DOWNLOAD_DIR
15
+ cd " $DOWNLOAD_DIR "
13
16
14
17
# Start with a sane default
15
18
NUM_CPU=4
@@ -26,27 +29,42 @@ if [ -f ${INSTALL_DIR}/bin/protoc ]; then
26
29
echo " Not building protobuf. Already built"
27
30
# TODO(ejona): swap to `brew install --devel protobuf` once it is up-to-date
28
31
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"
31
37
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"
33
42
# install here so we don't need sudo
34
43
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
45
64
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"
50
68
popd
51
69
fi
52
70
0 commit comments