diff --git a/.ci/docker/common/install_cache.sh b/.ci/docker/common/install_cache.sh index 45edb19b107..f17b4cc6068 100755 --- a/.ci/docker/common/install_cache.sh +++ b/.ci/docker/common/install_cache.sh @@ -12,6 +12,26 @@ set -ex # shellcheck source=/dev/null source "$(dirname "${BASH_SOURCE[0]}")/utils.sh" +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.8.2 + + 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 +} + install_binary() { echo "Downloading sccache binary from S3 repo" curl --retry 3 https://s3.amazonaws.com/ossci-linux/sccache -o /opt/cache/bin/sccache @@ -22,15 +42,33 @@ mkdir -p /opt/cache/bin sed -e 's|PATH="\(.*\)"|PATH="/opt/cache/bin:\1"|g' -i /etc/environment export PATH="/opt/cache/bin:$PATH" -# NB: Install the pre-built binary from S3 as building from source -# https://github.com/pytorch/sccache has started failing mysteriously -# in which sccache server couldn't start with the following error: -# sccache: error: Invalid argument (os error 22) -install_binary +install_ubuntu function write_sccache_stub() { BINARY=$1 - 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}" + 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" < /dev/null 2>&1 || true + as_ci_user sccache --stop-server >/dev/null 2>&1 || true rm -f "${SCCACHE_ERROR_LOG}" || true # Clear sccache stats before using it diff --git a/.ci/docker/ubuntu/Dockerfile b/.ci/docker/ubuntu/Dockerfile index f55504c9700..713a076d617 100644 --- a/.ci/docker/ubuntu/Dockerfile +++ b/.ci/docker/ubuntu/Dockerfile @@ -57,6 +57,7 @@ COPY ./common/utils.sh utils.sh RUN bash ./install_cache.sh && rm install_cache.sh utils.sh ENV SCCACHE_BUCKET ossci-compiler-cache-circleci-v2 ENV SCCACHE_S3_KEY_PREFIX executorch +ENV SCCACHE_REGION us-east-1 ARG TORCH_VERSION COPY ./common/install_pytorch.sh install_pytorch.sh diff --git a/.github/workflows/docker-builds.yml b/.github/workflows/docker-builds.yml index d256af7fcda..9a220a6f29b 100644 --- a/.github/workflows/docker-builds.yml +++ b/.github/workflows/docker-builds.yml @@ -26,6 +26,9 @@ concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }} cancel-in-progress: true +env: + AWS_DEFAULT_REGION: us-east-1 + jobs: docker-build: runs-on: [self-hosted, linux.2xlarge]