Skip to content

Moving CARGO_HOME invalidates target caches #10915

@overdrivenpotato

Description

@overdrivenpotato

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-rebuild-detectionArea: rebuild detection and fingerprintingC-bugCategory: bugS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions