Features not working with virtual workspace


#1

I have a virtual workspace consisting of many crates, and some of the crates have their own features. My top-level Cargo.toml file is:

[workspace]
members = [ "crate1", "crate2", "crate3"]

[features]
featA = [ "crate1/featA", "crate2/featA" ]
featB = [ "crate3/featB" ]

I’m trying to issue a command like cargo build --features "featA" in the top-level workspace directory and have it build both crate1 and crate2 with featA enabled.

However, when I run this, none of the features are ever enabled. This style of feature selection syntax was working beforehand when I was using a different project layout with a single “parent” crate, but the virtual workspace feature is way better for my use case, aside from this feature not working.

What is the proper way to have a top-level workspace Cargo.toml file with features that enable its subcrates’ features?

Thanks!


#2

There is a new opt-in flag in nightly cargo that might get this working:

cargo +nightly build -Z package-features --features featA

It was announced a few days ago on the internals forum: https://internals.rust-lang.org/t/help-us-test-the-breaking-bug-fix-to-cargo-features/7317


#3

Thanks so much! I updated to the latest nightly and it indeed solves my problem, but it seemingly doesn’t let me specify features for multiple crates at once. I posted my problem on that thread in the internals forum, right after your post.