Created
March 19, 2021 02:56
-
-
Save alberthdev/4aa940b6c9fa6c4c239d795a86910044 to your computer and use it in GitHub Desktop.
bootstrap.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script aims to build a bootstrap CMake + gRPC environment for | |
# your project! It tries and saves space for the build - shallow cloning | |
# by default. Post build it'll take 1.5 GBs total, 340 MBs for just the | |
# final binaries needed for your project. | |
# | |
# magical bash snip @ https://stackoverflow.com/a/246128 | |
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | |
becho() { echo -e "\e[1m$@\e[0m"; } | |
# Settings | |
# --------- | |
# BOOTSTRAP_DIR - where to install this bootstrap environment | |
# default: <directory where this script is located>/bootstrap | |
BOOTSTRAP_DIR="$SCRIPT_DIR/bootstrap" | |
# PARALLEL_GRPC_CPUS - how many CPUs to build gRPC with | |
# leave empty to unbound the number of parallel processes make can | |
# run at the same time (dangerous - will run out of memory) | |
# default: 2 CPUs | |
PARALLEL_GRPC_CPUS=2 | |
mkdir -p $BOOTSTRAP_DIR $BOOTSTRAP_DIR/pkgs $BOOTSTRAP_DIR/prefix | |
becho " * writing env script..." | |
echo 'export PATH="'"$BOOTSTRAP_DIR"'/prefix/bin:$PATH"' > $BOOTSTRAP_DIR/env.sh | |
echo 'export LD_LIBRARY_PATH="'"$BOOTSTRAP_DIR"'/bootstrap/prefix/lib:$LD_LIBRARY_PATH"' >> $BOOTSTRAP_DIR/env.sh | |
echo 'echo "environment loaded"' >> $BOOTSTRAP_DIR/env.sh | |
chmod +x $BOOTSTRAP_DIR/env.sh | |
becho " * loading env script..." | |
source $BOOTSTRAP_DIR/env.sh | |
becho " * installing cmake..." | |
wget -q -O $BOOTSTRAP_DIR/pkgs/cmake-linux.sh https://github.com/Kitware/CMake/releases/download/v3.19.6/cmake-3.19.6-Linux-x86_64.sh | |
sh $BOOTSTRAP_DIR/pkgs/cmake-linux.sh -- --skip-license --prefix=$BOOTSTRAP_DIR/prefix | |
becho " * ensuring we have the correct cmake..." | |
cmake_loc=$(which cmake) | |
if [ ! "$cmake_loc" = "$BOOTSTRAP_DIR/prefix/bin/cmake" ]; then | |
becho " * failed to setup cmake in bootstrap prefix... got $cmake_loc" | |
exit 1 | |
fi | |
becho " * installing required build deps..." | |
distro=$(lsb_release -i | cut -f2) | |
if [ "$distro" = "Ubuntu" ] || [ "$distro" = "Debian" ]; then | |
sudo apt install -y build-essential autoconf libtool pkg-config | |
else | |
echo "You will need basic build tools (make, gcc, etc.), autoconf, libtool," | |
echo "pkg-config, and git (>=2.9.0) installed." | |
echo "Press ENTER if you have those installed already. Otherwise, CTRL-C to exit." | |
read | |
fi | |
becho " * downloading grpc from git..." | |
pushd $BOOTSTRAP_DIR/pkgs | |
git clone --recurse-submodules -b v1.35.0 --single-branch --depth 1 --shallow-submodules https://github.com/grpc/grpc | |
becho " * building grpc..." | |
pushd grpc | |
mkdir -p cmake/build | |
pushd cmake/build | |
cmake -DgRPC_INSTALL=ON \ | |
-DgRPC_BUILD_TESTS=OFF \ | |
-DCMAKE_INSTALL_PREFIX=$BOOTSTRAP_DIR/prefix \ | |
../.. | |
make -j $PARALLEL_GRPC_CPUS | |
make install | |
popd # Leaving: cmake/build | |
becho " * building grpc examples" | |
pushd examples/cpp/helloworld | |
mkdir -p cmake/build | |
pushd cmake/build | |
cmake -DCMAKE_PREFIX_PATH=$BOOTSTRAP_DIR/prefix ../.. | |
make -j $PARALLEL_GRPC_CPUS | |
popd # Leaving: cmake/build | |
popd # Leaving: grpc | |
popd # Leaving: $BOOTSTRAP_DIR/pkgs | |
becho " * done - to use this environment, run: source $BOOTSTRAP_DIR/env.sh" | |
becho " * build artifacts are available in $BOOTSTRAP_DIR/pkgs - this can be removed as needed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment