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

Proposal: Adding a prune command/flag to the cargo CLI #13234

Open
coillteoir opened this issue Jan 2, 2024 · 4 comments
Open

Proposal: Adding a prune command/flag to the cargo CLI #13234

coillteoir opened this issue Jan 2, 2024 · 4 comments
Labels
A-crate-dependencies Area: [dependencies] of any kind C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix

Comments

@coillteoir
Copy link

Problem

Dependencies may be left orphaned or unused in a project as it grows and changes. This can increase build times and storage requirements for developer workstations. While it is up to developers to ensure their dependencies are in order, issuing a cargo command to remove these dependencies would be beneficial.

This seems like a common enough use case among developers to integrate it with the Cargo CLI.

Proposed Solution

Implementing a prune command cargo prune --[flags] to automatically mark unused dependencies. Some flags to consider would be a dry-run flag, dev dependencies only, and more.

Notes

Docker has a similar command docker image prune which will remove all unused images in a local registry. docs

Npm has a similar solution. docs

There is an existing solution to this problem. github

@coillteoir coillteoir added C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage. labels Jan 2, 2024
@epage
Copy link
Contributor

epage commented Jan 2, 2024

Huh, I thought we had an issue for this but I can't find it.

Existing solutions

The big challenge with this is combining reliability with being able to detect unused deps across all build configurations.

If we did this, I imagine this would work better to be a lint controlled by #12235 that would support cargo fix removing the dependency.

@epage epage added the A-crate-dependencies Area: [dependencies] of any kind label Jan 2, 2024
@ehuss
Copy link
Contributor

ehuss commented Jan 2, 2024

I think the primary issue tracking this is rust-lang/rust#57274, which contains some commentary about why this is very hard and some ideas for solutions.

@Eh2406
Copy link
Contributor

Eh2406 commented Jan 2, 2024

By the way, the link npm and docker commands are not removing the unused dependency requirement they are instead cleaning up the built artifacts. To translate cargo they are cleaning the target directory, not the cargo.toml. So the work on GC is relevant, at least based on links if not the description.

@coillteoir
Copy link
Author

Ah okay, thank you. I knew docker's prune is just to remove images without running containers, I thought npm was tidying up unused dependencies.

@weihanglo weihanglo added S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix and removed S-triage Status: This issue is waiting on initial triage. labels Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-crate-dependencies Area: [dependencies] of any kind C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix
Projects
None yet
Development

No branches or pull requests

5 participants