From 3291bda7b6aca51b1e2644e1adc7824c89530dc0 Mon Sep 17 00:00:00 2001 From: marius david Date: Tue, 23 Aug 2022 13:09:33 +0200 Subject: [PATCH] buildRustCrate: Do not compile binaries if all the requiredFeatures aren't enabled. --- .../rust/build-rust-crate/build-crate.nix | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/rust/build-rust-crate/build-crate.nix b/pkgs/build-support/rust/build-rust-crate/build-crate.nix index b24398665a10..37bf3ec26f77 100644 --- a/pkgs/build-support/rust/build-rust-crate/build-crate.nix +++ b/pkgs/build-support/rust/build-rust-crate/build-crate.nix @@ -69,7 +69,15 @@ - ${lib.optionalString (lib.length crateBin > 0) (lib.concatMapStringsSep "\n" (bin: '' + ${lib.optionalString (lib.length crateBin > 0) (lib.concatMapStringsSep "\n" (bin: + let + haveRequiredFeature = if bin ? requiredFeatures then + # Check that all element in requiredFeatures are also present in crateFeatures + lib.intersectLists bin.requiredFeatures crateFeatures == bin.requiredFeatures + else + true; + in + if haveRequiredFeature then '' mkdir -p target/bin BIN_NAME='${bin.name or crateName}' ${if !bin ? path then '' @@ -79,6 +87,8 @@ BIN_PATH='${bin.path}' ''} ${build_bin} "$BIN_NAME" "$BIN_PATH" + '' else '' + echo Binary ${bin.name or crateName} not compiled due to not having all of the required features -- ${lib.escapeShellArg (builtins.toJSON bin.requiredFeatures)} -- enabled. '') crateBin)} ${lib.optionalString buildTests ''