Open inodentry opened 1 year ago
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:
~/.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.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?
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
: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.