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

cargo clean ~/.cargo #3289

Closed
ralt opened this issue Nov 13, 2016 · 17 comments
Closed

cargo clean ~/.cargo #3289

ralt opened this issue Nov 13, 2016 · 17 comments
Labels
A-caching Area: caching of dependencies, repositories, and build artifacts C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-clean S-needs-team-input Status: Needs input from team on whether/how to proceed.

Comments

@ralt
Copy link

ralt commented Nov 13, 2016

Would it be possible to have a cargo clean command for all the downloaded deps in ~/.cargo? I'm currently using a small HDD (Chromebook) and would like to cleanup whatever I can, included sources and the local index (not sure it's in ~/.cargo).

@ralt
Copy link
Author

ralt commented Nov 13, 2016

Also, I'm not sure what I can actually safely delete.

@alexcrichton
Copy link
Member

In general it's always safe to completely rm -rf ~/.cargo (unless you've got your own data there like config, installed crates, rustup, etc). Seems fine to have something like cargo clean --global though!

@dlukes
Copy link

dlukes commented Sep 20, 2017

FWIW, it looks like you can safely delete ~/.cargo/registry and the binaries under ~/.cargo/bin will keep working. At least they did when I moved the registry directory elsewhere.

@carols10cents carols10cents added A-caching Area: caching of dependencies, repositories, and build artifacts C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` labels Sep 29, 2017
@benjamingr
Copy link

Hey Florian - just ran into this - 👍 would have expected this to be built in.

@matthiaskrgr
Copy link
Member

I made a small plugin that prints cache size and can clean out different parts of it, feel free to try it out:
https://github.com/matthiaskrgr/cargo-cache

@alexchandel
Copy link

alexchandel commented Oct 18, 2018

rm -rf ~/.cargo blows away your rustup binaries in PATH, I do not recommend.

@chevdor
Copy link

chevdor commented Oct 19, 2018

The following command in addition to what has been mention may help saving disk space.
Go into the folder containing all your rust projects:

find `pwd` -maxdepth 5 -type d -name 'target' | grep -v supercurrentproject | xargs rm -rf

It wont do anything a cargo build can fix again.

@mcclure
Copy link

mcclure commented Apr 16, 2019

This is a sorta old bug, it seems real weird that this is still not a supported feature of cargo. Most package managers have a "clear cache files" command. I feel like I shouldn't have had to search google to find a github issue with scary "manually delete these files" instructions, I should have been able to find how to do it just by typing "cargo help"…

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Apr 20, 2019

For anyone interested I have released cargo-cache on crates.io a few months ago, cargo install cargo-cache to install.

rm -rf ~/.cargo blows away your rustup binaries in PATH, I do not recommend.

cargo-cache can remove dirs selectively via --remove-dir git-repos,registry-sources (this for example will only remove checkouts of cloned git repos but not touch the original repos and also remove unpacked crate sources).

To be extra sure you can perform a --dry-run first which will tell you the directory paths that would be removed.

If you have any additional ideas or feature requests, I would be glad to hear them. :)

jonhoo pushed a commit to jonhoo/cargo that referenced this issue Nov 12, 2021
This patch adds the `--include-cache` flag to `cargo clean`, which
allows the command to also remove related artifacts from `CARGO_HOME`
such as downloaded `.crate` files in `~/.cargo/cache/` and extracted
source directories in `~/.cargo/src/`.

Note that this feature is not intended to replace the `cargo-cache`
command which does smart cache management. Instead, this command simply
blows away whatever it's asked to delete with no smarts whatsoever.

Fixes rust-lang#3289.
@guillaume-uH57J9
Copy link

Deleting ~/.cargo/registry seems like a decent workaround.

The downside is that it deletes both crates sources and index, so the whole index has to be downloaded all over again after each cleanup, and it's not small.

An option to cleanup source but keep the index would be nice.

@bjorn3
Copy link
Member

bjorn3 commented Apr 3, 2022

You can delete ~/.cargo/registry/{cache,src} to only delete crate sources. (cache has downloaded .crate tarballs, src has unpacked sources)

@johnalanwoods
Copy link

I guess still not a thing...

@weihanglo weihanglo added the S-needs-team-input Status: Needs input from team on whether/how to proceed. label May 17, 2023
@epage
Copy link
Contributor

epage commented May 17, 2023

#10070 added a --with-downloads flag to cargo clean to clear all user-wide downloaded files. The name was felt to be more clear than --global.

My concern with this approach is that cargo clean is a focused on a workspace and this opens a can of worms for user expectations. Does this clean only whats relevant for the current project, for the current project thats not referenced by others, or everything?

We also need to keep in mind other kinds of global caches that we will have

I think it would also help to have a design that also explores prior art

@bjorn3
Copy link
Member

bjorn3 commented Sep 22, 2023

NPM and Composer are package managers for languages that aren't compiled, so there also isn't any cache for compiled artifacts. I don't get what distinction between different types of caches you are trying to make.

@epage
Copy link
Contributor

epage commented Oct 11, 2023

FYI we are working on global cache garbage collection. Its being tracked in #12633

@ehuss
Copy link
Contributor

ehuss commented Nov 28, 2023

I'm going to close in favor of #12633. I don't think this issue tracks anything beyond what is implemented in the tracking issue.

@ehuss ehuss closed this as completed Nov 28, 2023
@kierun
Copy link

kierun commented Apr 17, 2024

I made a small plugin that prints cache size and can clean out different parts of it, feel free to try it out:
matthiaskrgr/cargo-cache

Thank you so much for this tool. 5G of data space saved! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-caching Area: caching of dependencies, repositories, and build artifacts C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-clean S-needs-team-input Status: Needs input from team on whether/how to proceed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.