Open
Description
Problem
When the CARGO_HOME
folder is moved to a new location, subsequent builds invalidate target
folder caches because source file paths were updated. This is relevant in CI, where a cache folder can be placed in a new location for every build. If the path changes, there is no way to cache crates, so they must be rebuilt every time.
Steps
$ export CARGO_HOME=$(pwd)/home1
$ cargo new foo
Created binary (application) `foo` package
$ cd foo
$ echo 'serde = "*"' >> Cargo.toml
$ cargo build
Updating crates.io index
Downloaded serde v1.0.140
Downloaded 1 crate (76.4 KB) in 0.28s
Compiling serde v1.0.140
Compiling foo v0.1.0 (/private/tmp/repro/foo)
Finished dev [unoptimized + debuginfo] target(s) in 2m 33s
$ cd ..
$ mv home1 home2
$ export CARGO_HOME=$(pwd)/home2
$ cd foo
$ cargo build
Compiling serde v1.0.140
Compiling foo v0.1.0 (/private/tmp/repro/foo)
Finished dev [unoptimized + debuginfo] target(s) in 4.74s
Note that serde
is built twice, after the CARGO_HOME
folder is moved.
Possible Solution(s)
Perhaps it is possible to have the CARGO_HOME
portion of crate build paths replaced with something that does not change?
Notes
No response
Version
No response