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 --recursive #11305

Open
LeSnake04 opened this issue Oct 27, 2022 · 8 comments
Open

cargo clean --recursive #11305

LeSnake04 opened this issue Oct 27, 2022 · 8 comments
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-clean S-triage Status: This issue is waiting on initial triage.

Comments

@LeSnake04
Copy link

Problem

Many have a folder with their cargo projects that quickly becomes very big (10 GB+)

Currently users need to go into each project indiviually and run cargo clean to clear storage or use a script or tool that does it for them.

Proposed Solution

A recursive option for the clean subcommand would provide an easy native way to clean folders.

It should scan for projects in the current directory and then run the clean function on each of them.

Notes

No response

@LeSnake04 LeSnake04 added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Oct 27, 2022
@epage
Copy link
Contributor

epage commented Oct 27, 2022

At the moment, cargo has no multi-workspace support, so this would be a first. As such, the flag would need to make that clear and I don't think "recursive" would do that.

This also requires cargo correctly identifying all of the target directories that it recurses into.

Personally, I wonder if #11156 would be a better way for making it easy to clean up everything.

@StyMaar
Copy link

StyMaar commented Oct 27, 2022

Personally, I wonder if #11156 would be a better way for making it easy to clean up everything.

That makes it easier to clean up everything, but on the flip side cargo clean would clean everything every time wouldn't it ?

@epage
Copy link
Contributor

epage commented Oct 27, 2022

That makes it easier to clean up everything, but on the flip side cargo clean would clean everything every time wouldn't it ?

#11156 only makes it so all the target dirs are in the same directory, they are still distinct from each other. cargo metadata would still report a workspace-specific target dir and cargo clean would only clean the target dir for that specific workspace.

@LeSnake04
Copy link
Author

LeSnake04 commented Nov 4, 2022

I think --recursive would fit pretty well since nealy all gnu like cli tools use it as well.

And maybe it makes sense to implement --recursive into cargo globally.

Then the usage would look like this:

cargo --recursive clean

It would search in the current directory and then run the command on all the project founds. If no command specified, it would display all project found.

EDIT:I would also add

cargo --recursive-from ~/Code  clean

An alternative would be a cargo-recursive like cargo find (as reference to gnu find)

cargo find --exec clean

or

cargo find . --exec clean

this might be the easier and less breaking way compared to moving target

@LeSnake04
Copy link
Author

LeSnake04 commented Apr 8, 2023

@epage what do you think about handling it this way?

Instead of --recursive we could also use --find that takes an optional path, defaulting to the current dir.

Finding projects would be as easy as running WalkDir on the folder and filtering out all files named Cargo.toml

@LeSnake04
Copy link
Author

LeSnake04 commented Apr 8, 2023

I would also make a similar option named --members that apply the subcommand to all members of the current crate

Otherwise actions that are shared between members,like clean, would be executed on every single crate, even though it only needs to be executed once.

Also --members would be pretty useful to e.g. add dependencies to all members or running cargo tarpulin on all of them.

@epage
Copy link
Contributor

epage commented Apr 10, 2023

--members sounds like the --workspace flag we have today.

One option is to develop cargo find as an external command, cargo-find, and experiment with the workflow and see what the adoption looks like.

@LeSnake04
Copy link
Author

LeSnake04 commented Apr 10, 2023

https://lib.rs/crates/cargo-recursive exists, but it doesn't look very popular. Maybe it makes sense to just make something that works for cleaning for now.

@epage epage added the S-triage Status: This issue is waiting on initial triage. label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-clean S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

3 participants