the-lean-crate / cargo-diet

A cargo-companion to become a 'lean crate' (a member of The Lean Crate Initiative)
https://github.com/the-lean-crate/criner
MIT License
156 stars 3 forks source link

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

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