How does feature unification work in crates universe? #2291
Replies: 2 comments
-
I think the answer is that everything is unified with no distinction, meaning that we have to manage the separate configurations with renames:
And then build the module under test twice, once as normal, and once with out the deps helper macro, and instead precisely listed dependencies, and an alias mapping tokio_test back to tokio. Is this right? (Note that I'm not looking to judge the ergonomics - at this point I just want to know whether my understanding of rules_rust's behaviour is correct). |
Beta Was this translation helpful? Give feedback.
-
This is the code which selects features for each crate: rules_rust/crate_universe/src/metadata.rs Lines 456 to 560 in 90e4505 I'm not sure what |
Beta Was this translation helpful? Give feedback.
-
This was prompted by a discussion about the use of features in workspace.dependencies, with Bazel. I looked for docs, but was not smart enough to find them.
I realise that in Bazel's model each named target needs to be hermetic, not influenced by its downstream dependencies, and thats fine - my goal here is to understand how crates-universe works in order to figure out how to get what we want (or perhaps crate a feature request).
Do we get all the possible features unified?
Or two targets for each crate, one for dev and one for prod, but features unified all deps within that variant?
Or N targets for each create, for each unique combination of unification target would have done given build/test on each binary?
--scenario--
Given two crates in a workspace, A and B, both using a third (lets say crates.io sourced) crate in cargo, A can set the features to be used when building B and C:
When building all packages, cargo unifies the features for C from A, and for C from B.
When building just A, the ones from B are not included. This is surprising to folk, because sudden rebuilds of a bunch of dependencies are common.
Now, when we lift dependency versions to a workspace, there's a third source of features.
What goes crates universe use when selecting the features to build a universe crate with? The workspace features? Unified features from A and B's default-features (and anything any transitive dep happens to enable?) Something else?
And of course then there is an extra source of features - A and B's dev dependencies.
A classic case of this is tokio's feature
test-utils
which enables apis that control time - https://docs.rs/tokio/latest/tokio/time/fn.pause.html - something that we'd really rather not have accidentally slip into a production build.Beta Was this translation helpful? Give feedback.
All reactions