-
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
feature to env var mapping is not unique #3702
Comments
Out of curiosity, was this causing a problem in practice? We could perhaps set both in the case of a |
It's definitely an edge case and I highly doubt it's come up in practice, I
was writing a [build script helper crate](https://crates.io/crates/foreman)
that looks at those env vars and I realized that you can't quite map the
var back to a feature name (since you don't know whether to replace the
underscores). One thing we could do is repeat the feature name as the value
of the env var, so instead of setting CARGO_FEATURE_FOO_BAR=1 it would be
CARGO_FEATURE_FOO_BAR=foo-bar.
|
Yeah that's true and we could handle the case you mentioned in theory by listing everything to the right as well. Should be backwards compatible as well! |
Technically not backcompat :( I found one crate[1] relying on the value
being "1" though they could probably be convinced to change it since it's
not documented to be any specific value. Another option is defining _yet
another_ env var e.g. `CARGO_FEATURES="foo-bar foo_bar"`. Or ignoring this
edge case :)
[1]:
https://github.com/uutils/coreutils/blob/4a16514d2cab76733e2d5623ebcaeff7730eddd3/build.rs#L11-L16
…On Wed, Feb 15, 2017 at 1:26 PM, Alex Crichton ***@***.***> wrote:
Yeah that's true and we could handle the case you mentioned in theory by
listing everything to the right as well. Should be backwards compatible as
well!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3702 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC3n1H8LOyMsrg0aqFcEhr-9uSYSU66ks5rc0NrgaJpZM4MBCFU>
.
|
Do we care to support the use case foreman has? Being able to map back from env var to feature name? If yes, we should decide on which solution to use. |
The case where I would find this helpful is I have tests that compile/run examples and need to pass along feature flags. Maintaining that manually is easy to mess up. |
I have a build script that runs cargo_metadata::MetadataCommand, and would like to forward the same features that the crate enabled. Because of this lossy conversion, the best I can do is gather a list of all the env_vars that start with Given the backwards-compat issue listed here, I wonder if maybe this could be solved with a new env var that lists all the features? Something like |
This may look redundant with `CARGO_FEATURE_<CASE_CONVERTED_NAME>=1` except that doesn't provide a lossless way of getting the names, e.g. for forwarding for child builds like tests that need to build examples. This also makes things more consistent as users conditionalize on features through `cfg` and this even fits with what the `CARGO_CFG_` docs say: > For each configuration option of the package being built, this > environment variable will contain the value of the configuration, where > <cfg> is the name of the configuration uppercased and having - > translated to _. Boolean configurations are present if they are set, and > not present otherwise. Configurations with multiple values are joined to > a single variable with the values delimited by ,. This includes values > built-in to the compiler (which can be seen with rustc --print=cfg) and > values set by build scripts and extra flags passed to rustc (such as > those defined in RUSTFLAGS). Some examples of what these variables are: Fixes rust-lang#3702
This may look redundant with `CARGO_FEATURE_<CASE_CONVERTED_NAME>=1` except that doesn't provide a lossless way of getting the names, e.g. for forwarding for child builds like tests that need to build examples. This also makes things more consistent as users conditionalize on features through `cfg` and this even fits with what the `CARGO_CFG_` docs say: > For each configuration option of the package being built, this > environment variable will contain the value of the configuration, where > <cfg> is the name of the configuration uppercased and having - > translated to _. Boolean configurations are present if they are set, and > not present otherwise. Configurations with multiple values are joined to > a single variable with the values delimited by ,. This includes values > built-in to the compiler (which can be seen with rustc --print=cfg) and > values set by build scripts and extra flags passed to rustc (such as > those defined in RUSTFLAGS). Some examples of what these variables are: Fixes rust-lang#3702
This may look redundant with `CARGO_FEATURE_<CASE_CONVERTED_NAME>=1` except that doesn't provide a lossless way of getting the names, e.g. for forwarding for child builds like tests that need to build examples. This also makes things more consistent as users conditionalize on features through `cfg` and this even fits with what the `CARGO_CFG_` docs say: > For each configuration option of the package being built, this > environment variable will contain the value of the configuration, where > <cfg> is the name of the configuration uppercased and having - > translated to _. Boolean configurations are present if they are set, and > not present otherwise. Configurations with multiple values are joined to > a single variable with the values delimited by ,. This includes values > built-in to the compiler (which can be seen with rustc --print=cfg) and > values set by build scripts and extra flags passed to rustc (such as > those defined in RUSTFLAGS). Some examples of what these variables are: Fixes rust-lang#3702
This may look redundant with `CARGO_FEATURE_<CASE_CONVERTED_NAME>=1` except that doesn't provide a lossless way of getting the names, e.g. for forwarding for child builds like tests that need to build examples. This also makes things more consistent as users conditionalize on features through `cfg` and this even fits with what the `CARGO_CFG_` docs say: > For each configuration option of the package being built, this > environment variable will contain the value of the configuration, where > <cfg> is the name of the configuration uppercased and having - > translated to _. Boolean configurations are present if they are set, and > not present otherwise. Configurations with multiple values are joined to > a single variable with the values delimited by ,. This includes values > built-in to the compiler (which can be seen with rustc --print=cfg) and > values set by build scripts and extra flags passed to rustc (such as > those defined in RUSTFLAGS). Some examples of what these variables are: Fixes rust-lang#3702
This may look redundant with `CARGO_FEATURE_<CASE_CONVERTED_NAME>=1` except that doesn't provide a lossless way of getting the names, e.g. for forwarding for child builds like tests that need to build examples. This also makes things more consistent as users conditionalize on features through `cfg` and this even fits with what the `CARGO_CFG_` docs say: > For each configuration option of the package being built, this > environment variable will contain the value of the configuration, where > <cfg> is the name of the configuration uppercased and having - > translated to _. Boolean configurations are present if they are set, and > not present otherwise. Configurations with multiple values are joined to > a single variable with the values delimited by ,. This includes values > built-in to the compiler (which can be seen with rustc --print=cfg) and > values set by build scripts and extra flags passed to rustc (such as > those defined in RUSTFLAGS). Some examples of what these variables are: Fixes rust-lang#3702
This may look redundant with `CARGO_FEATURE_<CASE_CONVERTED_NAME>=1` except that doesn't provide a lossless way of getting the names, e.g. for forwarding for child builds like tests that need to build examples. This also makes things more consistent as users conditionalize on features through `cfg` and this even fits with what the `CARGO_CFG_` docs say: > For each configuration option of the package being built, this > environment variable will contain the value of the configuration, where > <cfg> is the name of the configuration uppercased and having - > translated to _. Boolean configurations are present if they are set, and > not present otherwise. Configurations with multiple values are joined to > a single variable with the values delimited by ,. This includes values > built-in to the compiler (which can be seen with rustc --print=cfg) and > values set by build scripts and extra flags passed to rustc (such as > those defined in RUSTFLAGS). Some examples of what these variables are: Fixes rust-lang#3702
This may look redundant with `CARGO_FEATURE_<CASE_CONVERTED_NAME>=1` except that doesn't provide a lossless way of getting the names, e.g. for forwarding for child builds like tests that need to build examples. This also makes things more consistent as users conditionalize on features through `cfg` and this even fits with what the `CARGO_CFG_` docs say: > For each configuration option of the package being built, this > environment variable will contain the value of the configuration, where > <cfg> is the name of the configuration uppercased and having - > translated to _. Boolean configurations are present if they are set, and > not present otherwise. Configurations with multiple values are joined to > a single variable with the values delimited by ,. This includes values > built-in to the compiler (which can be seen with rustc --print=cfg) and > values set by build scripts and extra flags passed to rustc (such as > those defined in RUSTFLAGS). Some examples of what these variables are: Fixes rust-lang#3702
### What does this PR try to resolve? This may look redundant with `CARGO_FEATURE_<CASE_CONVERTED_NAME>=1` except that doesn't provide a lossless way of getting the names, e.g. for forwarding to child builds like tests that need to build examples. which clap does to [test examples](https://github.com/clap-rs/clap/blob/master/tests/examples.rs). Maintaining that manually is easy to mess up. This also makes things more consistent as users conditionalize on features through `cfg` and this even fits with what the `CARGO_CFG_` docs say: > For each configuration option of the package being built, this > environment variable will contain the value of the configuration, where > <cfg> is the name of the configuration uppercased and having - > translated to _. Boolean configurations are present if they are set, and > not present otherwise. Configurations with multiple values are joined to > a single variable with the values delimited by , (comma). This includes values > built-in to the compiler (which can be seen with rustc --print=cfg) and > values set by build scripts and extra flags passed to rustc (such as > those defined in RUSTFLAGS). Some examples of what these variables are: Fixes #3702 ### How should we test and review this PR? ### Additional information
Build scripts receive information about activated features as environment variables
CARGO_FEATURE_$name
, where$name
is the feature name uppercased and with dashes converted to underscores.However, feature names are allowed to contain underscores, so this transformation can create collisions. Example:
cargo build --features "foo_bar foo-bar"
The text was updated successfully, but these errors were encountered: