#!/bin/bash set -ex install_ubuntu() { echo "Preparing to build sccache from source" apt-get update # libssl-dev will not work as it is upgraded to libssl3 in Ubuntu-22.04. # Instead use lib and headers from OpenSSL1.1 installed in `install_openssl.sh`` apt-get install -y cargo echo "Checking out sccache repo" git clone https://github.com/mozilla/sccache -b v0.10.0 cd sccache echo "Building sccache" cargo build --release cp target/release/sccache /opt/cache/bin echo "Cleaning up" cd .. rm -rf sccache apt-get remove -y cargo rustc apt-get autoclean && apt-get clean echo "Downloading old sccache binary from S3 repo for PCH builds" curl --retry 3 https://s3.amazonaws.com/ossci-linux/sccache -o /opt/cache/bin/sccache-0.2.14a chmod 755 /opt/cache/bin/sccache-0.2.14a } install_binary() { echo "Downloading sccache binary from S3 repo" curl --retry 3 https://s3.amazonaws.com/ossci-linux/sccache -o /opt/cache/bin/sccache } mkdir -p /opt/cache/bin mkdir -p /opt/cache/lib sed -e 's|PATH="\(.*\)"|PATH="/opt/cache/bin:\1"|g' -i /etc/environment export PATH="/opt/cache/bin:$PATH" # Setup compiler cache install_ubuntu chmod a+x /opt/cache/bin/sccache function write_sccache_stub() { # Unset LD_PRELOAD for ps because of asan + ps issues # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90589 if [ $1 == "gcc" ]; then # Do not call sccache recursively when dumping preprocessor argument # For some reason it's very important for the first cached nvcc invocation cat >"/opt/cache/bin/$1" <"/opt/cache/bin/$1" < clang -> clang-?? # Final link in symlink chain must point back to original directory. # Original compiler is moved one directory deeper. Wrapper replaces it. function write_sccache_stub_rocm() { OLDCOMP=$1 COMPNAME=$(basename $OLDCOMP) TOPDIR=$(dirname $OLDCOMP) WRAPPED="$TOPDIR/original/$COMPNAME" mv "$OLDCOMP" "$WRAPPED" printf "#!/bin/sh\nexec sccache $WRAPPED \"\$@\"" >"$OLDCOMP" chmod a+x "$OLDCOMP" } if [[ -e "/opt/rocm/hcc/bin/hcc" ]]; then # ROCm 3.3 or earlier. mkdir /opt/rocm/hcc/bin/original write_sccache_stub_rocm /opt/rocm/hcc/bin/hcc write_sccache_stub_rocm /opt/rocm/hcc/bin/clang write_sccache_stub_rocm /opt/rocm/hcc/bin/clang++ # Fix last link in symlink chain, clang points to versioned clang in prior dir pushd /opt/rocm/hcc/bin/original ln -s ../$(readlink clang) popd elif [[ -e "/opt/rocm/llvm/bin/clang" ]]; then # ROCm 3.5 and beyond. mkdir /opt/rocm/llvm/bin/original write_sccache_stub_rocm /opt/rocm/llvm/bin/clang write_sccache_stub_rocm /opt/rocm/llvm/bin/clang++ # Fix last link in symlink chain, clang points to versioned clang in prior dir pushd /opt/rocm/llvm/bin/original ln -s ../$(readlink clang) popd else echo "Cannot find ROCm compiler." exit 1 fi fi