Description
I have Rust 1.22 nightly installed. I installed sccache with cargo install sccache
(sccache 0.2.2). I followed instruction to set up RUSTC_WRAPPER=sccache. I noticed that even multiple projects shares same dependencies, sccache will not have cache hits as expected. My OS is Windows 10.
Steps to reproduce:
- Create a snippet project
snippet1
with one dependency and no transitive dependency:
[dependencies]
itoa = "0.3.4"
Cargo.lock may look like
[root]
name = "snippet"
version = "0.1.0"
dependencies = [
"itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "itoa"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8324a32baf01e2ae060e9de58ed0bc2320c9a2833491ee36cd3b4c414de4db8c"
- Copy
snippet1
tosnippet2
with no change. cargo build
thesnippet1
project. Thencargo clean
andcargo build
again. Observe 1 cache hit insccache -s
.cargo build
thesnippet2
project andsccache -s
.
Expected result:
sccache should now report 2 cache hits.
Actual result:
sccache still reports 1 cache hit, indicate itoa 0.3.4 from snippet2
was not a cache hit.
Now, create .cargo/config
file in the parent directory and point a common target-dir
for the two projects. Repeat steps 1-4. sccache will report 2 cache hits.
This shows that sccache probably uses the cargo parameters --out-dir
or even -L dependency
as part of the hash key. I'm not 100% sure if there is any corner case, but this behavior defeats the purpose of sharing common library across projects with sccache.
Related cargo output for snippet1
:
Compiling itoa v0.3.4
Running `sccache rustc --crate-name itoa D:\Application\Rust\Cargo\registry\src\github.1485827954.workers.dev-1ecc6299db9ec823\itoa-0.3.4\src\lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=fd1fa8f333ce5a78 -C extra-filename=-fd1fa8f333ce5a78 --out-dir C:\workspace\snippet1\target\debug\deps -L dependency=C:\workspace\snippet1\target\debug\deps --cap-lints allow`
snippet2
:
Compiling itoa v0.3.4
Running `sccache rustc --crate-name itoa D:\Application\Rust\Cargo\registry\src\github.1485827954.workers.dev-1ecc6299db9ec823\itoa-0.3.4\src\lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=fd1fa8f333ce5a78 -C extra-filename=-fd1fa8f333ce5a78 --out-dir C:\workspace\snippet2\target\debug\deps -L dependency=C:\workspace\snippet2\target\debug\deps --cap-lints allow`