Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support shared target directory #71

Open
inodentry opened this issue Oct 9, 2022 · 1 comment
Open

Support shared target directory #71

inodentry opened this issue Oct 9, 2022 · 1 comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.

Comments

@inodentry
Copy link

I (and many other people) configue cargo to use a single target dir shared between all projects, by putting something like this in ~/.cargo/config:

[build]
target-dir = "/Users/iyes/.cargo/target"

That way all projects put their build artifacts in the same place, allowing dependencies to be reused, etc. shortening clean build times.

However, currently there is no nice way to remove only outdated build artifacts from it (say, when updating a nightly toolchain), without outright deleting everything. cargo sweep could be the perfect tool for this. However, it is currently unsupported, as the tool expects to be run on project dirs.

@jyn514
Copy link
Collaborator

jyn514 commented Nov 26, 2022

This is an interesting problem. sweep does support cleaning that global target dir, but only if you're already in a project:

(bash@pop-os) ~/rust-community/cargo-sweep [18:42:07, ci]
; CARGO_TARGET_DIR=$CARGO_HOME/target cargo sweep -i
[INFO] Using all installed toolchains: ["stable-x86_64-unknown-linux-gnu", "beta-2022-05-20-x86_64-unknown-linux-gnu", ...]
[INFO] Cleaned 0.00 bytes
; cd /tmp
; CARGO_TARGET_DIR=$CARGO_HOME/target cargo sweep -i
[ERROR] Failed to clean "/tmp" as it is not a cargo project.

The problem is that sweep is detecting the target directory with the Rust equivalent of cargo metadata | jq .target_directory, and Cargo of course only works when there's a Cargo.toml.

There are two possible ways I think we could solve this:

  • Hard-code that sweep should read ~/.cargo and any applicable keys. This seems hard to maintain; any new feature cargo adds means that someone could configure a shared dir that sweep doesn't know about.
  • Try to create a new dummy directory and run cargo metadata from there. This has the downside that we end up doing more IO, and need to figure out a temporary directory where we can put the project.

@inodentry can you talk more about why you want to sweep the global directory when you're not in a cargo project? Is this working for you in a project, and you just want the convenience of running it from /home or wherever?

@jyn514 jyn514 added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Nov 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

No branches or pull requests

2 participants