-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cfg
aliases
#7260
Comments
A real-world example on how unfortunate for us to not have this feature: gfx-rs/wgpu#333 |
I'd be a big fan of this as I'm dealing with the following in the #[cfg(all(
target_feature = "pclmulqdq",
target_feature = "sse2",
target_feature = "sse4.1",
any(target_arch = "x86", target_arch = "x86_64")
))] I see there was a pre-RFC for it: https://internals.rust-lang.org/t/pre-rfc-cfg-attribute-alias/7404 @Manishearth suggested this syntax, which looks great to me: #![cfg_alias(foo, any(bar, baz))]
#[cfg(foo)] pub mod bar; |
I wonder if there is a way here that would support using these aliases in |
It's worth pointing out that you can already do this today with build scripts. You'll need to read the env vars yourself, but you can then print out |
@alexcrichton neat! Thanks for the tip |
@alexcrichton wouldn't it only work for just one crate? For instance how can we create an alias for |
Describe the problem you are trying to solve
As seen in gfx-rs/wgpu#290 (comment),
cfg
parameters can be quite long:If such a dependency is not optional, using it has to be guarded by a similar
cfg
statement in the code:Describe the solution you'd like
It is very inconvenient and error prone. It would be great if instead we could define a set of configurations to be used across Cargo config as well as the code. Something like this:
And then in Rust code:
Notes
Interestingly, configuration aliases are already there, just hard-coded to just "windows" and "unix": https://doc.rust-lang.org/reference/conditional-compilation.html#unix-and-windows
This issue can be seen as making this more generic.
The text was updated successfully, but these errors were encountered: