-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Poor interaction between workspace dependencies and default-features #12162
Copy link
Copy link
Open
Labels
A-edition-nextArea: may require a breaking change over an editionArea: may require a breaking change over an editionA-featuresArea: features — conditional compilationArea: features — conditional compilationA-manifestArea: Cargo.toml issuesArea: Cargo.toml issuesA-workspace-inheritanceArea: workspace inheritance RFC 2906Area: workspace inheritance RFC 2906C-bugCategory: bugCategory: bugS-needs-infoStatus: Needs more info, such as a reproduction or more background for a feature request.Status: Needs more info, such as a reproduction or more background for a feature request.
Metadata
Metadata
Assignees
Labels
A-edition-nextArea: may require a breaking change over an editionArea: may require a breaking change over an editionA-featuresArea: features — conditional compilationArea: features — conditional compilationA-manifestArea: Cargo.toml issuesArea: Cargo.toml issuesA-workspace-inheritanceArea: workspace inheritance RFC 2906Area: workspace inheritance RFC 2906C-bugCategory: bugCategory: bugS-needs-infoStatus: Needs more info, such as a reproduction or more background for a feature request.Status: Needs more info, such as a reproduction or more background for a feature request.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Projects
Status
No status
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,
fooandbar, both of these crates depend ontracing. You want to make surefooandbardepend on the same version oftracing, so you define it in your workspace and have crates inherit from it. In the cratebaryou want to disabledefault-featuresfortracing, but you cannot since when you inherit from a workspace it's in a purely additive way. The only way to disabledefault-featuresinbaris to disable it at the workspace level, this has the adverse effect of also disablingdefault-featuresforfoo. In the cratefooyou could specifydefault-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 disabledefault-features, to do that it requires you to specifydefault-features = truefor the other 9, and any crates in the future that depend ontracing.Steps
workspace.dependencyoftracing = 0.1.37(or any other crate).foo, add a dependency oftracing = { workspace = true }.bar, add a dependency oftracing = { workspace = true, default-features = false }.bar, indicating that thedefault-featuresflag is ignored.Possible Solution(s)
Allow inherited dependencies within a workspace to disable default features.
Notes
No response
Version