@@ -203,7 +203,13 @@ impl Default for BuildOptions {
203
203
}
204
204
}
205
205
206
- type BuildStep = fn ( & mut Build ) -> Result < ( ) > ;
206
+ type BuildStep = fn ( & mut Build , _state : & mut State ) -> Result < ( ) > ;
207
+
208
+ #[ derive( Default ) ]
209
+ struct State {
210
+ // step state
211
+ cargo_artifact : Option < PathBuf > ,
212
+ }
207
213
208
214
impl Build {
209
215
/// Construct a build command from the given options.
@@ -260,9 +266,10 @@ impl Build {
260
266
let process_steps = Build :: get_process_steps ( self . mode , self . no_pack , self . no_opt ) ;
261
267
262
268
let started = Instant :: now ( ) ;
269
+ let mut state = State :: default ( ) ;
263
270
264
271
for ( _, process_step) in process_steps {
265
- process_step ( self ) ?;
272
+ process_step ( self , & mut state ) ?;
266
273
}
267
274
268
275
let duration = crate :: command:: utils:: elapsed ( started. elapsed ( ) ) ;
@@ -331,51 +338,48 @@ impl Build {
331
338
steps
332
339
}
333
340
334
- fn step_check_rustc_version ( & mut self ) -> Result < ( ) > {
341
+ fn step_check_rustc_version ( & mut self , _state : & mut State ) -> Result < ( ) > {
335
342
info ! ( "Checking rustc version..." ) ;
336
343
let version = build:: check_rustc_version ( ) ?;
337
344
let msg = format ! ( "rustc version is {}." , version) ;
338
345
info ! ( "{}" , & msg) ;
339
346
Ok ( ( ) )
340
347
}
341
348
342
- fn step_check_crate_config ( & mut self ) -> Result < ( ) > {
349
+ fn step_check_crate_config ( & mut self , _state : & mut State ) -> Result < ( ) > {
343
350
info ! ( "Checking crate configuration..." ) ;
344
351
self . crate_data . check_crate_config ( ) ?;
345
352
info ! ( "Crate is correctly configured." ) ;
346
353
Ok ( ( ) )
347
354
}
348
355
349
- fn step_check_for_wasm_target ( & mut self ) -> Result < ( ) > {
356
+ fn step_check_for_wasm_target ( & mut self , _state : & mut State ) -> Result < ( ) > {
350
357
info ! ( "Checking for wasm-target..." ) ;
351
358
build:: wasm_target:: check_for_wasm32_target ( ) ?;
352
359
info ! ( "Checking for wasm-target was successful." ) ;
353
360
Ok ( ( ) )
354
361
}
355
362
356
- fn step_build_wasm ( & mut self ) -> Result < ( ) > {
363
+ fn step_build_wasm ( & mut self , state : & mut State ) -> Result < ( ) > {
357
364
info ! ( "Building wasm..." ) ;
358
- build:: cargo_build_wasm ( & self . crate_path , self . profile , & self . extra_options ) ?;
365
+ let cargo_artifact =
366
+ build:: cargo_build_wasm ( & self . crate_path , self . profile , & self . extra_options ) ?;
367
+
368
+ info ! ( "wasm built at {:#?}." , cargo_artifact) ;
369
+
370
+ state. cargo_artifact = Some ( cargo_artifact) ;
359
371
360
- info ! (
361
- "wasm built at {:#?}." ,
362
- & self
363
- . crate_path
364
- . join( "target" )
365
- . join( "wasm32-unknown-unknown" )
366
- . join( "release" )
367
- ) ;
368
372
Ok ( ( ) )
369
373
}
370
374
371
- fn step_create_dir ( & mut self ) -> Result < ( ) > {
375
+ fn step_create_dir ( & mut self , _state : & mut State ) -> Result < ( ) > {
372
376
info ! ( "Creating a pkg directory..." ) ;
373
377
create_pkg_dir ( & self . out_dir ) ?;
374
378
info ! ( "Created a pkg directory at {:#?}." , & self . crate_path) ;
375
379
Ok ( ( ) )
376
380
}
377
381
378
- fn step_create_json ( & mut self ) -> Result < ( ) > {
382
+ fn step_create_json ( & mut self , _state : & mut State ) -> Result < ( ) > {
379
383
self . crate_data . write_package_json (
380
384
& self . out_dir ,
381
385
& self . scope ,
@@ -389,21 +393,21 @@ impl Build {
389
393
Ok ( ( ) )
390
394
}
391
395
392
- fn step_copy_readme ( & mut self ) -> Result < ( ) > {
396
+ fn step_copy_readme ( & mut self , _state : & mut State ) -> Result < ( ) > {
393
397
info ! ( "Copying readme from crate..." ) ;
394
398
readme:: copy_from_crate ( & self . crate_data , & self . crate_path , & self . out_dir ) ?;
395
399
info ! ( "Copied readme from crate to {:#?}." , & self . out_dir) ;
396
400
Ok ( ( ) )
397
401
}
398
402
399
- fn step_copy_license ( & mut self ) -> Result < ( ) > {
403
+ fn step_copy_license ( & mut self , _state : & mut State ) -> Result < ( ) > {
400
404
info ! ( "Copying license from crate..." ) ;
401
405
license:: copy_from_crate ( & self . crate_data , & self . crate_path , & self . out_dir ) ?;
402
406
info ! ( "Copied license from crate to {:#?}." , & self . out_dir) ;
403
407
Ok ( ( ) )
404
408
}
405
409
406
- fn step_install_wasm_bindgen ( & mut self ) -> Result < ( ) > {
410
+ fn step_install_wasm_bindgen ( & mut self , _state : & mut State ) -> Result < ( ) > {
407
411
info ! ( "Identifying wasm-bindgen dependency..." ) ;
408
412
let lockfile = Lockfile :: new ( & self . crate_data ) ?;
409
413
let bindgen_version = lockfile. require_wasm_bindgen ( ) ?;
@@ -419,7 +423,7 @@ impl Build {
419
423
Ok ( ( ) )
420
424
}
421
425
422
- fn step_run_wasm_bindgen ( & mut self ) -> Result < ( ) > {
426
+ fn step_run_wasm_bindgen ( & mut self , state : & mut State ) -> Result < ( ) > {
423
427
info ! ( "Building the wasm bindings..." ) ;
424
428
bindgen:: wasm_bindgen_build (
425
429
& self . crate_data ,
@@ -431,13 +435,16 @@ impl Build {
431
435
self . reference_types ,
432
436
self . target ,
433
437
self . profile ,
434
- & self . extra_options ,
438
+ state
439
+ . cargo_artifact
440
+ . as_ref ( )
441
+ . expect ( "bindgen ran before cargo build" ) ,
435
442
) ?;
436
443
info ! ( "wasm bindings were built at {:#?}." , & self . out_dir) ;
437
444
Ok ( ( ) )
438
445
}
439
446
440
- fn step_run_wasm_opt ( & mut self ) -> Result < ( ) > {
447
+ fn step_run_wasm_opt ( & mut self , _state : & mut State ) -> Result < ( ) > {
441
448
let mut args = match self
442
449
. crate_data
443
450
. configured_profile ( self . profile )
0 commit comments