Is there a tool that can check if two crates in the same workspace are using the same dependency, and make sure they're using the same version, features, etc?
(Related question, does it slow down compilation if two dependent crates share the same dependency+version but different features? I'm guessing yes.)
For versions there is cargo tree -d that finds duplicate crates. They can be duplicate only if they differ by semver-major. Otherwise Cargo unifies their versions.
For features there's cargo tree -e features, but you'll need to check by hand.
My ideal solution would be a command that suggests fixes and updates your Cargo.toml files for you.
For example you might have a workspace two crates:
a/Cargo.toml:
[dependencies]
rand = "*"
regex = { version = "1.2.3", features = [ "gzip" ] }
b/Cargo.toml:
[dependencies]
rand = "1"
regex = { version = "1.2.4", features = [ "serde" ] }
Running the tool might suggest:
# cargo workspace-sync
1) rand = "*" (a/Cargo.toml)
2) rand = "1" (b/Cargo.toml)
Enter) rand = "1"
Select which dependency to sync, or [Enter] for the latest version, and a union of all features:
1) regex = { version = "1.2.3", features = [ "gzip" ] } (a/Cargo.toml)
2) regex = { version = "1.2.4", features = [ "serde" ] } (b/Cargo.toml)
Enter) regex = { version = "1.2.4", features = [ "gzip", "serde" ] }
Select which dependency to sync, or [Enter] for the latest version, and a union of all features:
Different sets of dependencies can actually slow things down! Cargo doesn't always unify feature flags across the entire workspace like it unifies versions.
Depending on whether you build from top-level workspace directory, or from single crate's subdirectory, you can get different feature flags enabled!