buildRustCrate: set CARGO_FEATURE_* when running the build script

Cargo sets `CARGO_FEATURE_*` for all features when running a build
script:

https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts

Some crates have build scripts (e.g. openblas-src) that rely on the
feature variables being properly set.

Since we now need several representations of features, this change
also updates `createFeatures` to be a list of features, rather than
`rustc` feature arguments. `configureCrate` and `buildCrate` then
build the required representations as-needed.

Fixes #68978
This commit is contained in:
Daniël de Kok
2020-06-13 14:09:06 +02:00
parent 91340aeea8
commit fe50bab788
4 changed files with 58 additions and 11 deletions
@@ -344,6 +344,32 @@ let
buildTests = true;
expectedTestOutputs = [ "test baz_false ... ok" ];
};
buildScriptFeatureEnv = {
crateName = "build-script-feature-env";
features = [ "some-feature" "crate/another_feature" ];
src = symlinkJoin {
name = "build-script-feature-env";
paths = [
(mkFile "src/main.rs" ''
#[cfg(test)]
#[test]
fn feature_not_visible() {
assert!(std::env::var("CARGO_FEATURE_SOME_FEATURE").is_err());
assert!(option_env!("CARGO_FEATURE_SOME_FEATURE").is_none());
}
fn main() {}
'')
(mkFile "build.rs" ''
fn main() {
assert!(std::env::var("CARGO_FEATURE_SOME_FEATURE").is_ok());
assert!(option_env!("CARGO_FEATURE_SOME_FEATURE").is_none());
}
'')
];
};
buildTests = true;
expectedTestOutputs = [ "test feature_not_visible ... ok" ];
};
# Regression test for https://github.com/NixOS/nixpkgs/pull/88054
# Build script output should be rewritten as valid env vars.
buildScriptIncludeDirDeps = let