|
109 | 109 | rustc = toolchains.stable.rust; |
110 | 110 | }; |
111 | 111 |
|
| 112 | + manifests = [ |
| 113 | + "Cargo.toml" |
| 114 | + "src/tests/rust_guests/dummyguest/Cargo.toml" |
| 115 | + "src/tests/rust_guests/simpleguest/Cargo.toml" |
| 116 | + "src/tests/rust_guests/witguest/Cargo.toml" |
| 117 | + ]; |
| 118 | + manifestDeps = builtins.map (manifest: |
| 119 | + let lockPath = builtins.replaceStrings [ "toml" ] [ "lock" ] manifest; in |
| 120 | + let lockFile = ./${lockPath}; in |
| 121 | + rust-platform.importCargoLock { inherit lockFile; }) manifests; |
112 | 122 | # when building a guest with cargo-hyperlight, or when |
113 | 123 | # building a miri sysroot for the main workspace, we need to |
114 | 124 | # include any crates.io dependencies of the standard library |
|
118 | 128 | ) toolchains; |
119 | 129 | stdlibDeps = builtins.map (lockFile: |
120 | 130 | rust-platform.importCargoLock { inherit lockFile; }) stdlibLocks; |
121 | | - withStdlibLock = lockFile: |
122 | | - pkgs.symlinkJoin { |
123 | | - name = "cargo-deps"; |
124 | | - paths = stdlibDeps ++ [ |
125 | | - (rust-platform.importCargoLock { |
126 | | - inherit lockFile; |
127 | | - }) |
128 | | - ]; |
129 | | - }; |
130 | | - deps = { |
131 | | - "Cargo.toml" = withStdlibLock ./Cargo.lock; |
132 | | - "src/tests/rust_guests/dummyguest/Cargo.toml" = withStdlibLock ./src/tests/rust_guests/dummyguest/Cargo.lock; |
133 | | - "src/tests/rust_guests/simpleguest/Cargo.toml" = withStdlibLock ./src/tests/rust_guests/simpleguest/Cargo.lock; |
134 | | - "src/tests/rust_guests/witguest/Cargo.toml" = withStdlibLock ./src/tests/rust_guests/witguest/Cargo.lock; |
| 131 | + deps = pkgs.symlinkJoin { |
| 132 | + name = "cargo-deps"; |
| 133 | + paths = stdlibDeps ++ manifestDeps; |
135 | 134 | }; |
136 | 135 |
|
137 | 136 | # Script snippet, used in the cargo/rustc wrappers below, |
|
144 | 143 | # like `cargo clippy` and `cargo hyperlight` (see |
145 | 144 | # https://github.com/rust-lang/cargo/issues/11031). |
146 | 145 | materialiseDeps = let |
147 | | - sortedNames = lib.lists.reverseList (builtins.attrNames deps); |
| 146 | + sortedManifests = lib.lists.sort (p: q: p > q) manifests; |
148 | 147 | matchClause = path: '' */${path}) root="''${manifest%${path}}" ;;''; |
149 | 148 | matchClauses = lib.strings.concatStringsSep "\n" |
150 | | - (builtins.map matchClause sortedNames); |
151 | | - makeClause = manifest: vendor: let |
152 | | - dir = builtins.dirOf manifest; |
153 | | - gitExclude = builtins.toString (/. + "${dir}/.cargo"); |
154 | | - in '' |
155 | | - mkdir -p $root/${dir}/.cargo |
156 | | - cat >$root/${dir}/.cargo/config.toml <<EOF |
157 | | - [source.crates-io] |
158 | | - replace-with = "vendored-sources" |
159 | | -
|
160 | | - [source.vendored-sources] |
161 | | - directory = "${vendor}" |
162 | | - EOF |
163 | | - printf "# vendor dependency configuration generated by nix\n%s\n" "${gitExclude}" >> $root/.git/info/exclude |
164 | | - ''; |
165 | | - makeClauses = lib.strings.concatStringsSep "\n" |
166 | | - (lib.mapAttrsToList makeClause deps); |
| 149 | + (builtins.map matchClause sortedManifests); |
167 | 150 | in '' |
168 | 151 | base_cargo() { |
169 | 152 | PATH="$base/bin:$PATH" "$base/bin/cargo" "$@" |
|
174 | 157 | ${matchClauses} |
175 | 158 | esac |
176 | 159 | if [ -f ''${root}/flake.nix ]; then |
| 160 | +
|
| 161 | + mkdir -p $root/$.cargo |
| 162 | + cat >$root/.cargo/config.toml <<EOF |
| 163 | + [source.crates-io] |
| 164 | + replace-with = "vendored-sources" |
| 165 | +
|
| 166 | + [source.vendored-sources] |
| 167 | + directory = "${deps}" |
| 168 | + EOF |
| 169 | +
|
177 | 170 | sed -i '/# vendor dependency configuration generated by nix/{N;d;}' $root/.git/info/exclude |
178 | | - ${makeClauses} |
| 171 | + printf "# vendor dependency configuration generated by nix\n%s\n" "/.cargo" >> $root/.git/info/exclude |
179 | 172 | fi |
180 | 173 |
|
181 | 174 | # libgit2-sys copies a vendored git2 into the target/ |
|
238 | 231 | pname = "hyperlight"; |
239 | 232 | version = "0.0.0"; |
240 | 233 | src = lib.cleanSource ./.; |
241 | | - cargoDeps = deps."Cargo.toml"; |
| 234 | + cargoDeps = deps; |
242 | 235 |
|
243 | 236 | nativeBuildInputs = [ |
244 | 237 | azure-cli |
|
0 commit comments