buildRustCrate: Do not compile binaries if all the requiredFeatures aren't enabled.

This commit is contained in:
marius david 2022-08-23 13:09:33 +02:00
parent c83b87fecd
commit 3291bda7b6

View File

@ -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 ''