Skip to content

Supports non-rustc-built-in target.cfg.dependencies#149

Open
csmoe wants to merge 2 commits into
hermeticbuild:mainfrom
csmoe:cfg
Open

Supports non-rustc-built-in target.cfg.dependencies#149
csmoe wants to merge 2 commits into
hermeticbuild:mainfrom
csmoe:cfg

Conversation

@csmoe

@csmoe csmoe commented Jun 15, 2026

Copy link
Copy Markdown

Fix #148

@csmoe csmoe marked this pull request as draft June 15, 2026 07:46
@csmoe csmoe marked this pull request as ready for review June 15, 2026 09:02
@csmoe

csmoe commented Jun 23, 2026

Copy link
Copy Markdown
Author

@dzbarsky may I have a review from you?

@dzbarsky

Copy link
Copy Markdown
Member

To be honest I don't understand this PR. It does look like the existing built-in mappings are incomplete, but that seems like it can be handled via fleshing them out rather than needing to compute them on the fly; aren't they immutable?

Then, if you just want to have an extra --cfg defined for your build it feels like that should be doable more directly, why do we need to invoke rustc for that?

It also seems odd to me to specify a --cfg at resolution time; I would expect conceptually that people specify it at build time (though of course in Bazel making it a starlark flag wouldn't help here). To me that suggests that it may not make sense to use this in a Bazel setting, but perhaps you have a use case I'm not imagining that makes it necessary?

@csmoe

csmoe commented Jun 24, 2026

Copy link
Copy Markdown
Author

it can be handled via fleshing them out rather than needing to compute them on the fly; aren't they immutable

why do we need to invoke rustc for that

Because we must confirm whether rustc actually activates the flag, we can optimize this by caching the --print=cfg result (as Cargo does), though at least one rustc invocation is always required.
https://github.com/rust-lang/cargo/blob/a595d0da21f228b7fdae64d3d5c0e527ea66bb59/src/cargo/core/compiler/build_context/target_info.rs#L221
https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#platform-specific-dependencies

It also seems odd to me to specify a --cfg at resolution time

People might write code like this, using cfg because sdk_dev can't be a feature—doing so would break the additivity of Cargo features. The downside: if --cfg=sdk_dev is missing at resolution time, hack_tls_cert won't be pulled into the dependency graph.

target.'cfg(sdk_dev)'.dependenices]
hack_tls_cert = { version = "1.0" }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support non-rustc-built-in target.cfg(...).dependencies

2 participants