Skip to content

Commit f51aa12

Browse files
committed
Cache the cargo build in CI
Tauri's dependency tree was recompiled from scratch every run, which was the whole 19 minutes. Separate cache keys per profile, pointed at src-tauri where the crate actually lives. Pull requests restore but do not save, so a branch cannot evict main's entry.
1 parent ca3dc45 commit f51aa12

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ jobs:
1919
toolchain: stable
2020
components: clippy, rustfmt
2121

22+
# The crate lives in src-tauri, not the repo root, so point the cache at it
23+
# or it finds no Cargo.lock and silently caches nothing. Tauri pulls a large
24+
# dependency tree and compiling it from scratch was the whole 19 minutes.
25+
# The key is separate from the release job's: this one holds dev profile
26+
# artifacts, that one holds the optimized profile, and they do not overlap.
27+
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2.9.1
28+
with:
29+
workspaces: src-tauri
30+
shared-key: ci-dev
31+
# Pull requests restore the cache but do not write one, so a branch
32+
# cannot evict main's entry with its own half built tree.
33+
save-if: ${{ github.ref == 'refs/heads/main' }}
34+
2235
# No setup-node: windows-latest already ships a Node new enough for Vite
2336
# and for the node --test style suites, so this is one less action to pin.
2437
- name: Frontend

.github/workflows/release.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ jobs:
2020
toolchain: stable
2121
components: clippy, rustfmt
2222

23+
# A separate key from CI's on purpose: this job compiles the optimized
24+
# profile with lto and opt-level z, so it shares almost no artifacts with
25+
# the dev profile CI caches. Tags are infrequent, but dependencies change
26+
# far less often than tags do, so the entry usually survives release to
27+
# release. Always saves: there is no branch here to protect main from.
28+
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2.9.1
29+
with:
30+
workspaces: src-tauri
31+
shared-key: release-opt
32+
2333
# Without the signing key the build still produces an installer, then fails
2434
# at the very end when it cannot write the updater signature. That wastes a
2535
# full Tauri release build, so refuse up front with a message that says what

0 commit comments

Comments
 (0)