From e4c71e6c6c7612f8e0d40ba5b79322f0883fa500 Mon Sep 17 00:00:00 2001 From: zowoq <59103226+zowoq@users.noreply.github.com> Date: Wed, 9 Sep 2020 21:39:23 +1000 Subject: [PATCH 1/4] buildRustPackage: support setting test-threads --- doc/languages-frameworks/rust.section.md | 12 ++++++++++++ pkgs/build-support/rust/default.nix | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 7f9d93216ed9..0e1d59e1a952 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -119,6 +119,18 @@ The above are just guidelines, and exceptions may be granted on a case-by-case b However, please check if it's possible to disable a problematic subset of the test suite and leave a comment explaining your reasoning. +#### Setting `test-threads` + +`buildRustPackage` will use parallel test threads by default, +sometimes it may be necessary to disable this so the tests run consecutively. + +```nix +rustPlatform.buildRustPackage { + /* ... */ + cargoParallelTestThreads = false; +} +``` + ### Building a package in `debug` mode By default, `buildRustPackage` will use `release` mode for builds. If a package diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index 0103e064828b..f6177ce198da 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -30,6 +30,8 @@ , cargoVendorDir ? null , checkType ? buildType , depsExtraArgs ? {} +, cargoParallelTestThreads ? true + # Needed to `pushd`/`popd` into a subdir of a tarball if this subdir # contains a Cargo.toml, but isn't part of a workspace (which is e.g. the # case for `rustfmt`/etc from the `rust-sources). @@ -204,11 +206,12 @@ stdenv.mkDerivation ((removeAttrs args ["depsExtraArgs"]) // { checkPhase = args.checkPhase or (let argstr = "${stdenv.lib.optionalString (checkType == "release") "--release"} --target ${rustTarget} --frozen"; + threads = if cargoParallelTestThreads then "$NIX_BUILD_CORES" else "1"; in '' ${stdenv.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=$NIX_BUILD_CORES ''${checkFlags} ''${checkFlagsArray+"''${checkFlagsArray[@]}"} + cargo test -j $NIX_BUILD_CORES ${argstr} -- --test-threads=${threads} ''${checkFlags} ''${checkFlagsArray+"''${checkFlagsArray[@]}"} runHook postCheck ${stdenv.lib.optionalString (buildAndTestSubdir != null) "popd"} ''); From f294531f17b6daddc7a9b44df6844bdf04405420 Mon Sep 17 00:00:00 2001 From: zowoq <59103226+zowoq@users.noreply.github.com> Date: Wed, 9 Sep 2020 21:39:23 +1000 Subject: [PATCH 2/4] castor: use cargoParallelTestThreads --- pkgs/applications/networking/browsers/castor/default.nix | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkgs/applications/networking/browsers/castor/default.nix b/pkgs/applications/networking/browsers/castor/default.nix index dd8ddd2dccb8..c9ad213cf1d1 100644 --- a/pkgs/applications/networking/browsers/castor/default.nix +++ b/pkgs/applications/networking/browsers/castor/default.nix @@ -39,8 +39,7 @@ rustPlatform.buildRustPackage rec { postInstall = "make PREFIX=$out copy-data"; # Sometimes tests fail when run in parallel - #checkFlags = [ "--test-threads=1" ]; - doCheck = false; + cargoParallelTestThreads = false; meta = with stdenv.lib; { description = "A graphical client for plain-text protocols written in Rust with GTK. It currently supports the Gemini, Gopher and Finger protocols"; @@ -49,4 +48,3 @@ rustPlatform.buildRustPackage rec { maintainers = with maintainers; [ fgaz ]; }; } - From 664170166edb47028adb71f4edd3a1dc69873799 Mon Sep 17 00:00:00 2001 From: zowoq <59103226+zowoq@users.noreply.github.com> Date: Wed, 9 Sep 2020 21:39:23 +1000 Subject: [PATCH 3/4] gitAndTools.git-interactive-rebase-tool: use cargoParallelTestThreads --- .../git-and-tools/git-interactive-rebase-tool/default.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkgs/applications/version-management/git-and-tools/git-interactive-rebase-tool/default.nix b/pkgs/applications/version-management/git-and-tools/git-interactive-rebase-tool/default.nix index e6185ec8ab9d..b656deaa7168 100644 --- a/pkgs/applications/version-management/git-and-tools/git-interactive-rebase-tool/default.nix +++ b/pkgs/applications/version-management/git-and-tools/git-interactive-rebase-tool/default.nix @@ -15,8 +15,7 @@ rustPlatform.buildRustPackage rec { buildInputs = [ ncurses5 ] ++ stdenv.lib.optionals stdenv.isDarwin [ libiconv Security ]; - #checkFlagsArray = [ "--test-threads=1" ]; - doCheck = false; + cargoParallelTestThreads = false; meta = with stdenv.lib; { homepage = "https://github.com/MitMaro/git-interactive-rebase-tool"; From a6c17c9cdd23af192a811e6c7b3cfb37fcd986fb Mon Sep 17 00:00:00 2001 From: zowoq <59103226+zowoq@users.noreply.github.com> Date: Wed, 9 Sep 2020 21:39:23 +1000 Subject: [PATCH 4/4] the-way: use cargoParallelTestThreads --- pkgs/development/tools/the-way/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/tools/the-way/default.nix b/pkgs/development/tools/the-way/default.nix index dce18580577c..6042f5f891a6 100644 --- a/pkgs/development/tools/the-way/default.nix +++ b/pkgs/development/tools/the-way/default.nix @@ -16,8 +16,8 @@ rustPlatform.buildRustPackage rec { buildInputs = stdenv.lib.optionals stdenv.isDarwin [ AppKit Security ]; cargoSha256 = "0adhgp6blwx7s1hlwqzzsgkzc43q9avxx8a9ykvvv2s1w7m9ql78"; - #checkFlags = "--test-threads=1"; - doCheck = false; + checkFlagsArray = stdenv.lib.optionals stdenv.isDarwin [ "--skip=copy" ]; + cargoParallelTestThreads = false; postInstall = '' $out/bin/the-way config default tmp.toml