Skip to content

Commit 76003cd

Browse files
committed
build: enable wasm builds on powerpc
- Reorganize the flake to better match `enarx` - Introduce an overlay - Add Enarx dependency via overlay Signed-off-by: Roman Volosatovs <[email protected]>
1 parent 97f363d commit 76003cd

File tree

2 files changed

+167
-125
lines changed

2 files changed

+167
-125
lines changed

flake.lock

Lines changed: 61 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 106 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
inputs.crane.inputs.flake-utils.follows = "flake-utils";
66
inputs.crane.inputs.nixpkgs.follows = "nixpkgs";
77
inputs.crane.url = github:ipetkov/crane;
8-
inputs.enarx.url = github:enarx/enarx;
8+
inputs.enarx.url = github:rvolosatovs/enarx/build/crane; # TODO: Remove fork once https://github.com/enarx/enarx/pull/2269 is merged
99
inputs.flake-compat.flake = false;
1010
inputs.flake-compat.url = github:edolstra/flake-compat;
1111
inputs.flake-utils.url = github:numtide/flake-utils;
@@ -23,8 +23,90 @@
2323
rust-overlay,
2424
...
2525
}:
26-
with flake-utils.lib.system;
27-
flake-utils.lib.eachSystem [
26+
with flake-utils.lib.system; let
27+
version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).package.version;
28+
29+
overlay = final: prev: let
30+
src =
31+
final.nix-gitignore.gitignoreRecursiveSource [
32+
"*.nix"
33+
"*.yml"
34+
"/.github"
35+
"flake.lock"
36+
"LICENSE"
37+
"rust-toolchain.toml"
38+
]
39+
./.;
40+
41+
rustToolchain = prev.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
42+
43+
craneLib = (crane.mkLib final).overrideToolchain rustToolchain;
44+
45+
commonArgs = {
46+
inherit
47+
src
48+
version
49+
;
50+
pname = "steward";
51+
};
52+
53+
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
54+
55+
commonArtifactArgs = commonArgs // {inherit cargoArtifacts;};
56+
57+
checks.clippy = craneLib.cargoClippy (commonArtifactArgs // {cargoClippyExtraArgs = "--all-targets --workspace -- --deny warnings";});
58+
checks.fmt = craneLib.cargoFmt commonArtifactArgs;
59+
checks.nextest = craneLib.cargoNextest commonArtifactArgs;
60+
61+
buildPackage = extraArgs:
62+
craneLib.buildPackage (commonArtifactArgs
63+
// {
64+
cargoExtraArgs = "-j $NIX_BUILD_CORES";
65+
}
66+
// extraArgs);
67+
68+
nativeBin = buildPackage {};
69+
aarch64LinuxMuslBin = buildPackage {
70+
CARGO_BUILD_TARGET = "aarch64-unknown-linux-musl";
71+
CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
72+
};
73+
wasm32WasiBin = buildPackage {
74+
nativeBuildInputs = [final.enarx];
75+
76+
CARGO_BUILD_TARGET = "wasm32-wasi";
77+
CARGO_TARGET_WASM_WASI32_RUNNER = "enarx run --wasmcfgfile ${self}/Enarx.toml";
78+
};
79+
x86_64LinuxMuslBin = buildPackage {
80+
CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
81+
CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
82+
};
83+
84+
buildImage = bin:
85+
final.dockerTools.buildImage {
86+
name = "steward";
87+
tag = version;
88+
contents = [
89+
bin
90+
];
91+
config.Cmd = ["steward"];
92+
config.Env = ["PATH=${bin}/bin"];
93+
};
94+
in {
95+
steward = nativeBin;
96+
steward-aarch64-unknown-linux-musl = aarch64LinuxMuslBin;
97+
steward-aarch64-unknown-linux-musl-oci = buildImage aarch64LinuxMuslBin;
98+
steward-wasm32-wasi = wasm32WasiBin;
99+
steward-x86_64-unknown-linux-musl = x86_64LinuxMuslBin;
100+
steward-x86_64-unknown-linux-musl-oci = buildImage x86_64LinuxMuslBin;
101+
102+
stewardChecks = checks;
103+
stewardRustToolchain = rustToolchain;
104+
};
105+
in
106+
{
107+
overlays.default = overlay;
108+
}
109+
// flake-utils.lib.eachSystem [
28110
aarch64-darwin
29111
aarch64-linux
30112
powerpc64le-linux
@@ -34,95 +116,37 @@
34116
system: let
35117
pkgs = import nixpkgs {
36118
inherit system;
37-
overlays = [(import rust-overlay)];
38-
};
39-
40-
# TODO: Add and use an overlay
41-
enarxBin = enarx.packages.${system}.default;
42-
43-
rust = pkgs.rust-bin.fromRustupToolchainFile "${self}/rust-toolchain.toml";
44-
45-
cargo.toml = builtins.fromTOML (builtins.readFile "${self}/Cargo.toml");
46-
src =
47-
pkgs.nix-gitignore.gitignoreRecursiveSource [
48-
"*.nix"
49-
"*.yml"
50-
"/.github"
51-
"flake.lock"
52-
"LICENSE"
53-
"rust-toolchain.toml"
54-
]
55-
self;
56-
57-
craneLib = (crane.mkLib pkgs).overrideToolchain rust;
58-
59-
commonArgs = {
60-
pname = cargo.toml.package.name;
61-
inherit (cargo.toml.package) version;
62-
inherit src;
119+
overlays = [
120+
rust-overlay.overlays.default
121+
enarx.overlays.default
122+
overlay
123+
];
63124
};
64-
65-
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
66-
67-
commonArtifactArgs = commonArgs // {inherit cargoArtifacts;};
68-
69-
cargoClippy = craneLib.cargoClippy (commonArtifactArgs // {cargoClippyExtraArgs = "--all-targets --workspace -- --deny warnings";});
70-
cargoFmt = craneLib.cargoFmt commonArtifactArgs;
71-
cargoNextest = craneLib.cargoNextest commonArtifactArgs;
72-
73-
buildPackage = extraArgs: craneLib.buildPackage (commonArtifactArgs // extraArgs);
74-
nativeBin = buildPackage {};
75-
wasm32WasiBin = buildPackage {
76-
nativeBuildInputs = [enarxBin];
77-
78-
CARGO_BUILD_TARGET = "wasm32-wasi";
79-
CARGO_TARGET_WASM_WASI32_RUNNER = "enarx run --wasmcfgfile ${self}/Enarx.toml";
80-
};
81-
x86_64LinuxMuslBin = buildPackage {
82-
CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
83-
CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
84-
};
85-
86-
buildImage = bin:
87-
pkgs.dockerTools.buildImage {
88-
inherit (cargo.toml.package) name;
89-
tag = cargo.toml.package.version;
90-
contents = [
91-
bin
92-
];
93-
config.Cmd = [cargo.toml.package.name];
94-
config.Env = ["PATH=${bin}/bin"];
95-
};
96125
in {
97126
formatter = pkgs.alejandra;
98127

99-
checks.clippy = cargoClippy;
100-
checks.fmt = cargoFmt;
101-
checks.nextest = cargoNextest;
128+
checks = pkgs.stewardChecks;
102129

103130
packages =
104131
{
105-
default = nativeBin;
106-
107-
"${cargo.toml.package.name}" = nativeBin;
108-
"${cargo.toml.package.name}-x86_64-unknown-linux-musl" = x86_64LinuxMuslBin;
109-
"${cargo.toml.package.name}-x86_64-unknown-linux-musl-oci" = buildImage x86_64LinuxMuslBin;
132+
default = pkgs.steward;
110133
}
111-
# TODO: Remove once an overlay is created in enarx
112-
// (pkgs.lib.optionalAttrs (system != powerpc64le-linux) {
113-
"${cargo.toml.package.name}-wasm32-wasi" = wasm32WasiBin;
114-
});
134+
// pkgs.lib.genAttrs [
135+
"steward"
136+
"steward-aarch64-unknown-linux-musl"
137+
"steward-aarch64-unknown-linux-musl-oci"
138+
"steward-wasm32-wasi"
139+
"steward-x86_64-unknown-linux-musl"
140+
"steward-x86_64-unknown-linux-musl-oci"
141+
] (name: pkgs.${name});
115142

116143
devShells.default = pkgs.mkShell {
117-
buildInputs =
118-
[
119-
pkgs.openssl
120-
pkgs.wasmtime
121-
122-
rust
123-
]
124-
# TODO: Add Enarx, once an overlay is created in enarx
125-
++ (pkgs.lib.optional (system != powerpc64le-linux) enarxBin);
144+
buildInputs = [
145+
pkgs.enarx
146+
pkgs.openssl
147+
pkgs.stewardRustToolchain
148+
pkgs.wasmtime
149+
];
126150
};
127151
}
128152
);

0 commit comments

Comments
 (0)