git.iko.soy/typeable/nixpkgs
on master help sign in
rust: Clean up target configs and test some more

See the new docs for details. The difference is vis-a-vis older versions of this PR, not master.

commitb7650aaa77634e42d62ed6fc1a9081b10139618b authorJohn Ericson <John.Ericson@Obsidian.Systems> dateSat 28 Nov 2020, 19:32 (6 years ago) parent8ddf5c6
3 files changed+47−33
doc/languages-frameworks/rust.section.md+7−7 pkgs/development/compilers/rust/default.nix+3−3 pkgs/test/rust-sysroot/default.nix+37−23
doc/languages-frameworks/rust.section.md+7−7
@@ -71,14 +71,14 @@ By default, it takes the `stdenv.hostPlatform.config` and replaces components
7171where they are known to differ. But there are ways to customize the argument:
7272
7373 - To choose a different target by name, define
74− `stdenv.hostPlatform.rustc.arch.config` as that name (a string), and that
74+ `stdenv.hostPlatform.rustc.config` as that name (a string), and that
7575 name will be used instead.
7676
7777 For example:
7878 ```nix
7979 import <nixpkgs> {
8080 crossSystem = (import <nixpkgs/lib>).systems.examples.armhf-embedded // {
81− rustc.arch.config = "thumbv7em-none-eabi";
81+ rustc.config = "thumbv7em-none-eabi";
8282 };
8383 }
8484 ```
@@ -88,18 +88,18 @@ where they are known to differ. But there are ways to customize the argument:
8888 ```
8989
9090 - To pass a completely custom target, define
91− `stdenv.hostPlatform.rustc.arch.config` with its name, and
92− `stdenv.hostPlatform.rustc.arch.custom` with the value. The value will be
91+ `stdenv.hostPlatform.rustc.config` with its name, and
92+ `stdenv.hostPlatform.rustc.platform` with the value. The value will be
9393 serialized to JSON in a file called
94− `${stdenv.hostPlatform.rustc.arch.config}.json`, and the path of that file
94+ `${stdenv.hostPlatform.rustc.config}.json`, and the path of that file
9595 will be used instead.
9696
9797 For example:
9898 ```nix
9999 import <nixpkgs> {
100100 crossSystem = (import <nixpkgs/lib>).systems.examples.armhf-embedded // {
101− rustc.arch.config = "thumb-crazy";
102− rustc.arch.custom = { foo = ""; bar = ""; };
101+ rustc.config = "thumb-crazy";
102+ rustc.platform = { foo = ""; bar = ""; };
103103 };
104104 }
105105 will result in:
pkgs/development/compilers/rust/default.nix+3−3
@@ -27,7 +27,7 @@
2727 # Returns the name of the rust target, even if it is custom. Adjustments are
2828 # because rust has slightly different naming conventions than we do.
2929 toRustTarget = platform: with platform.parsed; let
30− cpu_ = platform.rustc.arch or {
30+ cpu_ = platform.rustc.platform.arch or {
3131 "armv7a" = "armv7";
3232 "armv7l" = "armv7";
3333 "armv6l" = "arm";
@@ -38,8 +38,8 @@
3838 # Returns the name of the rust target if it is standard, or the json file
3939 # containing the custom target spec.
4040 toRustTargetSpec = platform:
41− if (platform.rustc.arch or {}) ? custom
42− then builtins.toFile (platform.rustc.config + ".json") (builtins.toJSON platform.rustc.arch.custom)
41+ if (platform.rustc or {}) ? platform
42+ then builtins.toFile (toRustTarget platform + ".json") (builtins.toJSON platform.rustc.platform)
4343 else toRustTarget platform;
4444
4545 # This just contains tools for now. But it would conceivably contain
pkgs/test/rust-sysroot/default.nix+37−23
@@ -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}