buildRustPackage: factor out check phase to cargoCheckHook
API change: `cargoParallelTestThreads` suggests that this attribute sets the number of threads used during tests, while it is actually a boolean option (use 1 thread or NIX_BUILD_CORES threads). In the hook, this is replaced by a more canonical name `dontUseCargoParallelTests`.
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
, lib
|
||||
, buildPackages
|
||||
, cacert
|
||||
, cargo
|
||||
, cargoBuildHook
|
||||
, cargoCheckHook
|
||||
, cargoInstallHook
|
||||
, cargoSetupHook
|
||||
, fetchCargoTarball
|
||||
@@ -42,7 +42,6 @@
|
||||
, cargoVendorDir ? null
|
||||
, checkType ? buildType
|
||||
, depsExtraArgs ? {}
|
||||
, cargoParallelTestThreads ? true
|
||||
|
||||
# Toggles whether a custom sysroot is created when the target is a .json file.
|
||||
, __internal_dontAddSysroot ? false
|
||||
@@ -105,8 +104,15 @@ stdenv.mkDerivation ((removeAttrs args ["depsExtraArgs"]) // lib.optionalAttrs u
|
||||
|
||||
patchRegistryDeps = ./patch-registry-deps;
|
||||
|
||||
nativeBuildInputs = nativeBuildInputs ++
|
||||
[ cacert git cargo cargoBuildHook cargoInstallHook cargoSetupHook rustc ];
|
||||
nativeBuildInputs = nativeBuildInputs ++ [
|
||||
cacert
|
||||
git
|
||||
cargoBuildHook
|
||||
cargoCheckHook
|
||||
cargoInstallHook
|
||||
cargoSetupHook
|
||||
rustc
|
||||
];
|
||||
|
||||
buildInputs = buildInputs ++ lib.optional stdenv.hostPlatform.isMinGW windows.pthreads;
|
||||
|
||||
@@ -126,18 +132,6 @@ stdenv.mkDerivation ((removeAttrs args ["depsExtraArgs"]) // lib.optionalAttrs u
|
||||
runHook postConfigure
|
||||
'';
|
||||
|
||||
checkPhase = args.checkPhase or (let
|
||||
argstr = "${lib.optionalString (checkType == "release") "--release"} --target ${target} --frozen";
|
||||
threads = if cargoParallelTestThreads then "$NIX_BUILD_CORES" else "1";
|
||||
in ''
|
||||
${lib.optionalString (buildAndTestSubdir != null) "pushd ${buildAndTestSubdir}"}
|
||||
runHook preCheck
|
||||
echo "Running cargo test ${argstr} -- ''${checkFlags} ''${checkFlagsArray+''${checkFlagsArray[@]}}"
|
||||
cargo test -j $NIX_BUILD_CORES ${argstr} -- --test-threads=${threads} ''${checkFlags} ''${checkFlagsArray+"''${checkFlagsArray[@]}"}
|
||||
runHook postCheck
|
||||
${lib.optionalString (buildAndTestSubdir != null) "popd"}
|
||||
'');
|
||||
|
||||
doCheck = args.doCheck or true;
|
||||
|
||||
strictDeps = true;
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
cargoCheckHook() {
|
||||
echo "Executing cargoCheckHook"
|
||||
|
||||
runHook preCheck
|
||||
|
||||
if [[ -n "${buildAndTestSubdir-}" ]]; then
|
||||
pushd "${buildAndTestSubdir}"
|
||||
fi
|
||||
|
||||
if [[ -z ${dontUseCargoParallelTests-} ]]; then
|
||||
threads=$NIX_BUILD_CORES
|
||||
else
|
||||
threads=1
|
||||
fi
|
||||
|
||||
argstr="--${cargoBuildType} --target @rustTargetPlatformSpec@ --frozen";
|
||||
|
||||
(
|
||||
set -x
|
||||
cargo test \
|
||||
-j $NIX_BUILD_CORES \
|
||||
${argstr} -- \
|
||||
--test-threads=${threads} \
|
||||
${checkFlags} \
|
||||
${checkFlagsArray+"${checkFlagsArray[@]}"}
|
||||
)
|
||||
|
||||
if [[ -n "${buildAndTestSubdir-}" ]]; then
|
||||
popd
|
||||
fi
|
||||
|
||||
echo "Finished cargoCheckHook"
|
||||
|
||||
runHook postCheck
|
||||
}
|
||||
|
||||
checkPhase=cargoCheckHook
|
||||
@@ -36,6 +36,15 @@ in {
|
||||
};
|
||||
} ./cargo-build-hook.sh) {};
|
||||
|
||||
cargoCheckHook = callPackage ({ }:
|
||||
makeSetupHook {
|
||||
name = "cargo-check-hook.sh";
|
||||
deps = [ cargo ];
|
||||
substitutions = {
|
||||
inherit rustTargetPlatformSpec;
|
||||
};
|
||||
} ./cargo-check-hook.sh) {};
|
||||
|
||||
cargoInstallHook = callPackage ({ }:
|
||||
makeSetupHook {
|
||||
name = "cargo-install-hook.sh";
|
||||
|
||||
Reference in New Issue
Block a user