From 0643540f97995e785b5e1d9b62be6876da3d2d20 Mon Sep 17 00:00:00 2001 From: figsoda Date: Mon, 28 Nov 2022 16:59:52 -0500 Subject: [PATCH 1/4] rustPlatform.cargoNextestHook: init --- .../rust/hooks/cargo-nextest-hook.sh | 54 +++++++++++++++++++ pkgs/build-support/rust/hooks/default.nix | 10 ++++ 2 files changed, 64 insertions(+) create mode 100644 pkgs/build-support/rust/hooks/cargo-nextest-hook.sh diff --git a/pkgs/build-support/rust/hooks/cargo-nextest-hook.sh b/pkgs/build-support/rust/hooks/cargo-nextest-hook.sh new file mode 100644 index 000000000000..de85683ead2a --- /dev/null +++ b/pkgs/build-support/rust/hooks/cargo-nextest-hook.sh @@ -0,0 +1,54 @@ +declare -a checkFlags +declare -a cargoTestFlags + +cargoNextestHook() { + echo "Executing cargoNextestHook" + + runHook preCheck + + if [[ -n "${buildAndTestSubdir-}" ]]; then + pushd "${buildAndTestSubdir}" + fi + + if [[ -z ${dontUseCargoParallelTests-} ]]; then + threads=$NIX_BUILD_CORES + else + threads=1 + fi + + if [ "${cargoCheckType}" != "debug" ]; then + cargoCheckProfileFlag="--${cargoCheckType}" + fi + + 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 + cargo nextest run \ + -j ${threads} \ + ${argstr} -- \ + ${checkFlags} \ + ${checkFlagsArray+"${checkFlagsArray[@]}"} + ) + + if [[ -n "${buildAndTestSubdir-}" ]]; then + popd + fi + + echo "Finished cargoNextestHook" + + runHook postCheck +} + +if [ -z "${dontCargoCheck-}" ] && [ -z "${checkPhase-}" ]; then + checkPhase=cargoNextestHook +fi diff --git a/pkgs/build-support/rust/hooks/default.nix b/pkgs/build-support/rust/hooks/default.nix index 6ee122adb52a..b9bbac371985 100644 --- a/pkgs/build-support/rust/hooks/default.nix +++ b/pkgs/build-support/rust/hooks/default.nix @@ -1,6 +1,7 @@ { buildPackages , callPackage , cargo +, cargo-nextest , clang , lib , makeSetupHook @@ -55,6 +56,15 @@ in { }; } ./cargo-install-hook.sh) {}; + cargoNextestHook = callPackage ({ }: + makeSetupHook { + name = "cargo-nextest-hook.sh"; + deps = [ cargo cargo-nextest ]; + substitutions = { + inherit rustTargetPlatformSpec; + }; + } ./cargo-nextest-hook.sh) {}; + cargoSetupHook = callPackage ({ }: makeSetupHook { name = "cargo-setup-hook.sh"; From d3eb6062965ddfec2e0bc029bfbab21a6421b751 Mon Sep 17 00:00:00 2001 From: figsoda Date: Mon, 28 Nov 2022 17:00:17 -0500 Subject: [PATCH 2/4] rustPlatform.buildRustPackage: add useNextest option to check with cargo-nextest --- pkgs/build-support/rust/build-rust-package/default.nix | 4 +++- pkgs/development/compilers/rust/make-rust-platform.nix | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pkgs/build-support/rust/build-rust-package/default.nix b/pkgs/build-support/rust/build-rust-package/default.nix index 812831c2959c..679e10a3442e 100644 --- a/pkgs/build-support/rust/build-rust-package/default.nix +++ b/pkgs/build-support/rust/build-rust-package/default.nix @@ -9,6 +9,7 @@ , cargoBuildHook , cargoCheckHook , cargoInstallHook +, cargoNextestHook , cargoSetupHook , rustc , libiconv @@ -40,6 +41,7 @@ , checkNoDefaultFeatures ? buildNoDefaultFeatures , buildFeatures ? [ ] , checkFeatures ? buildFeatures +, useNextest ? false , depsExtraArgs ? {} # Toggles whether a custom sysroot is created when the target is a .json file. @@ -117,7 +119,7 @@ stdenv.mkDerivation ((removeAttrs args [ "depsExtraArgs" "cargoUpdateHook" "carg cacert git cargoBuildHook - cargoCheckHook + (if useNextest then cargoNextestHook else cargoCheckHook) cargoInstallHook cargoSetupHook rustc diff --git a/pkgs/development/compilers/rust/make-rust-platform.nix b/pkgs/development/compilers/rust/make-rust-platform.nix index b859d01dc085..f61ba57d7b95 100644 --- a/pkgs/development/compilers/rust/make-rust-platform.nix +++ b/pkgs/development/compilers/rust/make-rust-platform.nix @@ -14,7 +14,7 @@ rec { buildRustPackage = callPackage ../../../build-support/rust/build-rust-package { git = buildPackages.gitMinimal; - inherit stdenv cargoBuildHook cargoCheckHook cargoInstallHook cargoSetupHook + inherit stdenv cargoBuildHook cargoCheckHook cargoInstallHook cargoNextestHook cargoSetupHook fetchCargoTarball importCargoLock rustc; }; @@ -31,5 +31,5 @@ rec { # Hooks inherit (callPackage ../../../build-support/rust/hooks { inherit stdenv cargo rustc; - }) cargoBuildHook cargoCheckHook cargoInstallHook cargoSetupHook maturinBuildHook bindgenHook; + }) cargoBuildHook cargoCheckHook cargoInstallHook cargoNextestHook cargoSetupHook maturinBuildHook bindgenHook; } From 52153336fef629cf60422c9265e757f5ade160b6 Mon Sep 17 00:00:00 2001 From: figsoda Date: Mon, 28 Nov 2022 17:00:44 -0500 Subject: [PATCH 3/4] python-launcher: check with cargo-nextest --- pkgs/development/tools/misc/python-launcher/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/tools/misc/python-launcher/default.nix b/pkgs/development/tools/misc/python-launcher/default.nix index 13863849caa9..f8023022bcdc 100644 --- a/pkgs/development/tools/misc/python-launcher/default.nix +++ b/pkgs/development/tools/misc/python-launcher/default.nix @@ -15,7 +15,7 @@ rustPlatform.buildRustPackage rec { checkInputs = [ python3 ]; - dontUseCargoParallelTests = true; + useNextest = true; meta = with lib; { description = "An implementation of the `py` command for Unix-based platforms"; From 0f386d18962d699c2a9d29f5b62fa645ad887d5f Mon Sep 17 00:00:00 2001 From: figsoda Date: Mon, 28 Nov 2022 17:25:46 -0500 Subject: [PATCH 4/4] docs/rust: document `cargoNextestHook` and `useNextest` --- doc/languages-frameworks/rust.section.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index db5d8c699e3a..591014480299 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -331,6 +331,20 @@ rustPlatform.buildRustPackage { } ``` +#### Using `cargo-nextest` {#using-cargo-nextest} + +Tests can be run with [cargo-nextest](https://github.com/nextest-rs/nextest) +by setting `useNextest = true`. The same options still apply, but nextest +accepts a different set of arguments and the settings might need to be +adapted to be compatible with cargo-nextest. + +```nix +rustPlatform.buildRustPackage { + /* ... */ + useNextest = true; +} +``` + #### Setting `test-threads` {#setting-test-threads} `buildRustPackage` will use parallel test threads by default, @@ -474,6 +488,9 @@ you of the correct hash. flags can be passed to the tests using `checkFlags` and `checkFlagsArray`. By default, tests are run in parallel. This can be disabled by setting `dontUseCargoParallelTests`. +* `cargoNextestHook`: run tests using + [cargo-nextest](https://github.com/nextest-rs/nextest). The same + options for `cargoCheckHook` also applies to `cargoNextestHook`. * `cargoInstallHook`: install binaries and static/shared libraries that were built using `cargoBuildHook`. * `bindgenHook`: for crates which use `bindgen` as a build dependency, lets