diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index 3d7057dd7d97..2cfd8d172869 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -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 ++ [ diff --git a/pkgs/build-support/rust/hooks/cargo-build-hook.sh b/pkgs/build-support/rust/hooks/cargo-build-hook.sh index c10120c5aa19..54ed765012b9 100644 --- a/pkgs/build-support/rust/hooks/cargo-build-hook.sh +++ b/pkgs/build-support/rust/hooks/cargo-build-hook.sh @@ -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} ) diff --git a/pkgs/build-support/rust/hooks/cargo-check-hook.sh b/pkgs/build-support/rust/hooks/cargo-check-hook.sh index 8a8e434f0ff6..57fc2779cfe9 100644 --- a/pkgs/build-support/rust/hooks/cargo-check-hook.sh +++ b/pkgs/build-support/rust/hooks/cargo-check-hook.sh @@ -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