Repository navigation
rust: cache incremental compiles with SCCACHE_ALLOW_INCREMENTAL=cache - #3020
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3020 +/- ##
==========================================
- Coverage 79.16% 72.51% -6.66%
==========================================
Files 75 75
Lines 46166 44867 -1299
==========================================
- Hits 36548 32535 -4013
- Misses 9618 12332 +2714 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
39acd81 to
82dc1c0
Compare
82dc1c0 to
95dfcb2
Compare
| // With the opt-in, `-C incremental=` compiles are left uncached (CannotCache), | ||
| // or cached with SCCACHE_CACHE_INCREMENTAL=1. | ||
| let allow_incremental = env::var("SCCACHE_ALLOW_INCREMENTAL").as_deref() == Ok("1") | ||
| || env::var("SCCACHE_CACHE_INCREMENTAL").is_ok_and(|v| { |
There was a problem hiding this comment.
two variables for one feature is a bit confusing.
maybe SCCACHE_ALLOW_INCREMENTAL=cache as you suggested would be simpler, no?
There was a problem hiding this comment.
Switched to SCCACHE_ALLOW_INCREMENTAL=cache. 1 keeps its current meaning.
| * Procedural macros that read files from the filesystem may not be cached properly. | ||
| * A procedural macro is identified by its crate metadata, so a change to native code it links, with no change to its Rust source or dependencies, is not seen. | ||
| * `rustc`'s incremental compilation needs to be disabled. See [The Cargo Book](https://doc.rust-lang.org/cargo/reference/profiles.html#incremental). sccache exits with an error when `CARGO_INCREMENTAL=1` is set, unless `SCCACHE_ALLOW_INCREMENTAL=1` is set: then only the incremental crates (workspace members and path dependencies) go uncached. | ||
| * Crates compiled with `rustc`'s incremental compilation (by default, in the debug profile, cargo's workspace members and path dependencies, see [The Cargo Book](https://doc.rust-lang.org/cargo/reference/profiles.html#incremental)) are not cached. sccache exits with an error when `CARGO_INCREMENTAL=1` is set, unless `SCCACHE_ALLOW_INCREMENTAL=1` is set: then only the incremental crates go uncached. |
There was a problem hiding this comment.
"are not cached" is a bit misleading now that they can be, maybe "are not cached by default"?
There was a problem hiding this comment.
Changed to "are not cached by default", also in the README.
7bfeedf to
7f68e32
Compare
|
Squashed the fixes into one commit. Besides the two you asked for, I deduplicated the two cargo incremental tests, made |
7f68e32 to
6768db0
Compare
Crates compiled with `-C incremental=<dir>` (cargo's default for workspace members and path dependencies in the dev profile) are never cached, so a cache shared between checkouts or machines misses on them whenever they are not built locally yet. With SCCACHE_ALLOW_INCREMENTAL=cache in the environment of the compile, they are cached; like `1`, it also allows CARGO_INCREMENTAL=1. The incremental directory is left out of the cache key and out of the dep-info and file-names runs of rustc, but the key records that the compile is incremental, since rustc's outputs differ (e.g. the default codegen-units). A hit leaves the incremental directory as it was; a miss compiles incrementally as asked. Such compiles are not distributed. On Windows the variable's name is matched ignoring case, as env::var does in the client. Without it, nothing changes, keys included.
6768db0 to
4bb282f
Compare
|
Thanks for your PR |
Crates cargo compiles with
-C incremental(workspace members and path dependencies in the dev profile) are never cached. #257/#259 excluded them because rustc reusing its incremental state beats a cache fetch, and a hit leaves that state stale. That holds for local rebuilds, but with a shared cache these crates miss whenever nothing is built locally yet (fresh checkout or worktree, CI). On a ~300-crate workspace on Windows, a second checkout from an empty target went from 2,327 to 778 CPU seconds; the cost is the first rebuild after an edit, 390 CPU seconds instead of ~95.With SCCACHE_ALLOW_INCREMENTAL=cache these compiles are cached;
1keeps its meaning. The incremental directory is left out of the key and out of the dep-info and file-names runs, but the key still records that the compile is incremental. They are not distributed. Withoutcachenothing changes, keys included, so CACHE_VERSION is unchanged. On Windows the server matches the name ignoring case, asenv::vardoes in the client.Tested on Windows with fmt, clippy,
cargo test --locked --liband tests/sccache_cargo.rs; system and dist were not run.Refs #236