Unrelated workspace members affect feature selection even with --bin, unless excluded #14529
Labels
A-features
Area: features — conditional compilation
C-bug
Category: bug
S-triage
Status: This issue is waiting on initial triage.
Problem
Understandably,
cargo {test/check/build} --bin some-binary --bin ...
only compiles needed dependent crates, ignoring other member crates of a workspace, which aren't part of the dependency graph.However, those members crates affect feature selection. So, if unused crate A depends on crate C with feature=F, it always activates the feature even when building some bin from crate B, which depends on crate C without feature=F.
The workaround is to explicitly exclude unneeded crates with
--exclude A
.While feature selection/unification should be additive and harmless most of time, it's desirable not to select unused features, due to various concerns including code sizes, longer compile times, etc.
Steps
cargo build --bin bin-high --workspace --exclude bin-high-bad
and see the command succeedscargo build --bin bin-high
and see the failure like this due to unexpected feature selection and unification:Possible Solution(s)
It seems that all feature selection/unification happens before restricting what to build according to
--bin
.Ideally, unneeded features are disabled after the specified target selections. In other words, Step 3 above should just work like Step 2.
Notes
This is a bit similar to #4463
Version
The text was updated successfully, but these errors were encountered: