2 releases
Uses new Rust 2024
0.1.1 | Apr 19, 2025 |
---|---|
0.1.0 | Apr 14, 2025 |
#74 in Cargo plugins
258 downloads per month
23KB
411 lines
cargo-easy-dep
A cargo subcommand that simplifies dependency management in Rust workspaces by automatically unifying common dependencies at the workspace level.
Overview
In large Rust workspaces, managing dependencies across multiple crates can become cumbersome. cargo-easy-dep
analyzes your workspace and:
- Identifies dependencies used by multiple workspace members
- Adds these common dependencies to the workspace's
Cargo.toml
- Updates each member's
Cargo.toml
to use the workspace dependency
This approach reduces duplication, simplifies updates, and ensures version consistency across your workspace.
Installation
cargo install cargo-easy-dep
Usage
From your workspace root directory, run:
cargo easy-dep
Options
Options:
-m, --min-occurrences <MIN_OCCURRENCES>
Minimum number of occurrences to consider a dependency common [env: CARGO_EASY_DEP_MIN_OCCURRENCES=] [default: 2]
-w, --workspace-root <WORKSPACE_ROOT>
Path to workspace root (defaults to current directory) [env: CARGO_EASY_DEP_WORKSPACE_ROOT=]
-q, --quiet
Suppress all output [env: CARGO_EASY_DEP_QUIET=]
-h, --help
Print help
-V, --version
Print version
Examples
Basic Usage
# Run from your workspace root
cargo easy-dep
Customize Minimum Occurrences
Consider all dependencies used by workspace members:
cargo easy-dep --min-occurrences 1
Specify Workspace Root
cargo easy-dep --workspace-root /path/to/my/workspace
Silent Mode
cargo easy-dep --quiet
How It Works
- Analyzes your workspace structure using
cargo_metadata
- Counts the occurrences of each dependency across workspace members
- Identifies dependencies used by multiple crates (configurable via
--min-occurrences
) - Updates the root
Cargo.toml
to add these dependencies to the[workspace.dependencies]
section - Updates each member's
Cargo.toml
to useworkspace = true
for these dependencies
Notes
- The workspace default-features is problematic, so
cargo-easy-dep
will disable default-features for all dependencies in the workspace and enable them based on each member's preferences. This disabling has been done without diffing and it gives maintainers better visibility by explicitly indicating the features without falling into the mentioned issue. - Only the first dependency version seen will be used in the workspace dependencies; tune the version based on your requirements in the workspace
Cargo.toml
. - There is no difference between '^1.0' and '1.0' in versioning and as
cargo-easy-dep
usessemver::VersionReq
as versioning strategy like whatcargo
does, you will see '^1.0' in your root workspaceCargo.toml
for dependencies versions. (1.0
version used as an example)
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Dependencies
~3–10MB
~109K SLoC