百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

cargo-diet

> 编程语言
开源

一个货运伴侣要成为一个"精简箱"(精简箱倡议的成员)

187 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一个货运伴侣要成为一个"精简箱"(精简箱倡议的成员)

cargo diet is a companion program of [The Lean Crate Initiative][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. [lean-crate-initiative]: https://github.com/the-lean-crate/criner

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
  • only print errors

    • cargo diet -q or cargo diet --quiet
  • 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
  • make the workspace lean

    • cargo diet falls back to the workspace's default members
    • make a specific package lean: cargo diet -p my-crate
    • make every package lean: cargo diet --workspace
    • make every package lean except a few: cargo diet --workspace --exclude my-crate
    • skip private packages with cargo diet --workspace --ignore-private

Installation

Using Cargo

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

bash
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:

bash
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.

bash
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

bash
make journey-tests

Learn about other targets

make

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rust

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言