Skip to content

Commit

Permalink
rust: allow building in debug or release modes
Browse files Browse the repository at this point in the history
  • Loading branch information
illegalprime authored and Ericson2314 committed Mar 29, 2019
1 parent 60761e6 commit bdd3c3f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkgs/build-support/rust/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
, cargoUpdateHook ? ""
, cargoDepsHook ? ""
, cargoBuildFlags ? []
, buildType ? "release"

, cargoVendorDir ? null
, ... } @ args:

assert cargoVendorDir == null -> cargoSha256 != "unset";
assert buildType == "release" || buildType == "debug";

let
cargoDeps = if cargoVendorDir == null
Expand All @@ -42,7 +44,7 @@ let
cxxForBuild="${buildPackages.stdenv.cc}/bin/${buildPackages.stdenv.cc.targetPrefix}c++";
ccForHost="${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
cxxForHost="${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++";
releaseDir = "target/${stdenv.hostPlatform.config}/release";
releaseDir = "target/${stdenv.hostPlatform.config}/${buildType}";

in stdenv.mkDerivation (args // {
inherit cargoDeps;
Expand Down Expand Up @@ -98,15 +100,15 @@ in stdenv.mkDerivation (args // {
"CC_${stdenv.hostPlatform.config}"="${ccForHost}" \
"CXX_${stdenv.hostPlatform.config}"="${cxxForHost}" \
cargo build \
--release \
--${buildType} \
--target ${stdenv.hostPlatform.config} \
--frozen ${concatStringsSep " " cargoBuildFlags}
)
# rename the output dir to a architecture independent one
mapfile -t targets < <(find "$NIX_BUILD_TOP" -type d | grep '${releaseDir}$')
for target in "''${targets[@]}"; do
rm -rf "$target/../../release"
rm -rf "$target/../../${buildType}"
ln -srf "$target" "$target/../../"
done
Expand Down

0 comments on commit bdd3c3f

Please sign in to comment.