Repository navigation
fix(rust): write dep-info locally not restoring from cache - #2894
Conversation
Also pin that dep-info is a cached output, not written while hashing.
This is currently unused.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2894 +/- ##
==========================================
+ Coverage 77.66% 77.84% +0.17%
==========================================
Files 72 72
Lines 41574 41785 +211
==========================================
+ Hits 32290 32529 +239
+ Misses 9284 9256 -28 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| .arg("--print=target-libdir") | ||
| .env_clear() | ||
| .envs(env_vars.to_vec()); | ||
| let hashed_archive = dist_archive.clone(); |
There was a problem hiding this comment.
do we need this variable? cloning dist_archive inside the async block would do the same
There was a problem hiding this comment.
Seems like it. The async block is async move so a pre clone is needed.
|
|
||
| // Write dep-info from this invocation rather than restoring it from the cache, | ||
| // which may come from another directory or machine (mozilla/sccache#984). | ||
| // The dist toolchain archive is a prerequisite so swapping it triggers a rebuild. |
There was a problem hiding this comment.
on a local cache miss, rustc still gets --emit dep-info and overwrites this file, so the archive prerequisite is dropped, no?
so it ends up in the dep-info on hits but not on local misses
There was a problem hiding this comment.
Yes, I think that is expected. A local miss on main doesn't include the archive either, and that artifact is built by local toolchain, so the archive isn't one of its inputs.
A cache hit keeps it because the entry may come from a distributed compile, which was built by toolchain archive.
I added a comment explaining this.
| })?; | ||
| let path = cwd.join(&dep_info); | ||
| fs::write(&path, text) | ||
| .with_context(|| format!("Failed to write dep-info to {}", path.display()))?; |
There was a problem hiding this comment.
this writes the file even if the compilation fails afterwards
is that ok for cargo? a short comment would help
There was a problem hiding this comment.
Cargo also leaves a dep-info behind when a compilation fail, so it is fine. I added comment with some code permalinks to rustc and cargo.
(I love permalink so we know the source of true in other tools)
A cache entry may come from another directory, or another machine with distributed compilation. Its dep-info names paths that don't exist here (mozilla#984). Cargo only reads prerequisites, so today it is mostly hit by `-Zbinary-dep-depinfo` (build-std). Once Rust cache keys honor `SCCACHE_BASEDIRS` (mozilla#2652), cargo would rebuild forever on stale prerequisites (rust-lang/cargo#17571). Make-style consumers reading rule targets are always affected. sccache already runs `rustc --emit dep-info` while hashing. The dep-info output is now derived from that, with the rules of the real compilation, and written while hashing. It is byte-identical to rustc's own, except for the dist toolchain archive below. The Rust dist outputs rewriter is removed. It remapped dep-info paths from the server, and added the custom dist toolchain archive as a prerequisite (9981926). The archive is now added when writing dep-info, so cache hits get it too. `CACHE_VERSION` is bumped, as older clients would fail to extract dep-info from new entries. Known gap: for a staticlib-only `cargo check`, the written dep-info lacks the `.rmeta` rule. That `.rmeta` was never cached anyway.
7c3b893 to
4ac324f
Compare
weihanglo
left a comment
There was a problem hiding this comment.
Added some lengthy comments to capture some integration details. Let me know if it is appropriate or too much.
| .arg("--print=target-libdir") | ||
| .env_clear() | ||
| .envs(env_vars.to_vec()); | ||
| let hashed_archive = dist_archive.clone(); |
There was a problem hiding this comment.
Seems like it. The async block is async move so a pre clone is needed.
| })?; | ||
| let path = cwd.join(&dep_info); | ||
| fs::write(&path, text) | ||
| .with_context(|| format!("Failed to write dep-info to {}", path.display()))?; |
There was a problem hiding this comment.
Cargo also leaves a dep-info behind when a compilation fail, so it is fine. I added comment with some code permalinks to rustc and cargo.
(I love permalink so we know the source of true in other tools)
|
|
||
| // Write dep-info from this invocation rather than restoring it from the cache, | ||
| // which may come from another directory or machine (mozilla/sccache#984). | ||
| // The dist toolchain archive is a prerequisite so swapping it triggers a rebuild. |
There was a problem hiding this comment.
Yes, I think that is expected. A local miss on main doesn't include the archive either, and that artifact is built by local toolchain, so the archive isn't one of its inputs.
A cache hit keeps it because the entry may come from a distributed compile, which was built by toolchain archive.
I added a comment explaining this.
|
Thanks for the review btw! |
|
Thanks for your PR |
Adopt upstream's local dep-info generation and remove the cached-output rewrite hook. Keep literal environment dependencies, remap destinations, and unremapped source identities in Rust cache keys. Restrict normalization around procedural macros and partial remap scopes. Advance the Rust cache-key version to avoid reusing unsafe entries. Add executable regressions comparing cached and fresh builds across checkouts, alongside a safe cache-hit control. Document the supported cases and conservative Cargo limitations. Related: mozilla#2918 Related: mozilla#2894
What is this
This fixes #984
A cache entry may come from another directory, or another machine with distributed compilation.
Its dep-info names paths that don't exist here.
Cargo only reads prerequisites,
so today it is mostly hit by
-Zbinary-dep-depinfo(build-std).Once Rust cache keys honor
SCCACHE_BASEDIRS(see #2652),cargo would rebuild forever on stale prerequisites (see rust-lang/cargo#17571).
sccache already runs
rustc --emit dep-infowhile hashing.After this PR, the dep-info output is now derived from that, with the rules of the real compilation, and written while hashing. It is byte-identical to rustc's own.
(except for the dist toolchain archive below since sccache need to be aware if that changes)
How to review
Reviewing this commit by commit is highly recommended.
Other notes
The Rust dist outputs rewriter is removed. It remapped dep-info paths from the server, and added the custom dist toolchain archive as a prerequisite (9981926).
The archive is now added when writing dep-info during hashing, so cache hits get it too.
CACHE_VERSIONis also bumped, as older clients would fail to extract dep-info from new entries.🤖 LLM disclosure: Like my previous PRs, this was initially generated by LLM after a series of design discussions, and handcrafted afterwards. I am responsible for the code change.