forked from grpc/grpc-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_dependencies.sh
More file actions
executable file
·115 lines (103 loc) · 3.78 KB
/
make_dependencies.sh
File metadata and controls
executable file
·115 lines (103 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
#
# Build protoc
set -evux -o pipefail
PROTOBUF_VERSION=33.1
ABSL_VERSION=20250127.1
# ARCH is x86_64 bit unless otherwise specified.
ARCH="${ARCH:-x86_64}"
DOWNLOAD_DIR=/tmp/source
INSTALL_DIR="/tmp/protobuf-cache/$PROTOBUF_VERSION/$(uname -s)-$ARCH"
BUILDSCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd)"
function build_and_install() {
if [[ "$1" == "abseil" ]]; then
TESTS_OFF_ARG=ABSL_BUILD_TEST_HELPERS
else
TESTS_OFF_ARG=protobuf_BUILD_TESTS
fi
if [[ "$(uname -s)" == "Darwin" ]]; then
cmake .. \
-DCMAKE_CXX_STANDARD=17 -D${TESTS_OFF_ARG}=OFF -DBUILD_SHARED_LIBS=OFF \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
-DCMAKE_PREFIX_PATH="$INSTALL_DIR" \
-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
-B. || exit 1
elif [[ "$ARCH" == x86* ]]; then
CFLAGS=-m${ARCH#*_} CXXFLAGS=-m${ARCH#*_} cmake .. \
-DCMAKE_CXX_STANDARD=17 -D${TESTS_OFF_ARG}=OFF -DBUILD_SHARED_LIBS=OFF \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
-DCMAKE_PREFIX_PATH="$INSTALL_DIR" \
-B. || exit 1
else
if [[ "$ARCH" == aarch_64 ]]; then
GCC_ARCH=aarch64-linux-gnu
elif [[ "$ARCH" == ppcle_64 ]]; then
GCC_ARCH=powerpc64le-linux-gnu
elif [[ "$ARCH" == s390_64 ]]; then
GCC_ARCH=s390x-linux-gnu
elif [[ "$ARCH" == loongarch_64 ]]; then
GCC_ARCH=loongarch64-unknown-linux-gnu
else
echo "Unknown architecture: $ARCH"
exit 1
fi
cmake .. \
-DCMAKE_CXX_STANDARD=17 -D${TESTS_OFF_ARG}=OFF -DBUILD_SHARED_LIBS=OFF \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
-DCMAKE_PREFIX_PATH="$INSTALL_DIR" \
-Dcrosscompile_ARCH="$GCC_ARCH" \
-DCMAKE_TOOLCHAIN_FILE=$BUILDSCRIPTS_DIR/toolchain.cmake \
-B. || exit 1
fi
export CMAKE_BUILD_PARALLEL_LEVEL="$NUM_CPU"
cmake --build . || exit 1
# install here so we don't need sudo
cmake --install . || exit 1
}
mkdir -p $DOWNLOAD_DIR
cd "$DOWNLOAD_DIR"
# Start with a sane default
NUM_CPU=4
if [[ $(uname) == 'Linux' ]]; then
NUM_CPU=$(nproc)
fi
if [[ $(uname) == 'Darwin' ]]; then
NUM_CPU=$(sysctl -n hw.ncpu)
fi
export CMAKE_BUILD_PARALLEL_LEVEL="$NUM_CPU"
# Make protoc
# Can't check for presence of directory as cache auto-creates it.
if [ -f ${INSTALL_DIR}/bin/protoc ]; then
echo "Not building protobuf. Already built"
# TODO(ejona): swap to `brew install --devel protobuf` once it is up-to-date
else
if [[ ! -d "protobuf-${PROTOBUF_VERSION}" ]]; then
curl -Ls "https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-${PROTOBUF_VERSION}.tar.gz" | tar xz
curl -Ls "https://github.com/abseil/abseil-cpp/archive/refs/tags/${ABSL_VERSION}.tar.gz" | tar xz
fi
# the same source dir is used for 32 and 64 bit builds, so we need to clean stale data first
rm -rf "$DOWNLOAD_DIR/abseil-cpp-${ABSL_VERSION}/build"
mkdir "$DOWNLOAD_DIR/abseil-cpp-${ABSL_VERSION}/build"
pushd "$DOWNLOAD_DIR/abseil-cpp-${ABSL_VERSION}/build"
build_and_install "abseil"
popd
rm -rf "$DOWNLOAD_DIR/protobuf-${PROTOBUF_VERSION}/build"
mkdir "$DOWNLOAD_DIR/protobuf-${PROTOBUF_VERSION}/build"
pushd "$DOWNLOAD_DIR/protobuf-${PROTOBUF_VERSION}/build"
build_and_install "protobuf"
popd
[ -d "$INSTALL_DIR/lib64" ] && mv "$INSTALL_DIR/lib64" "$INSTALL_DIR/lib"
fi
# If /tmp/protobuf exists then we just assume it's a symlink created by us.
# It may be that it points to the wrong arch, so we idempotently set it now.
if [[ -L /tmp/protobuf ]]; then
rm /tmp/protobuf
fi
ln -s "$INSTALL_DIR" /tmp/protobuf
cat <<EOF
To compile with the build dependencies:
export LDFLAGS="$(PKG_CONFIG_PATH=/tmp/protobuf/lib/pkgconfig pkg-config --libs protobuf)"
export CXXFLAGS="$(PKG_CONFIG_PATH=/tmp/protobuf/lib/pkgconfig pkg-config --cflags protobuf)"
export LIBRARY_PATH=/tmp/protobuf/lib
export LD_LIBRARY_PATH=/tmp/protobuf/lib
EOF