Problem
Note: Split off of (and blocks) this rust-analyzer issue: rust-lang/rust-analyzer#19846
cargo metadata has a --filter-platform flag to return the effective dependency tree for a given platform, evaluating conditional dependencies like [target.'cfg(windows)'.dependencies] and culling dependencies that evaluate to false.
This target dependency syntax supports any cfg condition, though:
[target.'cfg(my_custom_cfg = "foobar")'.dependencies]
bar = { workspace = true }
However, there doesn't seem to be a way to provide additional cfgs for cargo metadata's dependency evaluation outside of setting one of the RUSTFLAGS environment variables.
This means that these conditional dependencies will be filtered out (for example by rust-analyzer's call of cargo metadata, see the linked issue above) as soon as --filter-platform is used.
Proposed Solution
From my limited perspective it seems that cargo metadata is missing a parameter like --filter-cfg that would allow specifying these additional cfgs, bringing them to parity with platform-defined cfgs.
The proposed solution would be to add --filter-cfg with effectively the same syntax as rustc's --cfg.
Notes
If this seems reasonable (or another way that might be) I'd like to give implementing it a try. Any guidance here would be appreciated!
Problem
Note: Split off of (and blocks) this rust-analyzer issue: rust-lang/rust-analyzer#19846
cargo metadatahas a--filter-platformflag to return the effective dependency tree for a given platform, evaluating conditional dependencies like[target.'cfg(windows)'.dependencies]and culling dependencies that evaluate tofalse.This target dependency syntax supports any
cfgcondition, though:However, there doesn't seem to be a way to provide additional
cfgs forcargo metadata's dependency evaluation outside of setting one of theRUSTFLAGSenvironment variables.This means that these conditional dependencies will be filtered out (for example by rust-analyzer's call of
cargo metadata, see the linked issue above) as soon as--filter-platformis used.Proposed Solution
From my limited perspective it seems that
cargo metadatais missing a parameter like--filter-cfgthat would allow specifying these additionalcfgs, bringing them to parity with platform-definedcfgs.The proposed solution would be to add
--filter-cfgwith effectively the same syntax asrustc's--cfg.Notes
If this seems reasonable (or another way that might be) I'd like to give implementing it a try. Any guidance here would be appreciated!