2024-03-23 01:39:45 +03:00
|
|
|
{ cargo-llvm-cov
|
|
|
|
, cargo-nextest
|
2023-08-31 02:44:00 +03:00
|
|
|
, rustc
|
2022-07-24 01:04:06 +03:00
|
|
|
, lib
|
2023-08-31 02:44:00 +03:00
|
|
|
, stdenv
|
2022-10-09 22:12:51 +03:00
|
|
|
, mkCargoDerivation
|
2022-07-24 01:04:06 +03:00
|
|
|
, runCommand
|
|
|
|
}:
|
|
|
|
|
|
|
|
{ cargoArtifacts
|
|
|
|
, cargoExtraArgs ? ""
|
2024-03-23 01:39:45 +03:00
|
|
|
, cargoLlvmCovExtraArgs ? "--lcov --output-path $out/coverage"
|
2022-07-24 01:04:06 +03:00
|
|
|
, cargoNextestExtraArgs ? ""
|
|
|
|
, doInstallCargoArtifacts ? true
|
|
|
|
, partitions ? 1
|
|
|
|
, partitionType ? "count"
|
2024-03-23 01:39:45 +03:00
|
|
|
, withLlvmCov ? false
|
2022-07-24 01:04:06 +03:00
|
|
|
, ...
|
|
|
|
}@origArgs:
|
|
|
|
let
|
|
|
|
args = builtins.removeAttrs origArgs [
|
2022-10-09 22:12:51 +03:00
|
|
|
"cargoExtraArgs"
|
2024-03-23 01:39:45 +03:00
|
|
|
"cargoLlvmCovExtraArgs"
|
2022-07-24 01:04:06 +03:00
|
|
|
"cargoNextestExtraArgs"
|
|
|
|
"partitions"
|
|
|
|
"partitionType"
|
2024-03-23 01:39:45 +03:00
|
|
|
"withLlvmCov"
|
2022-07-24 01:04:06 +03:00
|
|
|
];
|
|
|
|
|
2024-08-06 19:07:59 +03:00
|
|
|
mkUpdatedArgs = { cmd ? "run", extraSuffix ? "", moreArgs ? "", withLlvmCov }: args // {
|
2022-07-24 01:04:06 +03:00
|
|
|
inherit cargoArtifacts;
|
|
|
|
pnameSuffix = "-nextest${extraSuffix}";
|
2022-10-09 22:12:51 +03:00
|
|
|
doCheck = args.doCheck or true;
|
2022-07-24 01:04:06 +03:00
|
|
|
|
|
|
|
buildPhaseCargoCommand = args.buildPhaseCargoCommand or ''
|
|
|
|
mkdir -p $out
|
2024-03-23 01:39:45 +03:00
|
|
|
${lib.optionalString withLlvmCov "cargo llvm-cov --version"}
|
2022-07-24 01:04:06 +03:00
|
|
|
cargo nextest --version
|
|
|
|
'';
|
|
|
|
|
2023-08-31 02:44:00 +03:00
|
|
|
# Work around Nextest bug: https://github.com/nextest-rs/nextest/issues/267
|
|
|
|
preCheck = (args.preCheck or "") + lib.optionalString stdenv.isDarwin ''
|
|
|
|
export DYLD_FALLBACK_LIBRARY_PATH=$(${rustc}/bin/rustc --print sysroot)/lib
|
|
|
|
'';
|
|
|
|
|
2024-03-23 01:39:45 +03:00
|
|
|
checkPhaseCargoCommand = ''
|
2024-08-06 19:07:59 +03:00
|
|
|
${if withLlvmCov
|
|
|
|
then "cargo llvm-cov nextest ${cargoLlvmCovExtraArgs}"
|
|
|
|
else "cargo nextest ${cmd}"} \
|
|
|
|
''${CARGO_PROFILE:+--cargo-profile $CARGO_PROFILE} \
|
|
|
|
${cargoExtraArgs} ${cargoNextestExtraArgs} ${moreArgs}
|
2024-03-23 01:39:45 +03:00
|
|
|
'';
|
2022-07-24 01:04:06 +03:00
|
|
|
|
2024-03-23 01:39:45 +03:00
|
|
|
nativeBuildInputs = (args.nativeBuildInputs or [ ])
|
|
|
|
++ [ cargo-nextest ]
|
|
|
|
++ lib.lists.optional withLlvmCov cargo-llvm-cov;
|
2022-07-24 01:04:06 +03:00
|
|
|
};
|
|
|
|
in
|
|
|
|
if partitions < 1 then
|
|
|
|
throw "paritions must be at least 1 or greater"
|
|
|
|
else if partitions == 1 then # Simple case do everything in one derivation
|
2024-03-23 01:39:45 +03:00
|
|
|
mkCargoDerivation (mkUpdatedArgs { inherit withLlvmCov; })
|
2022-07-24 01:04:06 +03:00
|
|
|
else # First build the tests in one derivation, then run each partition in another
|
|
|
|
let
|
|
|
|
mkArchiveArgs = root: "--archive-format tar-zst --archive-file ${root}/archive.tar.zst";
|
2022-10-09 22:12:51 +03:00
|
|
|
archive = mkCargoDerivation (mkUpdatedArgs {
|
2022-07-24 01:04:06 +03:00
|
|
|
cmd = "archive";
|
|
|
|
moreArgs = mkArchiveArgs "$out";
|
2024-03-23 01:39:45 +03:00
|
|
|
withLlvmCov = !(lib.asserts.assertMsg (!withLlvmCov) "withLLvmCov is not supported for partitioned runs");
|
2022-07-24 01:04:06 +03:00
|
|
|
});
|
|
|
|
mkPartition = nInt:
|
|
|
|
let
|
|
|
|
n = toString (nInt + 1);
|
|
|
|
in
|
2022-10-09 22:12:51 +03:00
|
|
|
mkCargoDerivation ((mkUpdatedArgs {
|
2024-03-23 01:39:45 +03:00
|
|
|
inherit withLlvmCov;
|
2022-07-24 01:04:06 +03:00
|
|
|
extraSuffix = "-p${toString n}";
|
2023-06-30 02:50:17 +03:00
|
|
|
moreArgs = builtins.concatStringsSep " " [
|
|
|
|
"${mkArchiveArgs archive}"
|
|
|
|
"--workspace-remap ."
|
|
|
|
"--partition ${partitionType}:${n}/${toString partitions}"
|
|
|
|
];
|
2022-07-24 01:04:06 +03:00
|
|
|
}) // {
|
|
|
|
# Everything we need is already in the archive
|
|
|
|
cargoArtifacts = null;
|
|
|
|
cargoVendorDir = null;
|
|
|
|
doInstallCargoArtifacts = false;
|
|
|
|
|
|
|
|
# Nextest does not like extra args when running with an archive
|
|
|
|
CARGO_PROFILE = "";
|
|
|
|
});
|
|
|
|
in
|
|
|
|
# Allow for retaining the artifacts from the `archive` derivation
|
2022-11-21 03:28:49 +03:00
|
|
|
# if callers want to chain other derivations after it. We provide
|
|
|
|
# the actual `partition*` derivations as inputs to ensure they are run.
|
2022-07-24 01:04:06 +03:00
|
|
|
runCommand "cargo-nextest-tests"
|
|
|
|
{
|
|
|
|
inherit doInstallCargoArtifacts;
|
|
|
|
buildInputs = lib.genList mkPartition partitions;
|
|
|
|
} ''
|
|
|
|
if [ "1" = "''${doInstallCargoArtifacts-}" ]; then
|
|
|
|
cp --recursive ${archive} $out/
|
|
|
|
else
|
|
|
|
mkdir -p $out
|
|
|
|
fi
|
|
|
|
''
|