You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+45-20Lines changed: 45 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
# Check Dependency Inheritance in Cargo Workspaces
2
2
3
-
A Cargo subcommand that enforces dependency inheritance hygiene in Cargo workspaces. It detects crates that specify dependency versions directly instead of using [`workspace = true`](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#inheriting-a-dependency-from-a-workspace), flags version mismatches, and suggests candidates for workspace promotion.
3
+
A Cargo subcommand that detects workspace dependency inheritance issues in Cargo workspaces. It finds crates that specify dependency versions directly instead of using [`workspace = true`](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#inheriting-a-dependency-from-a-workspace), flags version mismatches, and suggests candidates for workspace promotion.
4
4
5
5
## Why?
6
6
7
-
Cargo workspaces support [dependency inheritance](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#inheriting-a-dependency-from-a-workspace),you declare shared dependency versions once in the root `Cargo.toml` under `[workspace.dependencies]`, and member crates reference them with `{ workspace = true }`. This prevents version drift and duplicated dependency specs across workspace members.
7
+
Cargo workspaces support [dependency inheritance](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#inheriting-a-dependency-from-a-workspace),you declare shared dependency versions once in the root `Cargo.toml` under `[workspace.dependencies]`, and member crates reference them with `{ workspace = true }`. This prevents version drift and duplicated dependency specs across workspace members.
8
8
9
9
However, **Cargo has no built-in lint** for detecting when a crate specifies a version directly instead of inheriting from the workspace. [Clippy issue #10306](https://github.com/rust-lang/rust-clippy/issues/10306) tracks this as a feature request but remains unimplemented.
10
10
@@ -30,7 +30,7 @@ error: `rand = "0.7"` in crates/bar/Cargo.toml has a different version than work
30
30
31
31
### 3. Candidate for workspace promotion (warning)
32
32
33
-
A dependency appears in multiple crates but isn't declared in `[workspace.dependencies]`.
33
+
A dependency appears in multiple crates but isn't declared in `[workspace.dependencies]`. This check helps you identify dependencies that should be centralized.
34
34
35
35
```
36
36
warning: `serde_yaml` appears in 3 crates but is not in [workspace.dependencies]
@@ -40,6 +40,8 @@ warning: `serde_yaml` appears in 3 crates but is not in [workspace.dependencies]
40
40
hint: consider adding `serde_yaml = "0.9"` to [workspace.dependencies]
41
41
```
42
42
43
+
By default, this is reported as a **warning** and does not cause the tool to exit with a non-zero code. Use `--promotion-failure` to treat promotion candidates as errors.
Running without any flags checks all workspace members against `[workspace.dependencies]` in the root `Cargo.toml`. It reports errors for dependencies not using inheritance ([checks 1 and 2](#what-it-checks)) and warnings for promotion candidates ([check 3](#3-candidate-for-workspace-promotion-warning)). The tool exits with code 1 if any **errors** are found, and 0 if there are only warnings or no issues.
52
56
53
57
```bash
54
-
# Check workspace dependency inheritance
55
58
cargo workspace-inheritance-check
59
+
```
60
+
61
+
### Options
56
62
57
-
# Specify a different workspace root
63
+
| Flag | Description | Default |
64
+
|------|-------------|---------|
65
+
|`--path <PATH>`| Path to the workspace root |`.`|
66
+
|`--promotion-threshold <N>`| Minimum number of crates a dependency must appear in before it is flagged as a promotion candidate. For example, `--promotion-threshold 3` means a dependency must appear in at least 3 crates to trigger a warning. |`2`|
67
+
|`--promotion-failure`| Promote promotion candidate warnings to errors, causing the tool to exit with code 1 when candidates are found. Useful in CI when you want to enforce that all shared dependencies are declared in `[workspace.dependencies]`. |`false`|
68
+
|`--format <FORMAT>`| Output format: `human` or `json`|`human`|
69
+
|`--no-fail`| Always exit with code 0, regardless of errors found. Useful when you want to see the report without failing a CI pipeline. |`false`|
0 commit comments