32
32
llvmPackages_12 . bintools
33
33
rustc-nightly
34
34
cargo-nightly
35
- xargo
36
35
wasmtime
37
36
rust-bindgen
37
+ python3
38
+ ] ++ pkgs . lib . optional pkgs . stdenv . isDarwin [
39
+ libiconv
38
40
] ;
39
41
40
42
llvmEnv = ''
152
154
rec {
153
155
rts =
154
156
let
155
- # We run this on motoko-rts-tests, to get the union of all
156
- # dependencies
157
- rustDeps = nixpkgs . rustPlatform-nightly . fetchCargoTarball {
157
+ # Build Rust package cargo-vendor-tools
158
+ cargoVendorTools = nixpkgs . rustPlatform . buildRustPackage rec {
159
+ name = "cargo-vendor-tools" ;
160
+ src = ./rts/cargo-vendor-tools ;
161
+ cargoSha256 = "0zi3fiq9sy6c9dv7fd2xc9lan85d16gfax47n6g6f5q5c1zb5r47" ;
162
+ } ;
163
+
164
+ # Path to vendor-rust-std-deps, provided by cargo-vendor-tools
165
+ vendorRustStdDeps = "${ cargoVendorTools } /bin/vendor-rust-std-deps" ;
166
+
167
+ # SHA256 of Rust std deps
168
+ rustStdDepsHash = "0wxx8prh66i19vd5078iky6x5bzs6ppz7c1vbcyx9h4fg0f7pfj6" ;
169
+
170
+ # Vendor directory for Rust std deps
171
+ rustStdDeps = nixpkgs . stdenvNoCC . mkDerivation {
172
+ name = "rustc-std-deps" ;
173
+
174
+ nativeBuildInputs = with nixpkgs ; [
175
+ curl
176
+ ] ;
177
+
178
+ buildCommand = ''
179
+ mkdir $out
180
+ cd $out
181
+ ${ vendorRustStdDeps } ${ nixpkgs . rustc-nightly } .
182
+ '' ;
183
+
184
+ outputHash = rustStdDepsHash ;
185
+ outputHashAlgo = "sha256" ;
186
+ outputHashMode = "recursive" ;
187
+ } ;
188
+
189
+ # Vendor tarball of the RTS
190
+ rtsDeps = nixpkgs . rustPlatform . fetchCargoTarball {
158
191
name = "motoko-rts-deps" ;
159
192
src = subpath ./rts ;
160
193
sourceRoot = "rts/motoko-rts-tests" ;
161
- sha256 = "0jyp3j8n5bj5cy1fd26d7h55zmc4v14qc2w8adxqwmsv5riqz41g " ;
194
+ sha256 = "129gfmn96vm7di903pxirg7zybl83q6nkwiqr3rsy7l1q8667kxx " ;
162
195
copyLockfile = true ;
163
196
} ;
197
+
198
+ # Unpacked RTS deps
199
+ rtsDepsUnpacked = nixpkgs . stdenvNoCC . mkDerivation {
200
+ name = rtsDeps . name + "-unpacked" ;
201
+ buildCommand = ''
202
+ tar xf ${ rtsDeps }
203
+ mv *.tar.gz $out
204
+ '' ;
205
+ } ;
206
+
207
+ # All dependencies needed to build the RTS, including Rust std deps, to
208
+ # allow `cargo -Zbuild-std`. (rust-lang/wg-cargo-std-aware#23)
209
+ allDeps = nixpkgs . stdenvNoCC . mkDerivation {
210
+ name = "merged-rust-deps" ;
211
+
212
+ buildCommand = ''
213
+ mkdir -p $out
214
+ cp -r ${ rtsDepsUnpacked } /* $out/
215
+ cp -r ${ rustStdDeps } /* $out/
216
+ '' ;
217
+ } ;
164
218
in
165
219
166
220
stdenv . mkDerivation {
167
221
name = "moc-rts" ;
168
222
169
223
src = subpath ./rts ;
170
- nativeBuildInputs = [ nixpkgs . makeWrapper nixpkgs . removeReferencesTo ] ;
224
+
225
+ nativeBuildInputs = [ nixpkgs . makeWrapper nixpkgs . removeReferencesTo nixpkgs . cacert ] ;
171
226
172
227
buildInputs = rtsBuildInputs ;
173
228
174
229
preBuild = ''
175
- export XARGO_HOME=$PWD/xargo-home
176
230
export CARGO_HOME=$PWD/cargo-home
177
231
178
- # this replicates logic from nixpkgs’ pkgs/build-support/rust/default.nix
232
+ # This replicates logic from nixpkgs’ pkgs/build-support/rust/default.nix
179
233
mkdir -p $CARGO_HOME
180
- echo "Using vendored sources from ${ rustDeps } "
181
- unpackFile ${ rustDeps }
234
+ echo "Using vendored sources from ${ rtsDeps } "
235
+ unpackFile ${ allDeps }
182
236
cat > $CARGO_HOME/config <<__END__
183
237
[source."crates-io"]
184
238
"replace-with" = "vendored-sources"
185
239
186
240
[source."vendored-sources"]
187
- "directory" = "$(stripHash ${ rustDeps } )"
241
+ "directory" = "$(stripHash ${ allDeps } )"
188
242
__END__
189
243
190
244
${ llvmEnv }
191
245
export TOMMATHSRC=${ nixpkgs . sources . libtommath }
192
246
export MUSLSRC=${ nixpkgs . sources . musl-wasi } /libc-top-half/musl
193
247
export MUSL_WASI_SYSROOT=${ musl-wasi-sysroot }
194
-
195
248
'' ;
196
249
197
250
doCheck = true ;
@@ -206,11 +259,16 @@ rec {
206
259
cp mo-rts-debug.wasm $out/rts
207
260
'' ;
208
261
209
- # This needs to be self-contained. Remove mention of
210
- # nix path in debug message.
262
+ # This needs to be self-contained. Remove mention of nix path in debug
263
+ # message.
211
264
preFixup = ''
212
- remove-references-to -t ${ nixpkgs . rustc-nightly } -t ${ rustDeps } $out/rts/mo-rts.wasm $out/rts/mo-rts-debug.wasm
265
+ remove-references-to \
266
+ -t ${ nixpkgs . rustc-nightly } \
267
+ -t ${ rtsDeps } \
268
+ -t ${ rustStdDeps } \
269
+ $out/rts/mo-rts.wasm $out/rts/mo-rts-debug.wasm
213
270
'' ;
271
+
214
272
allowedRequisites = [ ] ;
215
273
} ;
216
274
@@ -440,7 +498,6 @@ rec {
440
498
441
499
filecheck = nixpkgs . linkFarm "FileCheck"
442
500
[ { name = "bin/FileCheck" ; path = "${ nixpkgs . llvm } /bin/FileCheck" ; } ] ;
443
- inherit ( nixpkgs ) xargo ;
444
501
445
502
# gitMinimal is used by nix/gitSource.nix; building it here warms the nix cache
446
503
inherit ( nixpkgs ) gitMinimal ;
0 commit comments