cargo-dependency-inheritor
cargo-dependency-inheritor copied to clipboard
Utility to inherit dependencies from workspace file if it occurs 'n' or more times throughout the project.
Cargo Workspace Dependency Inheritor
Utility that inherits dependencies from the main workspace if they occur n or more times in the workspace.
Workspace Inheritance was stabilized in version 1.64.
See [workspace.package], [workspace.dependencies], and inheriting-a-dependency-from-a-workspace for more information.
How to Use
To inherit a dependency that occurs five or more times in the workspace, use the following command:
cargo install cargo-dependency-inheritor
cargo dependency-inheritor --workspace-path "path/to/workspace/Cargo.toml" -n 5
This command edits your toml files, make sure to have a back up
Process
Dependencies can be inherited from a workspace by specifying the dependency in the workspace's [workspace.dependencies] table. After that, add it to the [dependencies] table with workspace = true.
This crate automates the process.
- Read packages defined in
[workspace]section of the workspace-file. - Note which dependencies occur
nor more times. - Update all dependencies that occurred
nor more times:- Turn
dependency = "0.1.3"into inline tables. - Add
workspace = truekey-value to the dependency inline table. - Remove
versionfrom inline table if exists (this will be specified in the workspace file).
- Turn
- Add
[workspace.dependencies]table to root workspace file with all the dependencies that occurredntimes and their version.
Result:
# in a project
[dependencies]
tokio = { workspace = true }
# in the workspace
[workspace.dependencies]
tokio = "1.0"