-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Problem
Apologies in advance if this is categorized incorrectly, I can see how this could be either a bug or feature request.
Recently introduced to Cargo is the ability to specify dependencies at the workspace level. Crates within that workspace can specify their dependencies as { workspace = true }, which results in that crate inheriting the dependency from their parent workspace.
With respect to features the inheritance works in a purely additive way, which I believe works well in general, but not in the case of default features.
For example say you have a workspace with two crates, foo and bar, both of these crates depend on tracing. You want to make sure foo and bar depend on the same version of tracing, so you define it in your workspace and have crates inherit from it. In the crate bar you want to disable default-features for tracing, but you cannot since when you inherit from a workspace it's in a purely additive way. The only way to disable default-features in bar is to disable it at the workspace level, this has the adverse effect of also disabling default-features for foo. In the crate foo you could specify default-features = true, but this feels like an anti-pattern.
Scaling this example up a bit and you can better see how this is an issue. Say you have a workspace of 50 crates, 10 of which depend on tracing. In 1 of the 10 crates you want to disable default-features, to do that it requires you to specify default-features = true for the other 9, and any crates in the future that depend on tracing.
Steps
- Create a new Rust project, make it a workspace, add a
workspace.dependencyoftracing = 0.1.37(or any other crate). - Add a new crate
foo, add a dependency oftracing = { workspace = true }. - Add a new crate
bar, add a dependency oftracing = { workspace = true, default-features = false }. - Observe a compiler warning when building
bar, indicating that thedefault-featuresflag is ignored.
Possible Solution(s)
Allow inherited dependencies within a workspace to disable default features.
Notes
No response
Version
$ cargo version --verbose
cargo 1.69.0 (6e9a83356 2023-04-12)
release: 1.69.0
commit-hash: 6e9a83356b70586d4b77613a6b33f9ea067b9cdf
commit-date: 2023-04-12
host: aarch64-apple-darwin
libgit2: 1.5.0 (sys:0.16.0 vendored)
libcurl: 7.86.0 (sys:0.4.59+curl-7.86.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
os: Mac OS 13.2.0 [64-bit]
Metadata
Metadata
Assignees
Labels
Type
Projects
Status