#cargo-build #artifact #garbage #outdated #collect #gc

build cargo-gc-bin

Garbage collect outdated cargo build artifacts

5 releases

0.1.4 May 7, 2024
0.1.3 Nov 15, 2023
0.1.2 Oct 9, 2023
0.1.1 Aug 24, 2023
0.1.0 Aug 24, 2023

#90 in Build Utils

Download history 8420/week @ 2024-07-27 4061/week @ 2024-08-03 2871/week @ 2024-08-10 2891/week @ 2024-08-17 3333/week @ 2024-08-24 3371/week @ 2024-08-31 2821/week @ 2024-09-07 2266/week @ 2024-09-14 2161/week @ 2024-09-21 1375/week @ 2024-09-28 2156/week @ 2024-10-05 2649/week @ 2024-10-12 2527/week @ 2024-10-19 3726/week @ 2024-10-26 3279/week @ 2024-11-02 2768/week @ 2024-11-09

12,831 downloads per month

Apache-2.0

13KB
214 lines

cargo gc

Crates.io License

Cargo extension to recycle outdated build artifacts. And try the best to avoid recompilation.

Usage

Install it with cargo:

cargo install cargo-gc-bin

The executable is cargo-gc. You can invoke it with cargo gc command:

cargo gc

It will check and remove all outdated build artifacts in the current project. See cargo gc --help for more information.

Limitations / Known issues

  • It needs to invoke cargo build that takes lots of time.
  • Need to re-link after GC
  • cargo check will re-check from scratch

Explaination

cargo gc uses the output information from cargo build to help recognize build artifacts in use, and removes all others. In the current implementation, top-level arficats are not recognized and leads to re-link after GC.

Compare to other utils like cargo sweep, this one is based on the informations provided by cargo itself rather than filesystem timestamp. So it can be more accurate and still avoiding recompilation as much as possible.

Next steps

Technically, it's possible to implement a "perfect" GC that can remove all outdated artifacts without any recompilation. And done this in a totally static way (i.e., without invoking cargo build). As the tuple ("crate name", "fingreprint") can be computed outside of cargo.

Dependencies

~5–12MB
~146K SLoC