nixpkgs/pkgs/test/rust-sysroot/default.nix

61 lines
2.1 KiB
Nix
Raw Normal View History

{ lib, rust, rustPlatform, fetchFromGitHub }:
2020-10-17 07:43:33 +00:00
let
mkBlogOsTest = target: rustPlatform.buildRustPackage rec {
2020-10-17 07:43:33 +00:00
name = "blog_os-sysroot-test";
src = fetchFromGitHub {
owner = "phil-opp";
repo = "blog_os";
rev = "4e38e7ddf8dd021c3cd7e4609dfa01afb827797b";
sha256 = "0k9ipm9ddm1bad7bs7368wzzp6xwrhyfzfpckdax54l4ffqwljcg";
};
cargoSha256 = "1cbcplgz28yxshyrp2krp1jphbrcqdw6wxx3rry91p7hiqyibd30";
inherit target;
2020-10-17 07:43:33 +00:00
RUSTFLAGS = "-C link-arg=-nostartfiles";
# Tests don't work for `no_std`. See https://os.phil-opp.com/testing/
2020-10-17 21:38:36 +00:00
doCheck = false;
2020-10-17 07:58:09 +00:00
meta = with lib; {
2020-10-17 07:58:27 +00:00
description = "Test for using custom sysroots with buildRustPackage";
2020-10-17 07:58:09 +00:00
maintainers = with maintainers; [ aaronjanse ];
platforms = lib.platforms.x86_64;
2020-10-17 07:58:09 +00:00
};
};
# The book uses rust-lld for linking, but rust-lld is not currently packaged for NixOS.
# The justification in the book for using rust-lld suggests that gcc can still be used for testing:
# > Instead of using the platform's default linker (which might not support Linux targets),
# > we use the cross platform LLD linker that is shipped with Rust for linking our kernel.
# https://github.com/phil-opp/blog_os/blame/7212ffaa8383122b1eb07fe1854814f99d2e1af4/blog/content/second-edition/posts/02-minimal-rust-kernel/index.md#L157
targetContents = {
"llvm-target" = "x86_64-unknown-none";
"data-layout" = "e-m:e-i64:64-f80:128-n8:16:32:64-S128";
"arch" = "x86_64";
"target-endian" = "little";
"target-pointer-width" = "64";
"target-c-int-width" = "32";
"os" = "none";
"executables" = true;
"linker-flavor" = "gcc";
"panic-strategy" = "abort";
"disable-redzone" = true;
"features" = "-mmx,-sse,+soft-float";
};
in {
blogOS-targetByFile = mkBlogOsTest (builtins.toFile "x86_64-blog_os.json" (builtins.toJSON targetContents));
blogOS-targetByNix = let
plat = lib.systems.elaborate { config = "x86_64-none"; } // {
rustc = {
config = "x86_64-blog_os";
platform = targetContents;
};
};
in mkBlogOsTest (rust.toRustTargetSpec plat);
2020-10-17 07:43:33 +00:00
}