@@ -12,43 +12,22 @@ ARCH="${ARCH:-x86_64}"
1212DOWNLOAD_DIR=/tmp/source
1313INSTALL_DIR=" /tmp/protobuf-cache/$PROTOBUF_VERSION /$( uname -s) -$ARCH "
1414BUILDSCRIPTS_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
2615
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- mv " abseil-cpp-$ABSL_VERSION " " protobuf-$PROTOBUF_VERSION /third_party/abseil-cpp"
16+ function build_and_install() {
17+ if [[ " $1 " == " abseil" ]]; then
18+ TESTS_OFF_ARG=ABSL_BUILD_TEST_HELPERS
19+ else
20+ TESTS_OFF_ARG=protobuf_BUILD_TESTS
3721 fi
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"
42- # install here so we don't need sudo
4322 if [[ " $( uname -s) " == " Darwin" ]]; then
4423 cmake .. \
45- -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_TESTS =OFF -DBUILD_SHARED_LIBS=OFF \
24+ -DCMAKE_CXX_STANDARD=17 -D ${TESTS_OFF_ARG} =OFF -DBUILD_SHARED_LIBS=OFF \
4625 -DCMAKE_INSTALL_PREFIX=" $INSTALL_DIR " \
4726 -DCMAKE_OSX_ARCHITECTURES=" arm64;x86_64" \
4827 -B. || exit 1
4928 elif [[ " $ARCH " == x86* ]]; then
5029 CFLAGS=-m${ARCH#* _} CXXFLAGS=-m${ARCH#* _} cmake .. \
51- -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_TESTS =OFF -DBUILD_SHARED_LIBS=OFF \
30+ -DCMAKE_CXX_STANDARD=17 -D ${TESTS_OFF_ARG} =OFF -DBUILD_SHARED_LIBS=OFF \
5231 -DCMAKE_INSTALL_PREFIX=" $INSTALL_DIR " \
5332 -B. || exit 1
5433 else
6544 exit 1
6645 fi
6746 cmake .. \
68- -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_TESTS =OFF -DBUILD_SHARED_LIBS=OFF \
47+ -DCMAKE_CXX_STANDARD=17 -D ${TESTS_OFF_ARG} =OFF -DBUILD_SHARED_LIBS=OFF \
6948 -DCMAKE_INSTALL_PREFIX=" $INSTALL_DIR " \
7049 -Dcrosscompile_ARCH=" $GCC_ARCH " \
7150 -DCMAKE_TOOLCHAIN_FILE=$BUILDSCRIPTS_DIR /toolchain.cmake \
7251 -B. || exit 1
7352 fi
7453 export CMAKE_BUILD_PARALLEL_LEVEL=" $NUM_CPU "
7554 cmake --build . || exit 1
55+ # install here so we don't need sudo
7656 cmake --install . || exit 1
77- [ -d " $INSTALL_DIR /lib64" ] && mv " $INSTALL_DIR /lib64" " $INSTALL_DIR /lib"
57+ }
58+
59+ mkdir -p $DOWNLOAD_DIR
60+ cd " $DOWNLOAD_DIR "
61+
62+ # Start with a sane default
63+ NUM_CPU=4
64+ if [[ $( uname) == ' Linux' ]]; then
65+ NUM_CPU=$( nproc)
66+ fi
67+ if [[ $( uname) == ' Darwin' ]]; then
68+ NUM_CPU=$( sysctl -n hw.ncpu)
69+ fi
70+
71+ # Make protoc
72+ # Can't check for presence of directory as cache auto-creates it.
73+ if [ -f ${INSTALL_DIR} /bin/protoc ]; then
74+ echo " Not building protobuf. Already built"
75+ # TODO(ejona): swap to `brew install --devel protobuf` once it is up-to-date
76+ else
77+ if [[ ! -d " protobuf-${PROTOBUF_VERSION} " ]]; then
78+ curl -Ls " https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION} /protobuf-${PROTOBUF_VERSION} .tar.gz" | tar xz
79+ curl -Ls " https://github.com/abseil/abseil-cpp/archive/refs/tags/${ABSL_VERSION} .tar.gz" | tar xz
80+ fi
81+ # the same source dir is used for 32 and 64 bit builds, so we need to clean stale data first
82+ rm -rf " $DOWNLOAD_DIR /abseil-cpp-${ABSL_VERSION} /build"
83+ mkdir " $DOWNLOAD_DIR /abseil-cpp-${ABSL_VERSION} /build"
84+ pushd " $DOWNLOAD_DIR /abseil-cpp-${ABSL_VERSION} /build"
85+ build_and_install " abseil"
86+ popd
87+
88+ rm -rf " $DOWNLOAD_DIR /protobuf-${PROTOBUF_VERSION} /build"
89+ mkdir " $DOWNLOAD_DIR /protobuf-${PROTOBUF_VERSION} /build"
90+ pushd " $DOWNLOAD_DIR /protobuf-${PROTOBUF_VERSION} /build"
91+ build_and_install " protobuf"
7892 popd
93+
94+ [ -d " $INSTALL_DIR /lib64" ] && mv " $INSTALL_DIR /lib64" " $INSTALL_DIR /lib"
7995fi
8096
8197# If /tmp/protobuf exists then we just assume it's a symlink created by us.
@@ -93,3 +109,4 @@ export CXXFLAGS="$(PKG_CONFIG_PATH=/tmp/protobuf/lib/pkgconfig pkg-config --cfla
93109export LIBRARY_PATH=/tmp/protobuf/lib
94110export LD_LIBRARY_PATH=/tmp/protobuf/lib
95111EOF
112+
0 commit comments