rustPlatform: add support for features

This commit is contained in:
figsoda 2021-10-26 22:41:37 -04:00
parent b6a580b9b3
commit 5a08a28803
3 changed files with 32 additions and 1 deletions

View File

@ -36,6 +36,10 @@
, cargoLock ? null
, cargoVendorDir ? null
, checkType ? buildType
, buildNoDefaultFeatures ? false
, checkNoDefaultFeatures ? buildNoDefaultFeatures
, buildFeatures ? [ ]
, checkFeatures ? buildFeatures
, depsExtraArgs ? {}
# Toggles whether a custom sysroot is created when the target is a .json file.
@ -103,6 +107,14 @@ stdenv.mkDerivation ((removeAttrs args [ "depsExtraArgs" "cargoLock" ]) // lib.o
cargoCheckType = checkType;
cargoBuildNoDefaultFeatures = buildNoDefaultFeatures;
cargoCheckNoDefaultFeatures = checkNoDefaultFeatures;
cargoBuildFeatures = buildFeatures;
cargoCheckFeatures = checkFeatures;
patchRegistryDeps = ./patch-registry-deps;
nativeBuildInputs = nativeBuildInputs ++ [

View File

@ -13,6 +13,14 @@ cargoBuildHook() {
cargoBuildProfileFlag="--${cargoBuildType}"
fi
if [ -n "${cargoBuildNoDefaultFeatures-}" ]; then
cargoBuildNoDefaultFeaturesFlag=--no-default-features
fi
if [ -n "${cargoBuildFeatures-}" ]; then
cargoBuildFeaturesFlag="--features=${cargoBuildFeatures// /,}"
fi
(
set -x
env \
@ -24,6 +32,8 @@ cargoBuildHook() {
--target @rustTargetPlatformSpec@ \
--frozen \
${cargoBuildProfileFlag} \
${cargoBuildNoDefaultFeaturesFlag} \
${cargoBuildFeaturesFlag} \
${cargoBuildFlags}
)

View File

@ -20,7 +20,16 @@ cargoCheckHook() {
cargoCheckProfileFlag="--${cargoCheckType}"
fi
argstr="${cargoCheckProfileFlag} --target @rustTargetPlatformSpec@ --frozen ${cargoTestFlags}";
if [ -n "${cargoCheckNoDefaultFeatures-}" ]; then
cargoCheckNoDefaultFeaturesFlag=--no-default-features
fi
if [ -n "${cargoCheckFeatures-}" ]; then
cargoCheckFeaturesFlag="--features=${cargoCheckFeatures// /,}"
fi
argstr="${cargoCheckProfileFlag} ${cargoCheckNoDefaultFeaturesFlag} ${cargoCheckFeaturesFlag}
--target @rustTargetPlatformSpec@ --frozen ${cargoTestFlags}"
(
set -x