Skip to content

Commit

Permalink
nix: Add justBuildTests parameter to buildCratesInLayers
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Spinale <nick@nickspinale.com>
  • Loading branch information
nspin committed May 29, 2024
1 parent b1334ac commit 5c2626a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 14 additions & 7 deletions hacking/nix/rust-utils/build-crates-in-layers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ in
, noDefaultFeatures ? false

, test ? false
, justBuildTests ? false

, verifyWithVerus ? false
, extraVerusArgs ? []
Expand Down Expand Up @@ -162,12 +163,12 @@ let
else "build"
);

mkCargoInvocation = runClippy: commonArgs: subcommandArgs:
mkCargoInvocation = isLastLayer: runClippy: commonArgs: subcommandArgs:
let
joinedCommonArgs = lib.concatStringsSep " " commonArgs;
joinedSubcommandArgs = lib.concatStringsSep " " (
subcommandArgs
++ lib.optionals test [ "--no-run" ]
++ lib.optionals (test && (!isLastLayer || justBuildTests)) [ "--no-run" ]
++ lib.optionals verifyWithVerus ([ "--" ] ++ extraVerusArgs)
);
in ''
Expand Down Expand Up @@ -225,7 +226,7 @@ let
cp -r --preserve=timestamps ${prev} $out
chmod -R +w $out
${mkCargoInvocation runClippyThisLayer (flags ++ [
${mkCargoInvocation false runClippyThisLayer (flags ++ [
"--config" "${config}"
"--manifest-path" "${workspace}/Cargo.toml"
"--target-dir" "$out"
Expand Down Expand Up @@ -271,17 +272,23 @@ in let
cp -r --preserve=timestamps ${lastIntermediateLayer} $target_dir
chmod -R +w $target_dir
${mkCargoInvocation runClippy (flags ++ [
${mkCargoInvocation true runClippy (flags ++ [
"--config" "${config}"
"--manifest-path" "${workspace}/Cargo.toml"
"--target-dir" "$target_dir"
]) (lib.optionals (!test) [
"--out-dir" "$out/bin"
])}
${lib.optionalString test (lib.concatStringsSep " " (findTestsCommandPrefix "$target_dir" ++ [
"-exec" "install" "-D" "-t" "$out/bin" "'{}'" "';'"
]))}
${lib.optionalString test (
if justBuildTests
then (lib.concatStringsSep " " (findTestsCommandPrefix "$target_dir" ++ [
"-exec" "install" "-D" "-t" "$out/bin" "'{}'" "';'"
]))
else ''
touch $out
''
)}
runHook postBuild
'';
Expand Down
2 changes: 2 additions & 0 deletions hacking/nix/scope/world/instances/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ in rec {
rootTask = mkTask {
rootCrate = crates.tests-root-task-default-test-harness;
test = true;
justBuildTests = true;
};
extraPlatformArgs = lib.optionalAttrs canSimulate {
canAutomateSimply = true;
Expand All @@ -231,6 +232,7 @@ in rec {
rootTask = lib.makeOverridable mkTask {
rootCrate = crates.ring;
test = true;
justBuildTests = true;
features = [
"less-safe-getrandom-custom-or-rdrand"
# "slow_tests"
Expand Down

0 comments on commit 5c2626a

Please sign in to comment.