Skip to content

Commit 1ff5324

Browse files
committed
wip (moderate rework)
1 parent f50e3eb commit 1ff5324

File tree

8 files changed

+121
-49
lines changed

8 files changed

+121
-49
lines changed

default.nix

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,27 @@ let
1616
if str == "" then [ ] else builtins.filter (elm: builtins.isString elm) (builtins.split split str);
1717
sanitizers = split-str ",+" sanitize;
1818
sources = import ./npins;
19-
target = import ./nix/target.nix {
19+
platform' = import ./nix/platforms.nix {
2020
inherit lib platform libc;
2121
};
2222
profile = import ./nix/profiles.nix {
2323
inherit prof sanitizers instrumentation;
24-
arch = target.platform.arch;
24+
arch = platform'.arch;
2525
};
2626
overlays = import ./nix/overlays {
2727
inherit
2828
sources
2929
sanitizers
30-
target
3130
profile
3231
;
32+
platform = platform';
3333
};
3434
pkgs =
3535
(import sources.nixpkgs {
3636
overlays = [
3737
overlays.${overlay}
3838
];
39-
}).pkgsCross.${target.info.nixarch};
39+
}).pkgsCross.${platform'.info.nixarch};
4040
sysroot = pkgs.symlinkJoin {
4141
name = "sysroot";
4242
paths = with pkgs; [
@@ -84,11 +84,11 @@ let
8484
in
8585
{
8686
inherit
87+
dev-tools
8788
pkgs
88-
sources
8989
profile
90-
target
90+
sources
9191
sysroot
92-
dev-tools
9392
;
93+
platform = platform';
9494
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"channel": "1.92.0",
3+
"hash": {
4+
"md5": "5925de5268fdcb9c70be7fa06de5583d",
5+
"sha1": "aace35bc46aa55685f1e19c34d644f3d49b057c6",
6+
"sha256": "b2a49624353173ecdacf59c158c00929300606e1963f6e4609fb483a508402d0",
7+
"sha512": "0a8fc59360a5e6f3236d9a35ce2c8e0ba184e8be9b5a918f9bc7aae3e5cc1f8133eaa01fd044fdc6ba645805a98aa645e343fbb7b15a850ea0e83ff20d42ebaa"
8+
},
9+
"url": "https://static.rust-lang.org/dist/channel-rust-1.92.0.toml"
10+
}

nix/overlays/dataplane.nix

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
sources,
55
sanitizers,
6-
target,
6+
platform,
77
profile,
88
}:
99
final: prev:
@@ -17,7 +17,7 @@ let
1717
adapt = final.stdenvAdapters;
1818
bintools = final.pkgsBuildHost.llvmPackages.bintools;
1919
lld = final.pkgsBuildHost.llvmPackages.lld;
20-
added-to-env = helpers.addToEnv target.platform.override.stdenv.env profile;
20+
added-to-env = helpers.addToEnv platform.override.stdenv.env profile;
2121
stdenv' = adapt.addAttrsToDerivation (orig: {
2222
doCheck = false;
2323
separateDebugInfo = true;
@@ -28,6 +28,11 @@ let
2828
];
2929
}) final.llvmPackages.stdenv;
3030
dataplane-dep = pkg: pkg.override { stdenv = stdenv'; };
31+
fenix = import sources.fenix { };
32+
rust-toolchain = fenix.fromToolchainFile {
33+
file = ../../rust-toolchain.toml;
34+
sha256 = (builtins.fromJSON (builtins.readFile ../.rust-toolchain.manifest-lock.json)).hash.sha256;
35+
};
3136
in
3237
{
3338
inherit stdenv' added-to-env;
@@ -219,9 +224,7 @@ in
219224
# Also, while this library has a respectable security track record, this is also a super strong candidate for
220225
# cfi, safe-stack, and cf-protection.
221226
dpdk = dataplane-dep (
222-
final.callPackage ../pkgs/dpdk (
223-
target.platform.override.dpdk.buildInputs // { src = sources.dpdk; }
224-
)
227+
final.callPackage ../pkgs/dpdk (platform.override.dpdk.buildInputs // { src = sources.dpdk; })
225228
);
226229

227230
# DPDK is largely composed of static-inline functions.
@@ -230,4 +233,10 @@ in
230233
# This wrapping process does not really cause any performance issue due to lto; the compiler is going to "unwrap"
231234
# these methods anyway.
232235
dpdk-wrapper = dataplane-dep (final.callPackage ../pkgs/dpdk-wrapper { });
236+
237+
# TODO: doc this
238+
rustPlatform = final.makeRustPlatform {
239+
cargo = rust-toolchain;
240+
rustc = rust-toolchain;
241+
};
233242
}

nix/overlays/default.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
{
44
sources,
55
sanitizers,
6-
target,
6+
platform,
77
profile,
88
}:
99
{
1010
dataplane = import ./dataplane.nix {
1111
inherit
1212
sources
1313
sanitizers
14-
target
14+
platform
1515
profile
1616
;
1717
};

nix/target.nix renamed to nix/platforms.nix

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -86,42 +86,45 @@ let
8686
};
8787
};
8888
in
89-
lib.fix (final: {
90-
platform = platforms.${platform};
91-
info =
92-
{
93-
x86_64 = {
94-
linux = {
95-
gnu = {
96-
target = "x86_64-unknown-linux-gnu";
97-
machine = "x86_64";
98-
nixarch = "gnu64";
99-
libc = "gnu";
100-
};
101-
musl = {
102-
target = "x86_64-unknown-linux-musl";
103-
machine = "x86_64";
104-
nixarch = "musl64";
105-
libc = "musl";
89+
lib.fix (
90+
final:
91+
platforms.${platform}
92+
// {
93+
info =
94+
{
95+
x86_64 = {
96+
linux = {
97+
gnu = {
98+
target = "x86_64-unknown-linux-gnu";
99+
machine = "x86_64";
100+
nixarch = "gnu64";
101+
libc = "gnu";
102+
};
103+
musl = {
104+
target = "x86_64-unknown-linux-musl";
105+
machine = "x86_64";
106+
nixarch = "musl64";
107+
libc = "musl";
108+
};
106109
};
107110
};
108-
};
109-
aarch64 = {
110-
linux = {
111-
gnu = {
112-
target = "aarch64-unknown-linux-gnu";
113-
machine = "aarch64";
114-
nixarch = "aarch64-multiplatform";
115-
libc = "gnu";
116-
};
117-
musl = {
118-
target = "aarch64-unknown-linux-musl";
119-
machine = "aarch64";
120-
nixarch = "aarch64-multiplatform-musl";
121-
libc = "musl";
111+
aarch64 = {
112+
linux = {
113+
gnu = {
114+
target = "aarch64-unknown-linux-gnu";
115+
machine = "aarch64";
116+
nixarch = "aarch64-multiplatform";
117+
libc = "gnu";
118+
};
119+
musl = {
120+
target = "aarch64-unknown-linux-musl";
121+
machine = "aarch64";
122+
nixarch = "aarch64-multiplatform-musl";
123+
libc = "musl";
124+
};
122125
};
123126
};
124-
};
125-
}
126-
.${final.platform.arch}.${kernel}.${libc};
127-
})
127+
}
128+
.${final.arch}.${kernel}.${libc};
129+
}
130+
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
let
2+
rust-toolchain = (builtins.fromTOML (builtins.readFile ../rust-toolchain.toml)).toolchain;
3+
channel = rust-toolchain.channel;
4+
url = "https://static.rust-lang.org/dist/channel-rust-${channel}.toml";
5+
manifest-path = builtins.fetchurl {
6+
inherit url;
7+
name = "manifest.toml";
8+
};
9+
hash = {
10+
md5 = builtins.hashFile "md5" manifest-path;
11+
sha1 = builtins.hashFile "sha1" manifest-path;
12+
sha256 = builtins.hashFile "sha256" manifest-path;
13+
sha512 = builtins.hashFile "sha512" manifest-path;
14+
};
15+
in
16+
{
17+
inherit channel url hash;
18+
}

npins/sources.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
"url": "https://github.com/DPDK/dpdk/archive/ed957165eadbe60a47d5ec223578cdd1c13d0bd9.tar.gz",
1414
"hash": "09h7wnmq4c9xm1nsyv5mz1yf91c1l6vy9sdcamb09qjjx4wgs0q9"
1515
},
16+
"fenix": {
17+
"type": "Tarball",
18+
"url": "https://github.com/nix-community/fenix/archive/main.tar.gz",
19+
"hash": "1gkd9ppvsxl4jjg1jyw61wm99xhy4hdqx5dxqj06gfxi2zkamvzf"
20+
},
1621
"nixpkgs": {
1722
"type": "Channel",
1823
"name": "nixpkgs-unstable",

rust-toolchain.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[toolchain]
2+
# NOTE: you can and should manually update this on new rust releases
3+
4+
channel = "1.92.0"
5+
components = [
6+
"rustc",
7+
"cargo",
8+
"rust-std",
9+
"rust-docs",
10+
"rustfmt-preview",
11+
"clippy-preview",
12+
"rust-analyzer-preview",
13+
"rust-src",
14+
15+
# disabled components
16+
# "rust-mingw",
17+
# "llvm-tools-preview", ## we already have a full llvm in the npins
18+
# "rust-analysis", ## obsolete
19+
# "miri-preview", ## not yet functional for us
20+
# "rustc-codegen-cranelift-preview" ## not relevant to us
21+
]
22+
targets = [
23+
"x86_64-unknown-linux-gnu",
24+
"x86_64-unknown-linux-musl",
25+
"aarch64-unknown-linux-gnu",
26+
"aarch64-unknown-linux-musl"
27+
]

0 commit comments

Comments
 (0)