@@ -7,11 +7,14 @@ mod wasm_opt;
7
7
8
8
pub use output:: RustAppOutput ;
9
9
10
- use super :: { Attrs , TrunkAssetPipelineOutput , ATTR_HREF , SNIPPETS_DIR } ;
11
- use crate :: pipelines:: rust:: sri:: { SriBuilder , SriOptions , SriType } ;
10
+ use super :: { data_target_path, Attrs , TrunkAssetPipelineOutput , ATTR_HREF , SNIPPETS_DIR } ;
12
11
use crate :: {
13
- common:: { self , check_target_not_found_err, copy_dir_recursive, path_exists} ,
12
+ common:: {
13
+ self , apply_data_target_path, check_target_not_found_err, copy_dir_recursive, path_exists,
14
+ target_path,
15
+ } ,
14
16
config:: { CargoMetadata , CrossOrigin , Features , RtcBuild } ,
17
+ pipelines:: rust:: sri:: { SriBuilder , SriOptions , SriType } ,
15
18
processing:: {
16
19
integrity:: { IntegrityType , OutputDigest } ,
17
20
minify:: minify_js,
@@ -46,7 +49,7 @@ pub struct RustApp {
46
49
cfg : Arc < RtcBuild > ,
47
50
/// The configuration of the features passed to cargo.
48
51
cargo_features : Features ,
49
- /// Is this module main or a worker.
52
+ /// Is this module main or a worker?
50
53
app_type : RustAppType ,
51
54
/// All metadata associated with the target Cargo project.
52
55
manifest : CargoMetadata ,
@@ -57,6 +60,8 @@ pub struct RustApp {
57
60
bin : Option < String > ,
58
61
/// An optional filter for finding the target artifact.
59
62
target_name : Option < String > ,
63
+ /// Optional target path inside the dist dir.
64
+ target_path : Option < PathBuf > ,
60
65
/// An option to instruct wasm-bindgen to preserve debug info in the final WASM output, even
61
66
/// for `--release` mode.
62
67
keep_debug : bool ,
@@ -231,6 +236,8 @@ impl RustApp {
231
236
}
232
237
} ) ;
233
238
239
+ let target_path = data_target_path ( & attrs) ?;
240
+
234
241
// done
235
242
236
243
Ok ( Self {
@@ -256,6 +263,7 @@ impl RustApp {
256
263
import_bindings,
257
264
import_bindings_name,
258
265
initializer,
266
+ target_path,
259
267
} )
260
268
}
261
269
@@ -302,6 +310,7 @@ impl RustApp {
302
310
import_bindings : true ,
303
311
import_bindings_name : None ,
304
312
initializer : None ,
313
+ target_path : None ,
305
314
} ) )
306
315
}
307
316
@@ -330,7 +339,7 @@ impl RustApp {
330
339
// evaluate wasm integrity after all processing
331
340
self . final_digest ( & mut output)
332
341
. await
333
- . context ( "finalizing digest" ) ?;
342
+ . with_context ( || format ! ( "finalizing digest for '{}'" , output . wasm_output ) ) ?;
334
343
335
344
// now the build is complete
336
345
tracing:: debug!( "rust build complete" ) ;
@@ -513,6 +522,10 @@ impl RustApp {
513
522
args. push ( "--no-typescript" ) ;
514
523
}
515
524
525
+ // the final base
526
+ let target_path =
527
+ target_path ( & self . cfg . staging_dist , self . target_path . as_deref ( ) , None ) . await ?;
528
+
516
529
// Invoke wasm-bindgen.
517
530
tracing:: debug!( "calling wasm-bindgen for {}" , self . name) ;
518
531
common:: run_command ( wasm_bindgen_name, & wasm_bindgen, & args)
@@ -522,22 +535,25 @@ impl RustApp {
522
535
// Copy the generated WASM & JS loader to the dist dir.
523
536
tracing:: debug!( "copying generated wasm-bindgen artifacts" ) ;
524
537
let hashed_name = self . hashed_wasm_base ( wasm_path) . await ?;
525
- let hashed_wasm_name = format ! ( "{hashed_name}_bg.wasm" ) ;
538
+ let hashed_wasm_name =
539
+ apply_data_target_path ( format ! ( "{hashed_name}_bg.wasm" ) , & self . target_path ) ;
526
540
527
541
let js_name = format ! ( "{}.js" , self . name) ;
528
- let hashed_js_name = format ! ( "{}.js" , hashed_name) ;
542
+ let hashed_js_name =
543
+ apply_data_target_path ( format ! ( "{}.js" , hashed_name) , & self . target_path ) ;
529
544
let ts_name = format ! ( "{}.d.ts" , self . name) ;
530
- let hashed_ts_name = format ! ( "{}.d.ts" , hashed_name) ;
545
+ let hashed_ts_name =
546
+ apply_data_target_path ( format ! ( "{}.d.ts" , hashed_name) , & self . target_path ) ;
531
547
532
548
let js_loader_path = bindgen_out. join ( & js_name) ;
533
549
let js_loader_path_dist = self . cfg . staging_dist . join ( & hashed_js_name) ;
534
550
let wasm_name = format ! ( "{}_bg.wasm" , self . name) ;
535
551
let wasm_path = bindgen_out. join ( & wasm_name) ;
536
552
let wasm_path_dist = self . cfg . staging_dist . join ( & hashed_wasm_name) ;
537
553
538
- let hashed_loader_name = self
539
- . loader_shim
540
- . then ( || format ! ( "{}_loader.js" , hashed_name ) ) ;
554
+ let hashed_loader_name = self . loader_shim . then ( || {
555
+ apply_data_target_path ( format ! ( "{}_loader.js" , hashed_name ) , & self . target_path )
556
+ } ) ;
541
557
let loader_shim_path = hashed_loader_name
542
558
. as_ref ( )
543
559
. map ( |m| self . cfg . staging_dist . join ( m) ) ;
@@ -610,7 +626,7 @@ impl RustApp {
610
626
// Check for any snippets, and copy them over.
611
627
let snippets_dir_src = bindgen_out. join ( SNIPPETS_DIR ) ;
612
628
let snippets = if path_exists ( & snippets_dir_src) . await ? {
613
- let snippets_dir_dest = self . cfg . staging_dist . join ( SNIPPETS_DIR ) ;
629
+ let snippets_dir_dest = target_path . join ( SNIPPETS_DIR ) ;
614
630
tracing:: debug!(
615
631
"recursively copying from '{snippets_dir_src}' to '{}'" ,
616
632
snippets_dir_dest. display( )
@@ -757,7 +773,7 @@ impl RustApp {
757
773
return false ;
758
774
}
759
775
760
- // if we have a --bin argument
776
+ // if we have the --bin argument
761
777
if let Some ( bin) = & self . bin {
762
778
// it must match
763
779
if bin != & art. target . name {
0 commit comments