|
17 | 17 | patchRustPkg = pkg: (pkg.overrideAttrs (oA: { |
18 | 18 | buildCommand = (builtins.replaceStrings |
19 | 19 | [ "rustc,rustdoc" ] |
20 | | - [ "rustc,rustdoc,clippy-driver,cargo-clippy" ] |
| 20 | + [ "rustc,rustdoc,clippy-driver,cargo-clippy,miri,cargo-miri" ] |
21 | 21 | oA.buildCommand) + (let |
22 | 22 | wrapperPath = pkgs.path + "/pkgs/build-support/bintools-wrapper/ld-wrapper.sh"; |
23 | 23 | baseOut = pkgs.clangStdenv.cc.bintools.out; |
|
68 | 68 | "x86_64-pc-windows-msvc" "x86_64-unknown-none" |
69 | 69 | "wasm32-wasip1" "wasm32-wasip2" "wasm32-unknown-unknown" |
70 | 70 | ]; |
71 | | - extensions = [ "rust-src" ]; |
| 71 | + extensions = [ "rust-src" ] ++ (if args.channel == "nightly" then [ "miri-preview" ] else []); |
72 | 72 | }); |
73 | 73 |
|
74 | 74 | # Hyperlight needs a variety of toolchains, since we use Nightly |
|
96 | 96 | rustc = toolchains.stable.rust; |
97 | 97 | }; |
98 | 98 |
|
| 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 | + |
99 | 124 | # Script snippet, used in the cargo/rustc wrappers below, |
100 | 125 | # which creates a number of .cargo/config.toml files in |
101 | 126 | # order to allow using Nix-fetched dependencies (this must |
|
105 | 130 | # unfortunately that tends not to play well with subcommands |
106 | 131 | # like `cargo clippy` and `cargo hyperlight` (see |
107 | 132 | # https://github.com/rust-lang/cargo/issues/11031). |
108 | | - materialiseDeps = deps: let |
| 133 | + materialiseDeps = let |
109 | 134 | sortedNames = lib.lists.reverseList (builtins.attrNames deps); |
110 | 135 | matchClause = path: '' */${path}) root="''${manifest%${path}}" ;;''; |
111 | 136 | matchClauses = lib.strings.concatStringsSep "\n" |
|
144 | 169 | # scripts also use `rustup toolchain install` in some cases, in |
145 | 170 | # order to work in CI, so we provide a fake rustup that does |
146 | 171 | # nothing as well. |
147 | | - rustup-like-wrapper = name: deps: pkgs.writeShellScriptBin name |
| 172 | + rustup-like-wrapper = name: pkgs.writeShellScriptBin name |
148 | 173 | (let |
149 | 174 | clause = name: toolchain: |
150 | 175 | "+${name}) base=\"${toolchain.rust}\"; shift 1; ;;"; |
151 | 176 | clauses = lib.strings.concatStringsSep "\n" |
152 | 177 | (lib.mapAttrsToList clause toolchains); |
153 | 178 | in '' |
154 | 179 | base="${toolchains.stable.rust}" |
155 | | - ${materialiseDeps deps} |
| 180 | + ${materialiseDeps} |
156 | 181 | case "$1" in |
157 | 182 | ${clauses} |
158 | 183 | install) exit 0; ;; |
159 | 184 | esac |
160 | 185 | export PATH="$base/bin:$PATH" |
161 | 186 | exec "$base/bin/${name}" "$@" |
162 | 187 | ''); |
163 | | - fake-rustup = deps: pkgs.symlinkJoin { |
| 188 | + fake-rustup = pkgs.symlinkJoin { |
164 | 189 | name = "fake-rustup"; |
165 | 190 | paths = [ |
166 | 191 | (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") |
169 | 194 | ]; |
170 | 195 | }; |
171 | 196 |
|
|
182 | 207 | }; |
183 | 208 | cargoHash = "sha256-muiMVrK1TydQiMitihfo7xYidqUIIQ+Hw3BIeo5rLFw="; |
184 | 209 | }; |
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 | | - }; |
208 | 210 | in (buildRustPackageClang (mkDerivationAttrs: { |
209 | 211 | pname = "hyperlight"; |
210 | 212 | version = "0.0.0"; |
211 | 213 | src = lib.cleanSource ./.; |
212 | | - cargoLock.lockFile = ./Cargo.lock; |
| 214 | + cargoDeps = deps."Cargo.toml"; |
213 | 215 |
|
214 | 216 | nativeBuildInputs = [ |
215 | 217 | azure-cli |
|
246 | 248 | # Set this through shellHook rather than nativeBuildInputs to be |
247 | 249 | # really sure that it overrides the real cargo. |
248 | 250 | postHook = '' |
249 | | - export PATH="${fake-rustup (deps mkDerivationAttrs.cargoDeps)}/bin:$PATH" |
| 251 | + export PATH="${fake-rustup}/bin:$PATH" |
250 | 252 | ''; |
251 | 253 | })).overrideAttrs(oA: { |
252 | 254 | hardeningDisable = [ "all" ]; |
|
0 commit comments