summary refs log tree commit diff
path: root/pkgs/build-support/rust/hooks
diff options
context:
space:
mode:
authorDaniël de Kok <me@danieldk.eu>2021-02-15 10:26:40 +0100
committerDaniël de Kok <me@danieldk.eu>2021-02-16 08:09:15 +0100
commit05e40e79a8559cdbe323ab05e003d56033000ee8 (patch)
treec4a1ff0bca75bc2689c33a04708678b6a551cdb2 /pkgs/build-support/rust/hooks
parent9757c7101a0527c001fa9e9832764d5dc106ff25 (diff)
downloadnixpkgs-05e40e79a8559cdbe323ab05e003d56033000ee8.tar
nixpkgs-05e40e79a8559cdbe323ab05e003d56033000ee8.tar.gz
nixpkgs-05e40e79a8559cdbe323ab05e003d56033000ee8.tar.bz2
nixpkgs-05e40e79a8559cdbe323ab05e003d56033000ee8.tar.lz
nixpkgs-05e40e79a8559cdbe323ab05e003d56033000ee8.tar.xz
nixpkgs-05e40e79a8559cdbe323ab05e003d56033000ee8.tar.zst
nixpkgs-05e40e79a8559cdbe323ab05e003d56033000ee8.zip
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`.
Diffstat (limited to 'pkgs/build-support/rust/hooks')
-rw-r--r--pkgs/build-support/rust/hooks/cargo-check-hook.sh37
-rw-r--r--pkgs/build-support/rust/hooks/default.nix9
2 files changed, 46 insertions, 0 deletions
diff --git a/pkgs/build-support/rust/hooks/cargo-check-hook.sh b/pkgs/build-support/rust/hooks/cargo-check-hook.sh
new file mode 100644
index 00000000000..a1df2babffb
--- /dev/null
+++ b/pkgs/build-support/rust/hooks/cargo-check-hook.sh
@@ -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
diff --git a/pkgs/build-support/rust/hooks/default.nix b/pkgs/build-support/rust/hooks/default.nix
index b43f83acda0..e8927e2b542 100644
--- a/pkgs/build-support/rust/hooks/default.nix
+++ b/pkgs/build-support/rust/hooks/default.nix
@@ -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";