@@ -203,7 +203,13 @@ impl Default for BuildOptions {
203203 }
204204}
205205
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+ }
207213
208214impl Build {
209215 /// Construct a build command from the given options.
@@ -260,9 +266,10 @@ impl Build {
260266 let process_steps = Build :: get_process_steps ( self . mode , self . no_pack , self . no_opt ) ;
261267
262268 let started = Instant :: now ( ) ;
269+ let mut state = State :: default ( ) ;
263270
264271 for ( _, process_step) in process_steps {
265- process_step ( self ) ?;
272+ process_step ( self , & mut state ) ?;
266273 }
267274
268275 let duration = crate :: command:: utils:: elapsed ( started. elapsed ( ) ) ;
@@ -331,51 +338,48 @@ impl Build {
331338 steps
332339 }
333340
334- fn step_check_rustc_version ( & mut self ) -> Result < ( ) > {
341+ fn step_check_rustc_version ( & mut self , _state : & mut State ) -> Result < ( ) > {
335342 info ! ( "Checking rustc version..." ) ;
336343 let version = build:: check_rustc_version ( ) ?;
337344 let msg = format ! ( "rustc version is {}." , version) ;
338345 info ! ( "{}" , & msg) ;
339346 Ok ( ( ) )
340347 }
341348
342- fn step_check_crate_config ( & mut self ) -> Result < ( ) > {
349+ fn step_check_crate_config ( & mut self , _state : & mut State ) -> Result < ( ) > {
343350 info ! ( "Checking crate configuration..." ) ;
344351 self . crate_data . check_crate_config ( ) ?;
345352 info ! ( "Crate is correctly configured." ) ;
346353 Ok ( ( ) )
347354 }
348355
349- fn step_check_for_wasm_target ( & mut self ) -> Result < ( ) > {
356+ fn step_check_for_wasm_target ( & mut self , _state : & mut State ) -> Result < ( ) > {
350357 info ! ( "Checking for wasm-target..." ) ;
351358 build:: wasm_target:: check_for_wasm32_target ( ) ?;
352359 info ! ( "Checking for wasm-target was successful." ) ;
353360 Ok ( ( ) )
354361 }
355362
356- fn step_build_wasm ( & mut self ) -> Result < ( ) > {
363+ fn step_build_wasm ( & mut self , state : & mut State ) -> Result < ( ) > {
357364 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) ;
359371
360- info ! (
361- "wasm built at {:#?}." ,
362- & self
363- . crate_path
364- . join( "target" )
365- . join( "wasm32-unknown-unknown" )
366- . join( "release" )
367- ) ;
368372 Ok ( ( ) )
369373 }
370374
371- fn step_create_dir ( & mut self ) -> Result < ( ) > {
375+ fn step_create_dir ( & mut self , _state : & mut State ) -> Result < ( ) > {
372376 info ! ( "Creating a pkg directory..." ) ;
373377 create_pkg_dir ( & self . out_dir ) ?;
374378 info ! ( "Created a pkg directory at {:#?}." , & self . crate_path) ;
375379 Ok ( ( ) )
376380 }
377381
378- fn step_create_json ( & mut self ) -> Result < ( ) > {
382+ fn step_create_json ( & mut self , _state : & mut State ) -> Result < ( ) > {
379383 self . crate_data . write_package_json (
380384 & self . out_dir ,
381385 & self . scope ,
@@ -389,21 +393,21 @@ impl Build {
389393 Ok ( ( ) )
390394 }
391395
392- fn step_copy_readme ( & mut self ) -> Result < ( ) > {
396+ fn step_copy_readme ( & mut self , _state : & mut State ) -> Result < ( ) > {
393397 info ! ( "Copying readme from crate..." ) ;
394398 readme:: copy_from_crate ( & self . crate_data , & self . crate_path , & self . out_dir ) ?;
395399 info ! ( "Copied readme from crate to {:#?}." , & self . out_dir) ;
396400 Ok ( ( ) )
397401 }
398402
399- fn step_copy_license ( & mut self ) -> Result < ( ) > {
403+ fn step_copy_license ( & mut self , _state : & mut State ) -> Result < ( ) > {
400404 info ! ( "Copying license from crate..." ) ;
401405 license:: copy_from_crate ( & self . crate_data , & self . crate_path , & self . out_dir ) ?;
402406 info ! ( "Copied license from crate to {:#?}." , & self . out_dir) ;
403407 Ok ( ( ) )
404408 }
405409
406- fn step_install_wasm_bindgen ( & mut self ) -> Result < ( ) > {
410+ fn step_install_wasm_bindgen ( & mut self , _state : & mut State ) -> Result < ( ) > {
407411 info ! ( "Identifying wasm-bindgen dependency..." ) ;
408412 let lockfile = Lockfile :: new ( & self . crate_data ) ?;
409413 let bindgen_version = lockfile. require_wasm_bindgen ( ) ?;
@@ -419,7 +423,7 @@ impl Build {
419423 Ok ( ( ) )
420424 }
421425
422- fn step_run_wasm_bindgen ( & mut self ) -> Result < ( ) > {
426+ fn step_run_wasm_bindgen ( & mut self , state : & mut State ) -> Result < ( ) > {
423427 info ! ( "Building the wasm bindings..." ) ;
424428 bindgen:: wasm_bindgen_build (
425429 & self . crate_data ,
@@ -431,13 +435,16 @@ impl Build {
431435 self . reference_types ,
432436 self . target ,
433437 self . profile ,
434- & self . extra_options ,
438+ state
439+ . cargo_artifact
440+ . as_ref ( )
441+ . expect ( "bindgen ran before cargo build" ) ,
435442 ) ?;
436443 info ! ( "wasm bindings were built at {:#?}." , & self . out_dir) ;
437444 Ok ( ( ) )
438445 }
439446
440- fn step_run_wasm_opt ( & mut self ) -> Result < ( ) > {
447+ fn step_run_wasm_opt ( & mut self , _state : & mut State ) -> Result < ( ) > {
441448 let mut args = match self
442449 . crate_data
443450 . configured_profile ( self . profile )
0 commit comments