From 42f01a4920e19ece28b9ab3d6f5cbdeda0c66122 Mon Sep 17 00:00:00 2001 From: Till Schneidereit Date: Wed, 17 Sep 2025 20:44:46 +0200 Subject: [PATCH 1/4] ci: Cache Rust compilation and cargo dependencies I noticed that Wasmtime uses almost no cache for its GitHub Actions workflows. Let's see how well adding a cache for `target` plus various `cargo` dirs works. --- .github/actions/install-rust/action.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/actions/install-rust/action.yml b/.github/actions/install-rust/action.yml index e292d8afab62..bb6a0166454b 100644 --- a/.github/actions/install-rust/action.yml +++ b/.github/actions/install-rust/action.yml @@ -74,3 +74,9 @@ runs: - name: Install the WASI target shell: bash run: rustup target add wasm32-wasip1 wasm32-unknown-unknown + + - name: Set up cargo cache + uses: Swatinem/rust-cache@94b28bf00e42c2b783e7dd289d30da129b46838b + with: + cache-all-crates: "true" + cache-workspace-crates: "true" From ae82cb6e4e545bf5acf84308f0d9be99d2507c52 Mon Sep 17 00:00:00 2001 From: Till Schneidereit Date: Wed, 17 Sep 2025 23:45:10 +0200 Subject: [PATCH 2/4] Use dedicated caches for test jobs and nothing else The test jobs are the long pole, and the cache key needs to be derived from the test matrix to work properly. --- .github/actions/install-rust/action.yml | 6 ------ .github/workflows/main.yml | 5 +++++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/actions/install-rust/action.yml b/.github/actions/install-rust/action.yml index bb6a0166454b..e292d8afab62 100644 --- a/.github/actions/install-rust/action.yml +++ b/.github/actions/install-rust/action.yml @@ -74,9 +74,3 @@ runs: - name: Install the WASI target shell: bash run: rustup target add wasm32-wasip1 wasm32-unknown-unknown - - - name: Set up cargo cache - uses: Swatinem/rust-cache@94b28bf00e42c2b783e7dd289d30da129b46838b - with: - cache-all-crates: "true" - cache-workspace-crates: "true" diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 50938004f7f9..8e0ff5526a8c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -675,6 +675,11 @@ jobs: - run: echo CARGO_BUILD_TARGET=${{ matrix.target }} >> $GITHUB_ENV if: matrix.target != '' + - name: Set up cargo cache + uses: Swatinem/rust-cache@94b28bf00e42c2b783e7dd289d30da129b46838b + with: + shared-key: "test-${{ matrix.bucket }}" + # Fix an ICE for now in gcc when compiling zstd with debuginfo (??) - run: echo CFLAGS=-g0 >> $GITHUB_ENV if: matrix.target == 'x86_64-pc-windows-gnu' From 2a577b5f7dde06ce89888731cda6e8e238531a66 Mon Sep 17 00:00:00 2001 From: Till Schneidereit Date: Thu, 18 Sep 2025 00:03:27 +0200 Subject: [PATCH 3/4] Use a viable cache key --- .github/workflows/main.yml | 2 +- ci/build-test-matrix.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8e0ff5526a8c..b2c555ae9544 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -678,7 +678,7 @@ jobs: - name: Set up cargo cache uses: Swatinem/rust-cache@94b28bf00e42c2b783e7dd289d30da129b46838b with: - shared-key: "test-${{ matrix.bucket }}" + shared-key: "test-${{ matrix.cache_key }}" # Fix an ICE for now in gcc when compiling zstd with debuginfo (??) - run: echo CFLAGS=-g0 >> $GITHUB_ENV diff --git a/ci/build-test-matrix.js b/ci/build-test-matrix.js index 95db8b7f7f7f..ce0ffe7cd993 100644 --- a/ci/build-test-matrix.js +++ b/ci/build-test-matrix.js @@ -228,6 +228,7 @@ async function shard(configs) { config, { name: `${config.name} (${Array.from(bucket).join(', ')})`, + cache_key: `${config.name}-${Array.from(bucket).join('-').substring(0, 400)}`, // We run tests via `cargo test --workspace`, so exclude crates that // aren't in this bucket, rather than naming only the crates that are // in this bucket. From 618dcd8a0ab8d22bca32ff7b80208253079b6d2c Mon Sep 17 00:00:00 2001 From: Till Schneidereit Date: Thu, 18 Sep 2025 00:56:17 +0200 Subject: [PATCH 4/4] Use cache for `wasmtime-cli` test bucket only and only store the cache on `main` This brings disk usage for the cache down to about 340MB per platform, which should mean that we're not risking eviction of other, longer-term stable caches. --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b2c555ae9544..0712012f025f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -679,6 +679,8 @@ jobs: uses: Swatinem/rust-cache@94b28bf00e42c2b783e7dd289d30da129b46838b with: shared-key: "test-${{ matrix.cache_key }}" + save-if: ${{ github.ref == 'refs/heads/main' }} + if: endsWith(matrix.cache_key, '-wasmtime-cli') # Fix an ICE for now in gcc when compiling zstd with debuginfo (??) - run: echo CFLAGS=-g0 >> $GITHUB_ENV