Add per-platform crate_universe feature and dependency exclusions#4164
Open
mgeisler wants to merge 1 commit into
Open
Add per-platform crate_universe feature and dependency exclusions#4164mgeisler wants to merge 1 commit into
crate_universe feature and dependency exclusions#4164mgeisler wants to merge 1 commit into
Conversation
mgeisler
force-pushed
the
crate-universe-per-platform-feature-exclusions
branch
from
July 22, 2026 15:59
5afc99f to
8d97d08
Compare
crate_universe feature and dependency exclusions
Contributor
Author
|
It seems the number of integration tests is fixed at max 128? This PR adds a new one – I'm curious to hear how I should approach this. I'll let it sit for a while until someone can tell me more about the conventions here. |
mgeisler
force-pushed
the
crate-universe-per-platform-feature-exclusions
branch
from
July 23, 2026 15:17
8d97d08 to
f98211f
Compare
`crate_universe` resolves crate features once over the whole Cargo
workspace, so Cargo's workspace-wide feature unification activates a
feature requested by any member on the single shared target generated
for that crate, for every supported platform triple.
This forces features onto platforms that cannot build them: an
unconditional `tokio = { features = ["net"] }` anywhere in the
workspace pulls in the `net` feature for Tokio (and thus the
transitive `mio` and `socket2` dependencies). This happens even on
`wasm32-unknown-unknown`, where they do not compile.
This MR adds new `disabled_features` and `excluded_deps` attributes to
`crate.annotation` and `crate.annotation_select`. They allow a user to
trim the resolved feature and dependency sets of a crate. The removal
is scoped to a triple and it demotes a formerly unconditional value
onto the other supported triples. This way, only the named platform
loses it.
Because the trimming operates on the shared target's own resolved
attributes, it fixes the crate for every consumer at once, regardless
of which workspace member (or dev-dependency) unioned the feature in.
New unit tests have been added, as well as an integration test that
demonstrates the issue for Tokio compiled both with and without the
`net` feature.
Fixes bazelbuild#4163.
mgeisler
force-pushed
the
crate-universe-per-platform-feature-exclusions
branch
from
July 23, 2026 15:18
f98211f to
f7183b1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Written by Claude, I can confirm that this works my company monorepo where we compile a Rust core for both Wasm, Android, and iOS.
I am happy to discuss other approaches: this was one suggested by the LLM. I hope the PR here serves to demonstrate the problem well and hopefully we can find a good and flexible solution. One thing I noticed while applying the fix to our codebase is that it required a lot of trial and error before Claude found the right crates and features to disable. A solution that simplifies this would be great.
crate_universeresolves crate features once over the whole Cargo workspace, so Cargo's workspace-wide feature unification activates a feature requested by any member on the single shared target generated for that crate, for every supported platform triple.This forces features onto platforms that cannot build them: an unconditional
tokio = { features = ["net"] }anywhere in the workspace pulls in thenetfeature for Tokio (and thus the transitivemioandsocket2dependencies). This happens even onwasm32-unknown-unknown, where they do not compile.This MR adds new
disabled_featuresandexcluded_depsattributes tocrate.annotationandcrate.annotation_select. They allow a user to trim the resolved feature and dependency sets of a crate. The removal is scoped to a triple and it demotes a formerly unconditional value onto the other supported triples. This way, only the named platform loses it.Because the trimming operates on the shared target's own resolved attributes, it fixes the crate for every consumer at once, regardless of which workspace member (or dev-dependency) unioned the feature in.
New unit tests have been added, as well as an integration test that demonstrates the issue for Tokio compiled both with and without the
netfeature.Fixes #4163.