Description
Problem
Suppose I have a workspace, containing crate A
,B
and C
. A
has the feature F
, but it is not a default-feature. Both B
and C
depend on A
, however B
does not use F
, while C
does.
The file ./A/src/lib.rs
looks like this:
pub fn A(){
if cfg!(feature = "F"){
println!("Using library A with Feature F")
}else {
println!("Using library A")
}
}
, while B and C just call A::A()
in their main function.
Behaviour:
cargo run --bin B
Using library A with Feature F
cargo build
"./target/debug/B.exe"
Using library A with Feature F
cargo run -p B
Using library A
This behaviour just seems inconsistent. I don't understand how B is ever built with F, as in my real use case this imposes a performance penalty for B, so I will have to fall back to using cargo run -p B
. The behaviour I expect is:
cargo run --bin B
Using library A
cargo build
"./target/debug/B.exe"
Using library A
cargo run -p B
Using library A
Steps
- Make a workspace containing three crates A , B, C.
A/src/lib.rs
as above
B/src/main.rs
:
fn main() {
A::A();
}
A/Cargo.toml
:
[features]
default = []
F = []
B/Cargo.toml
[dependencies]
A = {path = "../A"}
C/Cargo.toml
[dependencies.A]
path = "../A"
default-features = false
features = ["F"]
- Run cargo commands as above
Possible Solution(s)
Notes
Output of cargo version
:
cargo 1.43.0 (3532cf738 2020-03-17)
Using latest stable Rust, rustc --version
:
rustc 1.43.0 (4fb7144ed 2020-04-20)