Skip to content

Commit c04eb9e

Browse files
authored
Merge pull request rust-lang#621 from tgross35/ci-caching
Add CI caching
2 parents 2fe1fd1 + 13f9ce3 commit c04eb9e

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

.github/workflows/main.yml

+36-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on: [push, pull_request]
44
env:
55
RUSTDOCFLAGS: -Dwarnings
66
RUSTFLAGS: -Dwarnings
7+
RUST_LLVM_VERSION: 18.0-2024-02-13
8+
RUST_COMPILER_RT_ROOT: ./compiler-rt
79

810
jobs:
911
test:
@@ -105,11 +107,28 @@ jobs:
105107
shell: bash
106108
- run: rustup target add ${{ matrix.target }}
107109
- run: rustup component add llvm-tools-preview
110+
- uses: Swatinem/rust-cache@v2
111+
with:
112+
key: ${{ matrix.target }}
113+
- name: Cache Docker layers
114+
uses: actions/cache@v2
115+
if: matrix.os == 'ubuntu-latest'
116+
with:
117+
path: /tmp/.buildx-cache
118+
key: ${{ matrix.target }}-buildx-${{ github.sha }}
119+
restore-keys: ${{ matrix.target }}-buildx-
120+
121+
- name: Cache compiler-rt
122+
id: cache-compiler-rt
123+
uses: actions/cache@v4
124+
with:
125+
path: compiler-rt
126+
key: ${{ runner.os }}-compiler-rt-${{ env.RUST_LLVM_VERSION }}
108127
- name: Download compiler-rt reference sources
128+
if: steps.cache-compiler-rt.outputs.cache-hit != 'true'
109129
run: |
110-
curl -L -o code.tar.gz https://github.com/rust-lang/llvm-project/archive/rustc/18.0-2024-02-13.tar.gz
111-
tar xzf code.tar.gz --strip-components 1 llvm-project-rustc-18.0-2024-02-13/compiler-rt
112-
echo RUST_COMPILER_RT_ROOT=./compiler-rt >> $GITHUB_ENV
130+
curl -L -o code.tar.gz "https://github.com/rust-lang/llvm-project/archive/rustc/${RUST_LLVM_VERSION}.tar.gz"
131+
tar xzf code.tar.gz --strip-components 1 llvm-project-rustc-${RUST_LLVM_VERSION}/compiler-rt
113132
shell: bash
114133

115134
# Non-linux tests just use our raw script
@@ -120,10 +139,23 @@ jobs:
120139
NO_STD: ${{ matrix.no_std }}
121140
TEST_VERBATIM: ${{ matrix.test_verbatim }}
122141

142+
# Configure buildx to use Docker layer caching
143+
- uses: docker/setup-buildx-action@v3
144+
if: matrix.os == 'ubuntu-latest'
145+
123146
# Otherwise we use our docker containers to run builds
124147
- run: cargo generate-lockfile && ./ci/run-docker.sh ${{ matrix.target }}
125148
if: matrix.os == 'ubuntu-latest'
126149

150+
# Workaround to keep Docker cache smaller
151+
# https://github.com/docker/build-push-action/issues/252
152+
# https://github.com/moby/buildkit/issues/1896
153+
- name: Move Docker cache
154+
if: matrix.os == 'ubuntu-latest'
155+
run: |
156+
rm -rf /tmp/.buildx-cache
157+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
158+
127159
rustfmt:
128160
name: Rustfmt
129161
runs-on: ubuntu-latest
@@ -147,6 +179,7 @@ jobs:
147179
- name: Install nightly `clippy`
148180
run: |
149181
rustup set profile minimal && rustup default "nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/clippy)" && rustup component add clippy
182+
- uses: Swatinem/rust-cache@v2
150183
- run: cargo clippy -- -D clippy::all
151184

152185
success:

ci/run-docker.sh

+13-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,19 @@ run() {
4141
export RUST_COMPILER_RT_ROOT=./compiler-rt
4242
fi
4343

44-
docker build \
44+
if [ "$GITHUB_ACTIONS" = "true" ]; then
45+
# Enable Docker image caching on GHA
46+
47+
buildx="buildx"
48+
build_args=(
49+
"--cache-from" "type=local,src=/tmp/.buildx-cache"
50+
"--cache-to" "type=local,dest=/tmp/.buildx-cache-new"
51+
"${build_args[@]:-}"
52+
"--load"
53+
)
54+
fi
55+
56+
docker "${buildx:-}" build \
4557
-t "builtins-$target" \
4658
${build_args[@]:-} \
4759
"ci/docker/$target"

0 commit comments

Comments
 (0)