rust: allow building in debug or release modes

This commit is contained in:
Michael Eden 2019-02-26 00:52:01 -05:00 committed by John Ericson
parent 60761e65ba
commit bdd3c3fdcb

View File

@ -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
@ -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;
@ -98,7 +100,7 @@ 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}
)
@ -106,7 +108,7 @@ in stdenv.mkDerivation (args // {
# 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