@@ -12,6 +12,34 @@ 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+ if [ -n " $CUDA_VERSION " ]; then
23+ # TODO: Remove this
24+ git clone https://github.com/pytorch/sccache
25+ else
26+ git clone https://github.com/mozilla/sccache -b v0.8.2
27+ fi
28+ cd sccache
29+ echo " Building sccache"
30+ cargo build --release
31+ cp target/release/sccache /opt/cache/bin
32+ echo " Cleaning up"
33+ cd ..
34+ rm -rf sccache
35+ apt-get remove -y cargo rustc
36+ apt-get autoclean && apt-get clean
37+
38+ echo " Downloading old sccache binary from S3 repo for PCH builds"
39+ curl --retry 3 https://s3.amazonaws.com/ossci-linux/sccache -o /opt/cache/bin/sccache-0.2.14a
40+ chmod 755 /opt/cache/bin/sccache-0.2.14a
41+ }
42+
1543install_binary () {
1644 echo " Downloading sccache binary from S3 repo"
1745 curl --retry 3 https://s3.amazonaws.com/ossci-linux/sccache -o /opt/cache/bin/sccache
@@ -26,11 +54,33 @@ export PATH="/opt/cache/bin:$PATH"
2654# https://github.com/pytorch/sccache has started failing mysteriously
2755# in which sccache server couldn't start with the following error:
2856# sccache: error: Invalid argument (os error 22)
29- install_binary
57+ install_ubuntu
3058
3159function write_sccache_stub() {
3260 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} "
61+ if [ $1 == " gcc" ]; then
62+ # Do not call sccache recursively when dumping preprocessor argument
63+ # For some reason it's very important for the first cached nvcc invocation
64+ cat > " /opt/cache/bin/$1 " << EOF
65+ #!/bin/sh
66+ if [ "\$ 1" = "-E" ] || [ "\$ 2" = "-E" ]; then
67+ exec $( which $1 ) "\$ @"
68+ elif [ \$ (env -u LD_PRELOAD ps -p \$ PPID -o comm=) != sccache ]; then
69+ exec sccache $( which $1 ) "\$ @"
70+ else
71+ exec $( which $1 ) "\$ @"
72+ fi
73+ EOF
74+ else
75+ cat > " /opt/cache/bin/$1 " << EOF
76+ #!/bin/sh
77+ if [ \$ (env -u LD_PRELOAD ps -p \$ PPID -o comm=) != sccache ]; then
78+ exec sccache $( which $1 ) "\$ @"
79+ else
80+ exec $( which $1 ) "\$ @"
81+ fi
82+ EOF
83+ fi
3484 chmod a+x " /opt/cache/bin/${BINARY} "
3585}
3686
@@ -44,7 +94,7 @@ init_sccache() {
4494
4595 # NB: This function is adopted from PyTorch core at
4696 # https://github.com/pytorch/pytorch/blob/main/.ci/pytorch/common-build.sh
47- as_ci_user sccache --stop-server > /dev/null 2>&1 || true
97+ as_ci_user sccache --stop-server > /dev/null 2>&1 || true
4898 rm -f " ${SCCACHE_ERROR_LOG} " || true
4999
50100 # Clear sccache stats before using it
0 commit comments