@@ -1,6 +1,7 @@
1−{ lib, rustPlatform, fetchFromGitHub, writeText }:
1+{ lib, rust, rustPlatform, fetchFromGitHub }:
22
3−rustPlatform.buildRustPackage rec {
3+let
4+ mkBlogOsTest = target: rustPlatform.buildRustPackage rec {
45 name = "blog_os-sysroot-test";
56
67 src = fetchFromGitHub {
@@ -12,27 +13,7 @@ rustPlatform.buildRustPackage rec {
1213
1314 cargoSha256 = "1cbcplgz28yxshyrp2krp1jphbrcqdw6wxx3rry91p7hiqyibd30";
1415
15− # The book uses rust-lld for linking, but rust-lld is not currently packaged for NixOS.
16− # The justification in the book for using rust-lld suggests that gcc can still be used for testing:
17− # > Instead of using the platform's default linker (which might not support Linux targets),
18− # > we use the cross platform LLD linker that is shipped with Rust for linking our kernel.
19− # https://github.com/phil-opp/blog_os/blame/7212ffaa8383122b1eb07fe1854814f99d2e1af4/blog/content/second-edition/posts/02-minimal-rust-kernel/index.md#L157
20− target = writeText "x86_64-blog_os.json" ''
21− {
22− "llvm-target": "x86_64-unknown-none",
23− "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
24− "arch": "x86_64",
25− "target-endian": "little",
26− "target-pointer-width": "64",
27− "target-c-int-width": "32",
28− "os": "none",
29− "executables": true,
30− "linker-flavor": "gcc",
31− "panic-strategy": "abort",
32− "disable-redzone": true,
33− "features": "-mmx,-sse,+soft-float"
34− }
35− '';
16+ inherit target;
3617
3718 RUSTFLAGS = "-C link-arg=-nostartfiles";
3819
@@ -42,5 +23,38 @@ rustPlatform.buildRustPackage rec {
4223 meta = with lib; {
4324 description = "Test for using custom sysroots with buildRustPackage";
4425 maintainers = with maintainers; [ aaronjanse ];
26+ platforms = lib.platforms.x86_64;
4527 };
28+ };
29+
30+ # The book uses rust-lld for linking, but rust-lld is not currently packaged for NixOS.
31+ # The justification in the book for using rust-lld suggests that gcc can still be used for testing:
32+ # > Instead of using the platform's default linker (which might not support Linux targets),
33+ # > we use the cross platform LLD linker that is shipped with Rust for linking our kernel.
34+ # https://github.com/phil-opp/blog_os/blame/7212ffaa8383122b1eb07fe1854814f99d2e1af4/blog/content/second-edition/posts/02-minimal-rust-kernel/index.md#L157
35+ targetContents = {
36+ "llvm-target" = "x86_64-unknown-none";
37+ "data-layout" = "e-m:e-i64:64-f80:128-n8:16:32:64-S128";
38+ "arch" = "x86_64";
39+ "target-endian" = "little";
40+ "target-pointer-width" = "64";
41+ "target-c-int-width" = "32";
42+ "os" = "none";
43+ "executables" = true;
44+ "linker-flavor" = "gcc";
45+ "panic-strategy" = "abort";
46+ "disable-redzone" = true;
47+ "features" = "-mmx,-sse,+soft-float";
48+ };
49+
50+in {
51+ blogOS-targetByFile = mkBlogOsTest (builtins.toFile "x86_64-blog_os.json" (builtins.toJSON targetContents));
52+ blogOS-targetByNix = let
53+ plat = lib.systems.elaborate { config = "x86_64-none"; } // {
54+ rustc = {
55+ config = "x86_64-blog_os";
56+ platform = targetContents;
57+ };
58+ };
59+ in mkBlogOsTest (rust.toRustTargetSpec plat);
4660}