Loading doc/languages-frameworks/rust.section.md +17 −0 Original line number Diff line number Diff line Loading @@ -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, Loading Loading @@ -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 Loading pkgs/build-support/rust/build-rust-package/default.nix +3 −1 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ , cargoBuildHook , cargoCheckHook , cargoInstallHook , cargoNextestHook , cargoSetupHook , rustc , libiconv Loading Loading @@ -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. Loading Loading @@ -117,7 +119,7 @@ stdenv.mkDerivation ((removeAttrs args [ "depsExtraArgs" "cargoUpdateHook" "carg cacert git cargoBuildHook cargoCheckHook (if useNextest then cargoNextestHook else cargoCheckHook) cargoInstallHook cargoSetupHook rustc Loading pkgs/build-support/rust/hooks/cargo-nextest-hook.sh 0 → 100644 +54 −0 Original line number Diff line number Diff line 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 pkgs/build-support/rust/hooks/default.nix +10 −0 Original line number Diff line number Diff line { buildPackages , callPackage , cargo , cargo-nextest , clang , lib , makeSetupHook Loading Loading @@ -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"; Loading pkgs/development/compilers/rust/make-rust-platform.nix +2 −2 Original line number Diff line number Diff line Loading @@ -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; }; Loading @@ -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; } Loading
doc/languages-frameworks/rust.section.md +17 −0 Original line number Diff line number Diff line Loading @@ -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, Loading Loading @@ -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 Loading
pkgs/build-support/rust/build-rust-package/default.nix +3 −1 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ , cargoBuildHook , cargoCheckHook , cargoInstallHook , cargoNextestHook , cargoSetupHook , rustc , libiconv Loading Loading @@ -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. Loading Loading @@ -117,7 +119,7 @@ stdenv.mkDerivation ((removeAttrs args [ "depsExtraArgs" "cargoUpdateHook" "carg cacert git cargoBuildHook cargoCheckHook (if useNextest then cargoNextestHook else cargoCheckHook) cargoInstallHook cargoSetupHook rustc Loading
pkgs/build-support/rust/hooks/cargo-nextest-hook.sh 0 → 100644 +54 −0 Original line number Diff line number Diff line 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
pkgs/build-support/rust/hooks/default.nix +10 −0 Original line number Diff line number Diff line { buildPackages , callPackage , cargo , cargo-nextest , clang , lib , makeSetupHook Loading Loading @@ -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"; Loading
pkgs/development/compilers/rust/make-rust-platform.nix +2 −2 Original line number Diff line number Diff line Loading @@ -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; }; Loading @@ -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; }