diff --git a/hacking/nix/rust-utils/build-crate-in-layers.nix b/hacking/nix/rust-utils/build-crates-in-layers.nix similarity index 86% rename from hacking/nix/rust-utils/build-crate-in-layers.nix rename to hacking/nix/rust-utils/build-crates-in-layers.nix index 531bae09c..b753433d0 100644 --- a/hacking/nix/rust-utils/build-crate-in-layers.nix +++ b/hacking/nix/rust-utils/build-crates-in-layers.nix @@ -32,7 +32,11 @@ in , rustEnvironment ? defaultRustEnvironment , targetTriple ? defaultRustTargetTriple -, rootCrate + +, name ? if rootCrate != null then rootCrate.name else "build-crates" + +, rootCrate ? null +, rootCrates ? if rootCrate != null then [ rootCrate ] else throw "must supply 'rootCrates' argument" , layers ? [ crateUtils.defaultIntermediateLayer ] # default to two building in two steps (external then local) , commonModifications ? {} @@ -45,6 +49,7 @@ in , noDefaultFeatures ? false , test ? false +, justBuildTests ? false , verifyWithVerus ? false , extraVerusArgs ? [] @@ -74,7 +79,7 @@ let prunedLockfile = pruneLockfile { inherit (rustEnvironment) rustToolchain vendoredSuperLockfile; - rootCrates = [ rootCrate ]; + inherit rootCrates; extraManifest = elaboratedCommonModifications.modifyManifest {}; # TODO }; @@ -87,7 +92,7 @@ let elaboratedCommonModifications = elaborateModifications commonModifications; - closure = crateUtils.getClosureOfCrate rootCrate; + closure = crateUtils.getClosureOfCrates rootCrates; accumulatedLayers = let @@ -116,7 +121,7 @@ let baseManifest = { workspace.resolver = "2"; - workspace.members = [ "src/${rootCrate.name}" ]; + workspace.members = lib.forEach rootCrates (crate: "src/${crate.name}"); }; baseConfig = denyWarnings: crateUtils.clobber [ @@ -137,8 +142,8 @@ let baseFlags = [ "--offline" "--frozen" - "-p" rootCrate.name - ] ++ lib.optionals (lib.length features > 0) [ + ] ++ lib.concatMap (crate: [ "-p" crate.name ]) rootCrates + ++ lib.optionals (lib.length features > 0) [ "--features" (lib.concatStringsSep "," features) ] ++ lib.optionals noDefaultFeatures [ "--no-default-features" @@ -158,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 '' @@ -211,7 +216,7 @@ let runClippyThisLayer = runClippy && layer.reals != {}; in modifications.modifyDerivation (stdenv.mkDerivation (baseArgs // { - name = "${rootCrate.name}-intermediate"; + name = "${name}-intermediate"; phases = [ "buildPhase" ]; @@ -221,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" @@ -256,7 +261,7 @@ in let ]; final = modifications.modifyDerivation (stdenv.mkDerivation (baseArgs // { - name = rootCrate.name; + name = name; phases = [ "buildPhase" ]; @@ -267,7 +272,7 @@ 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" @@ -275,15 +280,21 @@ in let "--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 ''; passthru = { - inherit rootCrate workspace lastIntermediateLayer; + inherit rootCrate rootCrates workspace lastIntermediateLayer; }; })); diff --git a/hacking/nix/rust-utils/default.nix b/hacking/nix/rust-utils/default.nix index 0c429d16c..e796e57eb 100644 --- a/hacking/nix/rust-utils/default.nix +++ b/hacking/nix/rust-utils/default.nix @@ -18,7 +18,7 @@ let in { - buildCrateInLayers = callPackage ./build-crate-in-layers.nix {}; + buildCratesInLayers = callPackage ./build-crates-in-layers.nix {}; buildSysroot = callPackage ./build-sysroot.nix {}; diff --git a/hacking/nix/scope/default.nix b/hacking/nix/scope/default.nix index 8a220d388..8b9af45f5 100644 --- a/hacking/nix/scope/default.nix +++ b/hacking/nix/scope/default.nix @@ -127,7 +127,7 @@ superCallPackage ../rust-utils {} self // mkMkCustomTargetPathForEnvironment = { rustEnvironment }: let - tool = buildCrateInLayers rec { + tool = buildCratesInLayers rec { inherit rustEnvironment; rootCrate = crates.sel4-generate-target-specs; lastLayerModifications = crateUtils.elaborateModifications { @@ -182,7 +182,7 @@ superCallPackage ../rust-utils {} self // ### local tools - mkTool = rootCrate: buildCrateInLayers { + mkTool = rootCrate: buildCratesInLayers { inherit rootCrate; }; @@ -197,6 +197,21 @@ superCallPackage ../rust-utils {} self // shellForMakefile = callPackage ./shell-for-makefile.nix {}; shellForHacking = callPackage ./shell-for-hacking.nix {}; + ### unit tests + + someUnitTests = buildCratesInLayers { + name = "some-unit-tests"; + test = true; + rootCrates = with crates; [ + sel4-bitfield-ops + sel4-kernel-loader-embed-page-tables + sel4-backtrace-types + ]; + features = [ + "sel4-backtrace-types/full" + ]; + }; + ### kernel mkSeL4 = callPackage ./sel4 {}; diff --git a/hacking/nix/scope/world/instances/default.nix b/hacking/nix/scope/world/instances/default.nix index 531ecbd1d..fe6bf3d86 100644 --- a/hacking/nix/scope/world/instances/default.nix +++ b/hacking/nix/scope/world/instances/default.nix @@ -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; @@ -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" diff --git a/hacking/nix/scope/world/mk-task.nix b/hacking/nix/scope/world/mk-task.nix index 680037e59..cc9a8e255 100644 --- a/hacking/nix/scope/world/mk-task.nix +++ b/hacking/nix/scope/world/mk-task.nix @@ -6,7 +6,7 @@ { lib, buildPackages , runCommand, runCommandCC -, buildCrateInLayers, buildSysroot, crateUtils +, buildCratesInLayers, buildSysroot, crateUtils , crates , defaultRustEnvironment , defaultRustTargetTriple @@ -107,7 +107,7 @@ let in -buildCrateInLayers (prunedArgs // { +buildCratesInLayers (prunedArgs // { commonModifications = crateUtils.composeModifications (crateUtils.elaborateModifications commonModifications) theseCommonModifications diff --git a/hacking/nix/scope/world/sel4-kernel-loader.nix b/hacking/nix/scope/world/sel4-kernel-loader.nix index 1107af5bc..b0bab1dd8 100644 --- a/hacking/nix/scope/world/sel4-kernel-loader.nix +++ b/hacking/nix/scope/world/sel4-kernel-loader.nix @@ -5,7 +5,7 @@ # { lib, buildPackages, writeText -, buildCrateInLayers, buildSysroot, crateUtils +, buildCratesInLayers, buildSysroot, crateUtils , crates, bareMetalRustTargetTriple , libclangPath , seL4RustEnvVars, seL4ForBoot, seL4ForUserspace @@ -44,7 +44,7 @@ let }; in -buildCrateInLayers { +buildCratesInLayers { inherit rootCrate; inherit targetTriple; diff --git a/hacking/nix/top-level/default.nix b/hacking/nix/top-level/default.nix index b344e3f17..f09e2e99f 100644 --- a/hacking/nix/top-level/default.nix +++ b/hacking/nix/top-level/default.nix @@ -56,6 +56,8 @@ in { map (instance: instance.links) world.instances.all )) + pkgs.build.this.someUnitTests + someConfigurationBuildTests sel4testInstancesList