Skip to content

Commit

Permalink
nix: Use Rust in sel4test
Browse files Browse the repository at this point in the history
  • Loading branch information
nspin committed Feb 10, 2024
1 parent 34836fc commit 4d8cd6b
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
1 change: 1 addition & 0 deletions hacking/nix/scope/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ superCallPackage ../rust-utils {} self //

# TODO name more configurations
sel4test = makeOverridable' mkSeL4Test {
rust = hostPlatform.isAarch || hostPlatform.isRiscV || hostPlatform.isx86_64;
# mcs = true;
};

Expand Down
81 changes: 80 additions & 1 deletion hacking/nix/scope/sel4test/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,34 @@
, qemuForSeL4
, git
, sources
, crateUtils
, defaultRustToolchain
, bareMetalRustTargetInfo
, libclangPath
, vendoredTopLevelLockfile
, buildSysroot
, crates
, pruneLockfile
, topLevelLockfile
, vendorLockfile
, runCommandCC
, seL4Arch
}:

{ mcs ? false
, smp ? false
, virtualization ? false
, rust ? true
, release ? false
, filter ? ".*"
}:

with lib;

let
rustToolchain = defaultRustToolchain;
rustTargetInfo = bareMetalRustTargetInfo;

initBuildArgs =
let
bool = v: if v then "TRUE" else "FALSE";
Expand All @@ -36,7 +51,14 @@ let
"-DMCS=${bool mcs}"
"-DSMP=${bool smp}"
"-DSIMULATION=TRUE"
"-DLibSel4UseRust=${bool rust}"
"-DLibSel4TestPrinterRegex='${filter}'"
] ++ lib.optionals rust [
"-DHACK_RUST_TARGET=${rustTargetInfo.name}"
"-DHACK_CARGO_MANIFEST_PATH=${workspace}/Cargo.toml"
"-DHACK_CARGO_CONFIG=${cargoConfig}"
"-DHACK_CARGO_NO_BUILD_SYSROOT=TRUE"
"-DHACK_CARGO_RELEASE=${bool release}"
] ++ lib.optionals hostPlatform.isi686 [
"-DPLATFORM=pc99"
] ++ lib.optionals hostPlatform.isRiscV [
Expand All @@ -50,7 +72,60 @@ let
"-DARM_CPU=cortex-a15"
];

kernelSrc = sources.seL4.rust;
kernelSrc = sources.seL4.rust-sel4test;

cratesSrc = crateUtils.collectReals (lib.attrValues (crateUtils.getClosureOfCrate rootCrate));

rootCrate = crates.sel4-sys-wrappers;

lockfile = builtins.toFile "Cargo.lock" lockfileContents;
lockfileContents = builtins.readFile lockfileDrv;
lockfileDrv = pruneLockfile {
superLockfile = topLevelLockfile;
superLockfileVendoringConfig = vendoredTopLevelLockfile.configFragment;
rootCrates = [ rootCrate ];
};

cargoConfig = crateUtils.toTOMLFile "config" (crateUtils.clobber [
(crateUtils.baseConfig {
inherit rustToolchain;
rustTargetName = rustTargetInfo.name;
})
{
target.${rustTargetInfo.name}.rustflags = [
"--sysroot" sysroot
];
}
(vendorLockfile { inherit lockfileContents; }).configFragment
]);

profiles = {
profile.release = {
debug = 0;
opt-level = "z";
};
};

manifest = crateUtils.toTOMLFile "Cargo.toml" (crateUtils.clobber [
{
workspace.resolver = "2";
workspace.members = [ "src/${rootCrate.name}" ];
}
profiles
]);

workspace = linkFarm "workspace" [
{ name = "Cargo.toml"; path = manifest; }
{ name = "Cargo.lock"; path = lockfile; }
{ name = "src"; path = cratesSrc; }
];

sysroot = buildSysroot {
release = false; # TODO why?
inherit rustTargetInfo;
extraManifest = profiles;
compilerBuiltinsWeakIntrinsics = true;
};

tests = stdenv.mkDerivation {
name = "sel4test";
Expand All @@ -62,6 +137,8 @@ let
sha256 = "sha256-1Gmbksgh2VTUggM6qcawRC9b+g/bwB8tWGfUzCg1A0U=";
};

LIBCLANG_PATH = libclangPath;

depsBuildBuild = lib.optionals (buildPlatform != hostPlatform) [
buildPackages.stdenv.cc
# NOTE: cause drv.__spliced.buildBuild to be used to work around splicing issue
Expand All @@ -72,6 +149,7 @@ let
cmake ninja
libxml2 dtc cpio protobuf
git
defaultRustToolchain
] ++ (with python3Packages; [
aenum plyplus pyelftools simpleeval
sel4-deps
Expand Down Expand Up @@ -126,6 +204,7 @@ let
installPhase = ''
cd ..
mv build $out
rm -rf $out/libsel4/rust/target
'';

dontFixup = true;
Expand Down

0 comments on commit 4d8cd6b

Please sign in to comment.