Skip to content

Configurable directory for temp files that isn't the target dir #6227

Closed as duplicate of#14125
@kornelski

Description

@kornelski

Currently CARGO_TARGET_DIR is a mix of two distinct functionalities:

  1. location where temporary/intermediate build files are placed
  2. location where final build artifacts are placed

I'm finding that it's useful for me to have these two directories separate, as I treat temporary and non-temporary files differently.

Use-cases:

Working on NFS

I'm using Cargo in a virtual machine to work on a Linux-only project. But I'm a Mac user, so my project is on a network drive in the VM (vagrant), so that I can edit files easily from the host machine.

It's convenient to have built executables in the easily-accessible ./target. OTOH the network drive is very slow, flaky, doesn't support hard links, and it makes rebuilds sloooow, so having intermediate build files in ./target is painful.

Easy cleanup of temp files

Temp dirs in the target directory can be huge — a few GB large. I have an SSD which is almost full, so I can't afford having a few GB of temp files just laying here and there all over the disk, and I have to regularly go and delete the target directories in all projects I'm working on. The problem is that I have my Rust projects intentionally in various folders, so to delete the temp files I have to look for them in several places.

I'd rather set a single system-global temp directory such as /var/tmp/cargo/%some_hash_of_project/ (#6210) which is easy to delete (and on macOS it could be in the proper ~/Library/Caches).

Integration with Xcode

Xcode already has distinction between "intermediate" files and "products". From Xcode's perspective CARGO_TARGET_DIR conflates the two, so it doesn't map well to Xcode's configuration. For cargo-xcode I had to add workaround for this.


I think it could be solved by supporting a variable like CARGO_TEMP_DIR that would configure cargo to place the ./target/<profile>/{build,native,.fingerprint,incremental} directories somewhere inside CARGO_TEMP_DIR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-layoutArea: target output directory layout, naming, and organizationC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-needs-infoStatus: Needs more info, such as a reproduction or more background for a feature request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions