Skip to content

Commit

Permalink
buildRustCrate: Replace hyphen with underscore in env variables (#88054)
Browse files Browse the repository at this point in the history
* Add test case for include dir
* buildRustCrate: replace hyphen with underscore in env

This fixes a bug that prevents encoding_c from building.

(cherry picked from commit c21cbf2)
  • Loading branch information
notriddle authored and Ekleog committed May 30, 2020
1 parent acba0f1 commit 5a46292
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkgs/build-support/rust/build-rust-crate/configure-crate.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions pkgs/build-support/rust/build-rust-crate/test/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,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 = {
Expand Down

0 comments on commit 5a46292

Please sign in to comment.