#cargo #cargo-subcommand #cli #crates #lean

bin+lib cargo-diet

Make your crate lean by computing size-optimal include directives for Cargo manifests

8 stable releases

1.2.0 Jul 26, 2020
1.1.5 Jul 25, 2020
1.1.3 May 31, 2020
0.0.0 Mar 18, 2020

#111 in Cargo plugins

Download history 10/week @ 2021-02-23 7/week @ 2021-03-02 15/week @ 2021-03-09 7/week @ 2021-03-16 35/week @ 2021-03-23 15/week @ 2021-03-30 14/week @ 2021-04-06 14/week @ 2021-04-13 47/week @ 2021-04-20 15/week @ 2021-04-27 8/week @ 2021-05-04 8/week @ 2021-05-11 15/week @ 2021-05-18 6/week @ 2021-05-25 8/week @ 2021-06-01 14/week @ 2021-06-08

85 downloads per month

MIT license

30KB
670 lines

Rust Crates.io

cargo diet is a companion program of The Lean Crate Initiative to help computing 'optimal' include directives for your Cargo.toml manifest. 'optimal' here is the smallest size a crate can have while retaining everything relevant to building the code and populating crates.io and lib.rs with useful information on the landing page.

Please note that this opinionated approach won't prevent you to adjust the initial include directive to your liking and needs, without cargo diet interfering with you on subsequent invocations.

asciicast

Usage

  • make the crate lean by editing the Cargo.toml file in place

    • cargo diet
  • simulate how the Cargo.toml file would be edited to obtain a lean crate

    • cargo diet -n or cargo diet --dry-run
  • force computing an include directive even though one exists already

    • cargo diet -r or cargo diet --reset-manifest
    • can also be used with --dry-run such as in cargo diet --reset-manifest --dry-run or cargo diet -rn
  • prevent the crate from exceeding a certain package size (best on CI)

    • cargo diet -n --package-size-limit 50KB
    • See the installation instructions specifically for CI, allowing to quickly download a pre-built binary

Installation

Using Cargo

With a recent version of cargo (obtainable using rustup), the following should work:

cargo install cargo-diet

Using GitHub releases

Pre-built binaries can be found in the releases section of this repository.

You can use an installation script to automate this process:

curl -LSfs https://raw.githubusercontent.com/the-lean-crate/cargo-diet/master/ci/install.sh | \
    sh -s -- --git the-lean-crate/cargo-diet

On CI for controlling the crate package size

Assuming tests are running on a linux box, the following script will install the latest version of cargo diet and run it with flags to assert a crate package size does not exceed 10KB, a value that can freely be chosen.

That way it's easy to get a warning if there are new and possibly unexpected files in one of the directories which are included already.

curl -LSfs https://raw.githubusercontent.com/the-lean-crate/cargo-diet/master/ci/install.sh | \
    sh -s -- --git the-lean-crate/cargo-diet --target x86_64-unknown-linux-musl

cargo diet --dry-run --package-size-limit 10KB

Also have a look at how this is actually used in GitHub Actions.

Development

Run tests

make journey-tests

Learn about other targets

make

Dependencies

~7.5MB
~151K SLoC