Skip to content

rust: add support for SCCACHE_BASEDIRS when hashing - #2918

Open
ghoulspa wants to merge 2 commits into
mozilla:mainfrom
ghoulspa:basedirs-rust
Open

ghoulspa wants to merge 2 commits into
mozilla:mainfrom
ghoulspa:basedirs-rust

Conversation

@ghoulspa

Copy link
Copy Markdown

The Rust implementation of the hasher doesn't respect SCCACHE_BASEDIRS currently. This PR adds support for the basedirs during the hashing process, by stripping the basedir from the working directory, the arguments, the CARGO_* variables and the env-dep values.

Not respecting basedirs causes issues when using crates that use OUT_DIR, such as serde, which miss the cache in every new checkout. Path dependency crates also miss the cache because of CARGO_MANIFEST_DIR and the working directory, and every crate that depends on them misses as well, so this fixes that too. This also fixes env-dep values by unescaping them, since rustc doubles their backslashes and the strip wouldn't match otherwise.

This change to the env-dep parser may cause new misses on Windows, once per crate, for anyone whose env-deps contain backslashes, such as serde's OUT_DIR. For all other cache keys there will be no changes, except where you use the new basedirs support.

We also added unit tests which check that the hash keys match when basedirs are in use and differ when they aren't, plus a few edge cases, and an integration test that builds with cargo from two checkouts.

Fixes #2870

@codecov-commenter

codecov-commenter commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.86099% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.22%. Comparing base (78c418b) to head (994db6a).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
tests/sccache_cargo.rs 92.94% 6 Missing ⚠️
src/compiler/rust.rs 99.23% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2918      +/-   ##
==========================================
+ Coverage   78.15%   78.22%   +0.07%     
==========================================
  Files          74       74              
  Lines       43324    43775     +451     
==========================================
+ Hits        33861    34245     +384     
- Misses       9463     9530      +67     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/compiler/rust.rs
Comment thread tests/sccache_cargo.rs Outdated
Comment thread tests/sccache_cargo.rs
rustc escapes backslashes, newlines and carriage returns in them. Keys
change once for crates whose env-deps contain one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread src/compiler/rust.rs
The cwd, the arguments, the CARGO_* variables and the env-dep values are
hashed with the basedirs stripped, so a crate built from another checkout
listed in SCCACHE_BASEDIRS is a hit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants