@@ -12,6 +12,26 @@ set -ex
1212# shellcheck source=/dev/null
1313source " $( dirname " ${BASH_SOURCE[0]} " ) /utils.sh"
1414
15+ install_ubuntu () {
16+ echo " Preparing to build sccache from source"
17+ apt-get update
18+ # libssl-dev will not work as it is upgraded to libssl3 in Ubuntu-22.04.
19+ # Instead use lib and headers from OpenSSL1.1 installed in `install_openssl.sh``
20+ apt-get install -y cargo
21+ echo " Checking out sccache repo"
22+ git clone https://github.com/mozilla/sccache -b v0.8.2
23+
24+ cd sccache
25+ echo " Building sccache"
26+ cargo build --release
27+ cp target/release/sccache /opt/cache/bin
28+ echo " Cleaning up"
29+ cd ..
30+ rm -rf sccache
31+ apt-get remove -y cargo rustc
32+ apt-get autoclean && apt-get clean
33+ }
34+
1535install_binary () {
1636 echo " Downloading sccache binary from S3 repo"
1737 curl --retry 3 https://s3.amazonaws.com/ossci-linux/sccache -o /opt/cache/bin/sccache
@@ -22,15 +42,33 @@ mkdir -p /opt/cache/bin
2242sed -e ' s|PATH="\(.*\)"|PATH="/opt/cache/bin:\1"|g' -i /etc/environment
2343export PATH=" /opt/cache/bin:$PATH "
2444
25- # NB: Install the pre-built binary from S3 as building from source
26- # https://github.com/pytorch/sccache has started failing mysteriously
27- # in which sccache server couldn't start with the following error:
28- # sccache: error: Invalid argument (os error 22)
29- install_binary
45+ install_ubuntu
3046
3147function write_sccache_stub() {
3248 BINARY=$1
33- printf " #!/bin/sh\nif [ \$ (env -u LD_PRELOAD ps -p \$ PPID -o comm=) != sccache ]; then\n exec sccache %s \"\$ @\" \nelse\n exec %s \"\$ @\" \nfi" " $( which " ${BINARY} " ) " " $( which " ${BINARY} " ) " > " /opt/cache/bin/${BINARY} "
49+ if [ $1 == " gcc" ]; then
50+ # Do not call sccache recursively when dumping preprocessor argument
51+ # For some reason it's very important for the first cached nvcc invocation
52+ cat > " /opt/cache/bin/$1 " << EOF
53+ #!/bin/sh
54+ if [ "\$ 1" = "-E" ] || [ "\$ 2" = "-E" ]; then
55+ exec $( which $1 ) "\$ @"
56+ elif [ \$ (env -u LD_PRELOAD ps -p \$ PPID -o comm=) != sccache ]; then
57+ exec sccache $( which $1 ) "\$ @"
58+ else
59+ exec $( which $1 ) "\$ @"
60+ fi
61+ EOF
62+ else
63+ cat > " /opt/cache/bin/$1 " << EOF
64+ #!/bin/sh
65+ if [ \$ (env -u LD_PRELOAD ps -p \$ PPID -o comm=) != sccache ]; then
66+ exec sccache $( which $1 ) "\$ @"
67+ else
68+ exec $( which $1 ) "\$ @"
69+ fi
70+ EOF
71+ fi
3472 chmod a+x " /opt/cache/bin/${BINARY} "
3573}
3674
@@ -44,7 +82,7 @@ init_sccache() {
4482
4583 # NB: This function is adopted from PyTorch core at
4684 # https://github.com/pytorch/pytorch/blob/main/.ci/pytorch/common-build.sh
47- as_ci_user sccache --stop-server > /dev/null 2>&1 || true
85+ as_ci_user sccache --stop-server > /dev/null 2>&1 || true
4886 rm -f " ${SCCACHE_ERROR_LOG} " || true
4987
5088 # Clear sccache stats before using it
0 commit comments