1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-09-11 15:08:33 +01:00

buildRustCrate: Replace hyphen with underscore in env variables (#88054)

* Add test case for include dir
* buildRustCrate: replace hyphen with underscore in env

This fixes a bug that prevents encoding_c from building.
This commit is contained in:
Michael Howell 2020-05-26 11:52:18 -07:00 committed by GitHub
parent 0300b47dd5
commit c21cbf22d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 2 deletions

View file

@ -179,9 +179,9 @@ in ''
export $env
done
CRATENAME=$(echo ${crateName} | sed -e "s/\(.*\)-sys$/\U\1/")
CRATENAME=$(echo ${crateName} | sed -e "s/\(.*\)-sys$/\U\1/" -e "s/-/_/g")
grep -P "^cargo:(?!(rustc-|warning=|rerun-if-changed=|rerun-if-env-changed))" target/build/${crateName}.opt \
| sed -e "s/cargo:\([^=]*\)=\(.*\)/export DEP_$(echo $CRATENAME)_\U\1\E=\2/" > target/env
| awk -F= "/^cargo:/ { sub(/^cargo:/, \"\", \$1); gsub(/-/, \"_\", \$1); print \"export \" toupper(\"DEP_$(echo $CRATENAME)_\" \$1) \"=\" \$2 }" > target/env
set -e
fi
runHook postConfigure

View file

@ -344,6 +344,40 @@ let
buildTests = true;
expectedTestOutputs = [ "test baz_false ... ok" ];
};
# Regression test for https://github.com/NixOS/nixpkgs/pull/88054
# Build script output should be rewritten as valid env vars.
buildScriptIncludeDirDeps = let
depCrate = mkCrate {
crateName = "bar";
src = symlinkJoin {
name = "build-script-and-include-dir-bar";
paths = [
(mkFile "src/lib.rs" ''
fn main() { }
'')
(mkFile "build.rs" ''
use std::path::PathBuf;
fn main() { println!("cargo:include-dir={}/src", std::env::current_dir().unwrap_or(PathBuf::from(".")).to_str().unwrap()); }
'')
];
};
};
in {
crateName = "foo";
src = symlinkJoin {
name = "build-script-and-include-dir-foo";
paths = [
(mkFile "src/main.rs" ''
fn main() { }
'')
(mkFile "build.rs" ''
fn main() { assert!(std::env::var_os("DEP_BAR_INCLUDE_DIR").is_some()); }
'')
];
};
buildDependencies = [ depCrate ];
dependencies = [ depCrate ];
};
# Regression test for https://github.com/NixOS/nixpkgs/issues/74071
# Whenevever a build.rs file is generating files those should not be overlayed onto the actual source dir
buildRsOutDirOverlay = {