-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathdefault.nix
128 lines (116 loc) · 3.21 KB
/
default.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
{ pkgs ? (
let
nixpkgs = import <nixpkgs>;
pkgs_ = (nixpkgs {});
rustOverlay = (pkgs_.fetchFromGitHub {
owner = "mozilla";
repo = "nixpkgs-mozilla";
rev = "d7ba4e48037c0f944d01d7902fcdc8fa0766df24";
sha256 = "033zk1pfnwh0ryrm1yzl9ybgqyhypgdxv1249a8z7cdy1rvb9zz4";
});
in (nixpkgs {
overlays = [
(import (builtins.toPath "${rustOverlay}/rust-overlay.nix"))
(self: super:
with super;
let nightly = lib.rustLib.fromManifest (lib.rustLib.manifest_v2_url {
channel = "nightly";
date = "2018-05-17";
}) {
inherit (self) stdenv fetchurl patchelf;
};
rustc_ = nightly.rustc;
cargo_ = nightly.cargo;
rust-src_ = nightly.rust-src;
rust_ = nightly.rust;
in {
rust = {
rustc = rustc_;
cargo = cargo_;
rust-src = rust-src_;
rust = rust_;
};
})
];
}))
}:
with pkgs;
let
x86_64-target-spec = stdenv.mkDerivation {
name = "target-spec";
src = ./x86_64.json;
phases = [ "buildPhase" ];
buildPhase = ''
mkdir -p $out
cp $src $out/x86_64.json
'';
};
libcore = stdenv.mkDerivation {
name = "libcore";
buildInputs = [
rust.rustc
];
phases = [ "buildPhase" ];
buildPhase = ''
mkdir -p $out
rustc --target=${x86_64-target-spec}/x86_64.json --out-dir=$out --crate-name=core --crate-type=lib ${rust.rust-src}/lib/rustlib/src/rust/src/libcore/lib.rs
'';
};
libcompiler_builtins = stdenv.mkDerivation {
name = "libcompiler_builtins";
buildInputs = [
rust.rustc
];
phases = [ "buildPhase" ];
buildPhase = ''
mkdir -p $out
rustc -L ${libcore} --cfg 'feature="compiler-builtins"' --target=${x86_64-target-spec}/x86_64.json --out-dir=$out --crate-name=compiler_builtins --crate-type=lib ${rust.rust-src}/lib/rustlib/src/rust/src/libcompiler_builtins/src/lib.rs
'';
};
liballoc = stdenv.mkDerivation {
name = "liballoc";
buildInputs = [
rust.rustc
];
phases = [ "buildPhase" ];
buildPhase = ''
mkdir -p $out
rustc -L ${libcore} -L ${libcompiler_builtins} --target=${x86_64-target-spec}/x86_64.json --out-dir=$out --crate-name=alloc --crate-type=lib ${rust.rust-src}/lib/rustlib/src/rust/src/liballoc/lib.rs
'';
};
triple = "x86_64-none-elf";
userspace-linker = stdenv.mkDerivation {
name = "userspace-linker";
phases = [ "buildPhase" ];
buildPhase = ''
mkdir -p $out
cat <<EOT > $out/linker.ld
ENTRY(start)
OUTPUT_FORMAT(elf64-x86-64)
EOT
'';
};
in stdenv.mkDerivation {
name = "rux-env";
buildInputs = [
gnumake
(binutils-unwrapped.override { targetPlatform = { config = triple; isiOS = false; isAarch64 = false; }; })
qemu
file
gdb
rust.rust
rust.cargo
curl
];
ARCH = "x86_64";
RUST_SRC = "${rust.rust-src}";
TARGET_SPEC = "${x86_64-target-spec}/x86_64.json";
USERSPACE_LINKER = "${userspace-linker}/linker.ld";
LIBCORE = "${libcore}";
LIBCOMPILER_BUILTINS = "${libcompiler_builtins}";
LIBALLOC = "${liballoc}";
LD = "${triple}-ld";
AS = "${triple}-as";
OBJDUMP = "${triple}-objdump";
OBJCOPY = "${triple}-objcopy";
}