-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(build-script): Pass CARGO_CFG_FEATURE (#14902)
### 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
- Loading branch information
Showing
6 changed files
with
32 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,7 +156,7 @@ fn custom_build_env_vars() { | |
authors = ["[email protected]"] | ||
[features] | ||
bar_feat = ["bar/foo"] | ||
bar_feat = ["bar/foo", "bar/other-feature"] | ||
[dependencies.bar] | ||
path = "bar" | ||
|
@@ -176,6 +176,7 @@ fn custom_build_env_vars() { | |
[features] | ||
foo = [] | ||
other-feature = [] | ||
"#, | ||
) | ||
.file("bar/src/lib.rs", "pub fn hello() {}"); | ||
|
@@ -213,6 +214,8 @@ fn custom_build_env_vars() { | |
let _host = env::var("HOST").unwrap(); | ||
let _feat = env::var("CARGO_FEATURE_FOO").unwrap(); | ||
let feat = env::var("CARGO_CFG_FEATURE").unwrap(); | ||
assert_eq!(feat, "foo,other-feature"); | ||
let cargo = env::var("CARGO").unwrap(); | ||
if env::var_os("CHECK_CARGO_IS_RUSTC").is_some() {{ | ||
|