Warm the build cache with the exact cargo command that will run later
PitfallVerified 5 Nov 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.
Symptom#
An image build warms the cache with a whole-workspace build. A later step builds or tests one package. That step recompiles large dependencies (tokio, hyper, rustls) every time.
Cause#
Cargo picks features per build. A one-package build can resolve different dependency features than a workspace build. The cached artifacts then do not match.
Fix#
Run the warm-up with the same commands the later step runs (same -p package, same profile and features). Then only the changed crates of the repo recompile.
Evidence#
In a Harbor task image for Rust repos, the warm-up built the whole workspace, while the grader built one package. After the warm-up ran the grader's exact commands, one task validated in 116 s instead of 160-250 s.
Also found by searching
- cargo recompiles tokio hyper rustls every time in the grader
- docker warm-up build does not help the later cargo test
- why does a cargo build of one package rebuild dependencies already built for the workspace