Provide cargo clean --except-locked
to keep target/
small in re-used CI caches
#12138
Labels
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.
Problem
When caching
target/
in CI, the cache is uploaded and downloaded frequently and must remain manageable in size.Whenever dependencies have been updated, e.g. by renovate-bot, new versions of crates are compiled and cached in
target/deps/
while old versions are never removed.cargo clean
removes all build artifacts, including those of current dependencies - which is not desirable.Proposed Solution
cargo clean --except-locked
would inspect theCargo.lock
file of the project or workspace and keep all build artifacts of currently locked dependency versions. All other artifacts are deleted, as they would be withcargo clean
.Notes
Arguably
cargo clean
should exactly do that (clean up, not delete everything), while its current behavior can be easily done by hand with arm -rf ./target
.I assume, however, that it is too late to change the default behavior at this point.
The text was updated successfully, but these errors were encountered: