Cargo Plugins

cat-development-tools::cargo-plugins

Subcommands that extend the capabilities of Cargo.

TopicRust Crates
Buildingcargo-cache, cargo-sweep, and cargo-prune keep disk consumption by build artifacts and other regenerable files under control.
Code Quality & Analysiscargo fmt (built-in) formats your code. cargo clippy (built-in) lints your code. cargo-spellcheck checks for spelling errors.
Dependency Managementcargo-update updates dependencies as recorded in the local lock file (built-in). cargo tree (built-in) displays your dependency tree. Use -d to list crates where more than one version is getting pulled in and what's pulling each version in. cargo-outdated lists packages that have newer versions than what your Cargo.toml and Cargo.lock are pinning. cargo add adds dependencies to your Cargo.toml. cargo rm removes dependencies. cargo-edit edits your Cargo.toml file. It adds cargo add <dependency>, cargo rm <dependency> and cargo upgrade to update your Cargo.toml's versions. This functionality is planned to be part of Cargo itself.
Testing/Benchmarkingcargo test (built-in) runs your tests (built-in, but often considered a plugin). cargo bench (built-in) runs your benchmarks. cargo fuzz or cargo-afl run your fuzz tests.
Code Coveragecargo-tarpaulin runs code coverage analysis.
Documentationcargo doc generates documentation (built-in). cargo-deadlinks checks cargo doc output for broken old-style or manual intra-doc links.
Profilingcargo-flamegraph generates flame graphs for profiling.
Code InspectionUse cargo-asm to investigate what the compiler generates from your code. cargo-expand shows the expanded output from macros. cargo-modules renders a tree or Graphviz graph of the modules within a crate.
Securitycargo-audit checks whether any of your dependencies are of a version that has a security advisory out against them. cargo-geiger identifies dependencies with unsafe code, so you can either audit them or find alternatives.
LicensingUse cargo-about, cargo-deny, cargo-license, or cargo-lichking for license compliance management.
Binary Size Optimizationcargo-bloat identifies what's contributing to your binary's size (eg. modules with generic functions or macros not designed with size-efficiency in mind).
Publishing, Distributioncargo publish publishes your crate to crates.io (built-in). cargo-deb creates Debian packages. cargo-rpm creates RPM packages.
Change Watchingcargo-watch watches your project for changes and rebuilds / re-run a command every time the source changes (e.g. cargo test).

Writing Code

Formatting and Linting

Dependency Management

Building

Watching for Changes

RecipeCratesCategories
cargo watchcargo-watchcat-development-tools::cargo-plugins
cargo limitcargo-limitcat-development-tools::cargo-plugins

Cross-compiling

Auditing

Performance

Maintenance

Creating a Cargo Plugin

Cargo plugins are essentially just executables that follow a certain naming convention (i.e. cargo-something). To create a Cargo Plugin, create a regular Rust project (often a binary crate) and name the executable cargo-<your name here>. Cargo will automatically discover and run these executables.

Useful Crates to Create a Cargo Plugin

| Argument Parsing | Use clap, structopt, argh for parsing command-line arguments passed to the plugin. | | Working with Cargo | Interact with Cargo.toml or other Cargo metadata. serde is often used for parsing TOML or JSON. | | Filesystem Operations | Use std::fs, pathdiff. | | Process Management | Use std::process for running External Commands. | | Networking, HTTP Client (if needed) | Use reqwest, hyper. | | Serialization/Deserialization | Use serde for handling configuration or data. | | Logging | Use tracing, orlog and env_logger. |

There is an unstable Cargo API, but it's not recommended for most plugins due to its instability.

  • Development Tools: Build Utils.
  • Development Tools: Debugging.
  • Development Tools: FFI.
  • Development Tools: Procedural Macro Helpers
  • Development Tools: Profiling.
  • Testing.