rust: support SCCACHE_BASEDIRS across checkout roots - #2794
Open
pamarcos wants to merge 7 commits into
Open
Conversation
SCCACHE_BASEDIRS now normalizes cwd, CARGO_MANIFEST_DIR, CARGO_WORKSPACE_DIR, CARGO_TARGET_TMPDIR, CARGO_MANIFEST_PATH, CARGO_BIN_EXE_*, dep-info env var values, and the concatenated argument string in the Rust compiler's hash key computation. This enables cache hits when the same crate is compiled from different absolute paths on different machines (e.g., CI runners with different checkout roots). strip_basedir_prefix now also matches when the value equals the basedir minus its trailing '/', so `cwd == basedir` strips to the empty string rather than passing through. Without this, two machines with different checkout paths produced different hashes even with matching basedirs -- the feature's central claim.
mozilla#2652 mozilla#2678 Keep rustc-reported environment dependencies location-sensitive and hash PGO data and LLVM plugins before normalizing their paths. Preserve non-path argument bytes on Windows and use conservative matching for non-ASCII input. Handle exact and overlapping basedirs consistently, bump the Rust cache-key version, and document that embedded paths still require compiler remapping.
mozilla#2652 mozilla#2678 Replace broad Rust argument scanning with normalization of explicit remap prefixes and path-valued Cargo variables. Hash the actual path produced by rustc remapping, honoring scope and mapping precedence, while keeping unremapped working directories location-sensitive. Frame normalized values to prevent absolute and relative inputs from sharing a key. Reduce the mock and integration-test changes, and leave profile and plugin paths location-sensitive.
Hash effective source paths without conflating duplicate remaps, and preserve Cargo path values whenever procedural macros can run. Honor rustc remap-scope precedence, keep non-identity distributed path transforms local, add CARGO_INSTALL_ROOT coverage, and bump the key version.
Version 7 was introduced by this unmerged change series, so later refinements do not require another upstream cache-key version.
Collaborator
|
Long comment #0 written by a llm isn't useful... Please make it shorter |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2794 +/- ##
==========================================
- Coverage 74.32% 74.23% -0.10%
==========================================
Files 71 72 +1
Lines 40789 40555 -234
==========================================
- Hits 30318 30107 -211
+ Misses 10471 10448 -23 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Author
Roger. I cut most of it. Left the implementation details available in case someone's interested, though. |
Build expected remapped paths with Path::join because rustc uses platform-native separators. This fixes the Windows test matrix without changing remap behavior.
Exercise malformed and nonmatching remap values, separated scope syntax, and absolute source arguments. Coverage report: https://app.codecov.io/gh/mozilla/sccache/pull/2794?src=pr&el=tree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First, I want to point that I've used GPT-5.6 Sol to assist me with the work. However, I've reviewed the code and tested it.
Rust compilation currently includes checkout-specific paths in its cache key, so the existing
SCCACHE_BASEDIRSsupport does not provide cross-checkout cache hits for Rust crates.This adds Rust support while preserving location sensitivity for path inputs that are not safely covered by compiler remapping. In particular, normalization requires an effective
--remap-path-prefixcovering the working directory with the default orallremap scope. Without that compiler-side remapping, the working directory and other path-sensitive inputs remain exact.This work is based on #2678 (Matt remains the author of the imported baseline commit). I also found that there's a similar PR at johnkferguson#1. Not sure why a PR upstream was never created.
So, I decided to create this PR because the other ones seem not to be followed up, but I'm happy to close this as a duplicate if the others are planned to be merged.
Implementation details
--remap-path-prefixvalues, preserving the destination,mapping precedence, component matching, and final remap scope;
multiple sources map to the same virtual path;
env!,option_env!, profiles, plugins, and unremapped paths location-sensitive;CARGO_*variables, includingCARGO_INSTALL_ROOT, only when the working directory is remapped, there are no explicit externs,and crate search paths contain no dynamic libraries;
6to7;remap; and
SCCACHE_BASEDIRSprefix stripping for non-ASCII Windows values.This deliberately avoids scanning arbitrary argument, linker, environment, or replacement-path bytes. Those values may affect compiler output without being rewritten by
rustc, so stripping them from the key could return an artifact containing paths or semantics from another checkout.Full provenance and related discussions
Direct lineage
CCACHE_BASEDIRequivalent.SCCACHE_BASEDIRSfoundation for C/C++.--remap-path-prefixcompilations cacheable.CARGO_ENCODED_RUSTFLAGS, which often carries the remap.Independent implementations and experiments
CARGO_INSTALL_ROOT, and reported 98.6% hit rate.zccache.SCCACHE_BASEDIRS.Cache-key and artifact-safety context
CARGO_*variables should affect Rust keys.CARGO_*variables.--remap-path-prefixvalues.CARGO_HOMEchanges path-sensitive artifacts/fingerprints.trim-pathsand remap-scope tracking issue.Benchmarks building ClickHouse
Running on a AMD Ryzen 9 9950X with 96G
The interesting part here is that using the new client-side architecture, it slows down a lot. I'll probably create a separate issue to point that.
Closes: #2652
Closes: #2765
Related: #2678
Related: #2595