Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upHave an option to make Cargo attempt to clean up after itself. #6229
Comments
dwijnand
added
Command-clean
C-cleanup
C-feature-request
labels
Oct 27, 2018
This comment has been minimized.
This comment has been minimized.
|
As I said on that thread I would love to see this experimented with out of tree. There are a lot of good heuristics that may work well. When we see which are widely useful we can talk about bringing them in. If out of tree development is not possible do to limitations of cargo, (like dose cargo leave a timestamp of the most recent time it used an artefact,) then let's see about getting it to be possible. I'd love a tool based on last used date. I'd love a tool that compared the version of the compiler used to the installed ones by rustup. I'd love to point it at a parent folder and have it search for all the places I hid a rust project. |
This comment has been minimized.
This comment has been minimized.
|
Actually I'm now wondering if this could be done as a cargo plugin? I confess I know nothing about how cargo's internals are structured. |
This comment has been minimized.
This comment has been minimized.
holmgr
commented
Oct 29, 2018
•
|
I would think a cargo plugin would work, if the needed information can be gained from cargo.
Might hack on something for this during this week if there is any interest in it :) |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton Is there a good way to determine the last time a file in @holmgr I would definitely be interested in seeing an initial hack! |
This comment has been minimized.
This comment has been minimized.
|
I don't think there's a great way to figure it out unfortunately other than running a full build and just seeing what was used (and considering everything else as unused). Supporting this in a first-class fashion I think will be a nontrivial undertaking! |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton I agree that "first-class" support will be hard, hence my encouragement of "out of tree" "derty hack" experimentation. Maybe I am missing something important, but at some point cargo has to make the list of things it needs to be on disk (or to build if they are not on disk). How hard would it be for cargo to take that list, for each item on the write a "x.timestamp" file? If all the cargos (that we care about) did that, then an out of tree tool could come along and del files associated with timestamp's that are older than 30 days. For initial testing purposes we could decide that the tool is only compatible with locally bilt cargos from someone's fork, if we are not willing to merge do to the feature freeze. |
This comment has been minimized.
This comment has been minimized.
|
Oh small things here and there probably aren't that hard I think? We could certainly try to patch the situation in the meantime! |
This comment has been minimized.
This comment has been minimized.
holmgr
commented
Nov 7, 2018
•
|
So I have been doing a bit of hacking on this issue to see what is possible, or not (https://github.com/holmgr/cargo-sweep). Since this type of solution is likely not the way we want to do this (i.e letting the tool maintain the timestamp files) I have been doing some digging around to see what else is possible. Finally, the most complex solution is to let cargo output the timestamp files as we discussed above. I have been searching through the source a bit, but not yet found a good place to place that code (partially because I am unsure of exactly which files we are interested in cleaning). |
This comment has been minimized.
This comment has been minimized.
holmgr
commented
Nov 9, 2018
|
Another update :) So I went with the second approach outlined in my comment above which seems to be the most straightforward solution, and it seems to be working pretty well. It is now published on crates.io and source is here. Hopefully this solves at least the basic needs for cleaning. |
This comment has been minimized.
This comment has been minimized.
|
@pietroalbini suggested a command that would clean up files needed to build a dependency but not needed to use that dependency. The big question is what are "they"? What are the minimum files required to use a dependency? |
This comment has been minimized.
This comment has been minimized.
|
cc some other discussion going on at #5885 (comment) |
icefoxen commentedOct 27, 2018
Cargo leaves build artifacts around forever, without making any attempt to ever clean them up. This is a feature but also a somewhat inconvenient one since your
./targetfolder grows forever, and this can make life harder for large projects and CI systems and such. You either delete everything and rebuild everything all the time, wasting a lot of time, or you deal with potentially very large folders. This also makes life harder for the idea of cargo eventually being able to share build artifacts between projects, as described in this reddit thread.I propose to add a simple, conservative command line flag/config option for Cargo to attempt to clean up files that have not been used in any builds for a while. Something like
--clean-unused 30dto remove any files that haven't been used in any builds that have run in the last 30 days. Hopefully this will provide a simple and useful tool for solving this sort of problem in many cases, while not resulting in unnecessary rebuilding of things. It also should pave the way for experimenting with more sophisticated decision-making about which build artifacts to keep and which to delete in the future.Related: #5026