Merge pull request #97603 from zowoq/rust-test-threads

This commit is contained in:
Jörg Thalheim 2020-09-25 06:19:23 +02:00 committed by GitHub
commit a2960ac430
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 8 deletions

View File

@ -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 However, please check if it's possible to disable a problematic subset of the
test suite and leave a comment explaining your reasoning. 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 ### Building a package in `debug` mode
By default, `buildRustPackage` will use `release` mode for builds. If a package By default, `buildRustPackage` will use `release` mode for builds. If a package

View File

@ -39,8 +39,7 @@ rustPlatform.buildRustPackage rec {
postInstall = "make PREFIX=$out copy-data"; postInstall = "make PREFIX=$out copy-data";
# Sometimes tests fail when run in parallel # Sometimes tests fail when run in parallel
#checkFlags = [ "--test-threads=1" ]; cargoParallelTestThreads = false;
doCheck = false;
meta = with stdenv.lib; { 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"; 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 ]; maintainers = with maintainers; [ fgaz ];
}; };
} }

View File

@ -15,8 +15,7 @@ rustPlatform.buildRustPackage rec {
buildInputs = [ ncurses5 ] ++ stdenv.lib.optionals stdenv.isDarwin [ libiconv Security ]; buildInputs = [ ncurses5 ] ++ stdenv.lib.optionals stdenv.isDarwin [ libiconv Security ];
#checkFlagsArray = [ "--test-threads=1" ]; cargoParallelTestThreads = false;
doCheck = false;
meta = with stdenv.lib; { meta = with stdenv.lib; {
homepage = "https://github.com/MitMaro/git-interactive-rebase-tool"; homepage = "https://github.com/MitMaro/git-interactive-rebase-tool";

View File

@ -30,6 +30,8 @@
, cargoVendorDir ? null , cargoVendorDir ? null
, checkType ? buildType , checkType ? buildType
, depsExtraArgs ? {} , depsExtraArgs ? {}
, cargoParallelTestThreads ? true
# Needed to `pushd`/`popd` into a subdir of a tarball if this subdir # 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 # contains a Cargo.toml, but isn't part of a workspace (which is e.g. the
# case for `rustfmt`/etc from the `rust-sources). # case for `rustfmt`/etc from the `rust-sources).
@ -204,11 +206,12 @@ stdenv.mkDerivation ((removeAttrs args ["depsExtraArgs"]) // {
checkPhase = args.checkPhase or (let checkPhase = args.checkPhase or (let
argstr = "${stdenv.lib.optionalString (checkType == "release") "--release"} --target ${rustTarget} --frozen"; argstr = "${stdenv.lib.optionalString (checkType == "release") "--release"} --target ${rustTarget} --frozen";
threads = if cargoParallelTestThreads then "$NIX_BUILD_CORES" else "1";
in '' in ''
${stdenv.lib.optionalString (buildAndTestSubdir != null) "pushd ${buildAndTestSubdir}"} ${stdenv.lib.optionalString (buildAndTestSubdir != null) "pushd ${buildAndTestSubdir}"}
runHook preCheck runHook preCheck
echo "Running cargo test ${argstr} -- ''${checkFlags} ''${checkFlagsArray+''${checkFlagsArray[@]}}" 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 runHook postCheck
${stdenv.lib.optionalString (buildAndTestSubdir != null) "popd"} ${stdenv.lib.optionalString (buildAndTestSubdir != null) "popd"}
''); '');

View File

@ -16,8 +16,8 @@ rustPlatform.buildRustPackage rec {
buildInputs = stdenv.lib.optionals stdenv.isDarwin [ AppKit Security ]; buildInputs = stdenv.lib.optionals stdenv.isDarwin [ AppKit Security ];
cargoSha256 = "0adhgp6blwx7s1hlwqzzsgkzc43q9avxx8a9ykvvv2s1w7m9ql78"; cargoSha256 = "0adhgp6blwx7s1hlwqzzsgkzc43q9avxx8a9ykvvv2s1w7m9ql78";
#checkFlags = "--test-threads=1"; checkFlagsArray = stdenv.lib.optionals stdenv.isDarwin [ "--skip=copy" ];
doCheck = false; cargoParallelTestThreads = false;
postInstall = '' postInstall = ''
$out/bin/the-way config default tmp.toml $out/bin/the-way config default tmp.toml