Skip to content

Commit 4c19b5a

Browse files
committed
[nix] include miri for the nightly toolchain
Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
1 parent 658bb2e commit 4c19b5a

1 file changed

Lines changed: 35 additions & 33 deletions

File tree

flake.nix

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
patchRustPkg = pkg: (pkg.overrideAttrs (oA: {
1818
buildCommand = (builtins.replaceStrings
1919
[ "rustc,rustdoc" ]
20-
[ "rustc,rustdoc,clippy-driver,cargo-clippy" ]
20+
[ "rustc,rustdoc,clippy-driver,cargo-clippy,miri,cargo-miri" ]
2121
oA.buildCommand) + (let
2222
wrapperPath = pkgs.path + "/pkgs/build-support/bintools-wrapper/ld-wrapper.sh";
2323
baseOut = pkgs.clangStdenv.cc.bintools.out;
@@ -68,7 +68,7 @@
6868
"x86_64-pc-windows-msvc" "x86_64-unknown-none"
6969
"wasm32-wasip1" "wasm32-wasip2" "wasm32-unknown-unknown"
7070
];
71-
extensions = [ "rust-src" ];
71+
extensions = [ "rust-src" ] ++ (if args.channel == "nightly" then [ "miri-preview" ] else []);
7272
});
7373

7474
# Hyperlight needs a variety of toolchains, since we use Nightly
@@ -96,6 +96,31 @@
9696
rustc = toolchains.stable.rust;
9797
};
9898

99+
# when building a guest with cargo-hyperlight, or when
100+
# building a miri sysroot for the main workspace, we need to
101+
# include any crates.io dependencies of the standard library
102+
# (e.g. rustc-literal-escaper)
103+
stdlibLocks = lib.mapAttrsToList (_: toolchain:
104+
"${toolchain.rust}/lib/rustlib/src/rust/library/Cargo.lock"
105+
) toolchains;
106+
stdlibDeps = builtins.map (lockFile:
107+
rust-platform.importCargoLock { inherit lockFile; }) stdlibLocks;
108+
withStdlibLock = lockFile:
109+
pkgs.symlinkJoin {
110+
name = "cargo-deps";
111+
paths = stdlibDeps ++ [
112+
(rust-platform.importCargoLock {
113+
inherit lockFile;
114+
})
115+
];
116+
};
117+
deps = {
118+
"Cargo.toml" = withStdlibLock ./Cargo.lock;
119+
"src/tests/rust_guests/dummyguest/Cargo.toml" = withStdlibLock ./src/tests/rust_guests/dummyguest/Cargo.lock;
120+
"src/tests/rust_guests/simpleguest/Cargo.toml" = withStdlibLock ./src/tests/rust_guests/simpleguest/Cargo.lock;
121+
"src/tests/rust_guests/witguest/Cargo.toml" = withStdlibLock ./src/tests/rust_guests/witguest/Cargo.lock;
122+
};
123+
99124
# Script snippet, used in the cargo/rustc wrappers below,
100125
# which creates a number of .cargo/config.toml files in
101126
# order to allow using Nix-fetched dependencies (this must
@@ -105,7 +130,7 @@
105130
# unfortunately that tends not to play well with subcommands
106131
# like `cargo clippy` and `cargo hyperlight` (see
107132
# https://github.com/rust-lang/cargo/issues/11031).
108-
materialiseDeps = deps: let
133+
materialiseDeps = let
109134
sortedNames = lib.lists.reverseList (builtins.attrNames deps);
110135
matchClause = path: '' */${path}) root="''${manifest%${path}}" ;;'';
111136
matchClauses = lib.strings.concatStringsSep "\n"
@@ -144,28 +169,28 @@
144169
# scripts also use `rustup toolchain install` in some cases, in
145170
# order to work in CI, so we provide a fake rustup that does
146171
# nothing as well.
147-
rustup-like-wrapper = name: deps: pkgs.writeShellScriptBin name
172+
rustup-like-wrapper = name: pkgs.writeShellScriptBin name
148173
(let
149174
clause = name: toolchain:
150175
"+${name}) base=\"${toolchain.rust}\"; shift 1; ;;";
151176
clauses = lib.strings.concatStringsSep "\n"
152177
(lib.mapAttrsToList clause toolchains);
153178
in ''
154179
base="${toolchains.stable.rust}"
155-
${materialiseDeps deps}
180+
${materialiseDeps}
156181
case "$1" in
157182
${clauses}
158183
install) exit 0; ;;
159184
esac
160185
export PATH="$base/bin:$PATH"
161186
exec "$base/bin/${name}" "$@"
162187
'');
163-
fake-rustup = deps: pkgs.symlinkJoin {
188+
fake-rustup = pkgs.symlinkJoin {
164189
name = "fake-rustup";
165190
paths = [
166191
(pkgs.writeShellScriptBin "rustup" "")
167-
(rustup-like-wrapper "rustc" deps)
168-
(rustup-like-wrapper "cargo" deps)
192+
(rustup-like-wrapper "rustc")
193+
(rustup-like-wrapper "cargo")
169194
];
170195
};
171196

@@ -182,34 +207,11 @@
182207
};
183208
cargoHash = "sha256-muiMVrK1TydQiMitihfo7xYidqUIIQ+Hw3BIeo5rLFw=";
184209
};
185-
# when building a guest with cargo-hyperlight, we need to
186-
# include any crates.io dependencies of the standard library
187-
# (e.g. rustc-literal-escaper)
188-
stdlibLocks = lib.mapAttrsToList (_: toolchain:
189-
"${toolchain.rust}/lib/rustlib/src/rust/library/Cargo.lock"
190-
) toolchains;
191-
stdlibDeps = builtins.map (lockFile:
192-
rust-platform.importCargoLock { inherit lockFile; }) stdlibLocks;
193-
withStdlibLock = lockFile:
194-
pkgs.symlinkJoin {
195-
name = "cargo-deps";
196-
paths = stdlibDeps ++ [
197-
(rust-platform.importCargoLock {
198-
inherit lockFile;
199-
})
200-
];
201-
};
202-
deps = finalRootVendor: {
203-
"Cargo.toml" = finalRootVendor;
204-
"src/tests/rust_guests/dummyguest/Cargo.toml" = withStdlibLock ./src/tests/rust_guests/dummyguest/Cargo.lock;
205-
"src/tests/rust_guests/simpleguest/Cargo.toml" = withStdlibLock ./src/tests/rust_guests/simpleguest/Cargo.lock;
206-
"src/tests/rust_guests/witguest/Cargo.toml" = withStdlibLock ./src/tests/rust_guests/witguest/Cargo.lock;
207-
};
208210
in (buildRustPackageClang (mkDerivationAttrs: {
209211
pname = "hyperlight";
210212
version = "0.0.0";
211213
src = lib.cleanSource ./.;
212-
cargoLock.lockFile = ./Cargo.lock;
214+
cargoDeps = deps."Cargo.toml";
213215

214216
nativeBuildInputs = [
215217
azure-cli
@@ -246,7 +248,7 @@
246248
# Set this through shellHook rather than nativeBuildInputs to be
247249
# really sure that it overrides the real cargo.
248250
postHook = ''
249-
export PATH="${fake-rustup (deps mkDerivationAttrs.cargoDeps)}/bin:$PATH"
251+
export PATH="${fake-rustup}/bin:$PATH"
250252
'';
251253
})).overrideAttrs(oA: {
252254
hardeningDisable = [ "all" ];

0 commit comments

Comments
 (0)