@@ -36,6 +36,7 @@ pub struct Bindgen {
36
36
// "ready to be instantiated on any thread"
37
37
threads : wasm_bindgen_threads_xform:: Config ,
38
38
anyref : bool ,
39
+ wasm_interface_types : bool ,
39
40
encode_into : EncodeInto ,
40
41
}
41
42
@@ -49,6 +50,7 @@ pub struct Output {
49
50
snippets : HashMap < String , Vec < String > > ,
50
51
local_modules : HashMap < String , String > ,
51
52
npm_dependencies : HashMap < String , ( PathBuf , String ) > ,
53
+ wasm_interface_types : bool ,
52
54
}
53
55
54
56
#[ derive( Clone ) ]
@@ -73,6 +75,8 @@ pub enum EncodeInto {
73
75
74
76
impl Bindgen {
75
77
pub fn new ( ) -> Bindgen {
78
+ let anyref = env:: var ( "WASM_BINDGEN_ANYREF" ) . is_ok ( ) ;
79
+ let wasm_interface_types = env:: var ( "WASM_INTERFACE_TYPES" ) . is_ok ( ) ;
76
80
Bindgen {
77
81
input : Input :: None ,
78
82
out_name : None ,
@@ -88,7 +92,8 @@ impl Bindgen {
88
92
emit_start : true ,
89
93
weak_refs : env:: var ( "WASM_BINDGEN_WEAKREF" ) . is_ok ( ) ,
90
94
threads : threads_config ( ) ,
91
- anyref : env:: var ( "WASM_BINDGEN_ANYREF" ) . is_ok ( ) ,
95
+ anyref : anyref || wasm_interface_types,
96
+ wasm_interface_types,
92
97
encode_into : EncodeInto :: Test ,
93
98
}
94
99
}
@@ -315,15 +320,15 @@ impl Bindgen {
315
320
// the webidl bindings proposal) as well as an auxiliary section for all
316
321
// sorts of miscellaneous information and features #[wasm_bindgen]
317
322
// supports that aren't covered by WebIDL bindings.
318
- webidl:: process ( & mut module, self . anyref , self . emit_start ) ?;
323
+ webidl:: process ( & mut module, self . anyref , self . wasm_interface_types , self . emit_start ) ?;
319
324
320
325
// Now that we've got type information from the webidl processing pass,
321
326
// touch up the output of rustc to insert anyref shims where necessary.
322
327
// This is only done if the anyref pass is enabled, which it's
323
328
// currently off-by-default since `anyref` is still in development in
324
329
// engines.
325
330
if self . anyref {
326
- anyref:: process ( & mut module) ?;
331
+ anyref:: process ( & mut module, self . wasm_interface_types ) ?;
327
332
}
328
333
329
334
let aux = module
@@ -344,6 +349,11 @@ impl Bindgen {
344
349
( npm_dependencies, cx. finalize ( stem) ?)
345
350
} ;
346
351
352
+ if self . wasm_interface_types {
353
+ webidl:: standard:: add_section ( & mut module, & aux, & bindings)
354
+ . with_context ( |_| "failed to generate a standard wasm bindings custom section" ) ?;
355
+ }
356
+
347
357
Ok ( Output {
348
358
module,
349
359
stem : stem. to_string ( ) ,
@@ -354,6 +364,7 @@ impl Bindgen {
354
364
ts,
355
365
mode : self . mode . clone ( ) ,
356
366
typescript : self . typescript ,
367
+ wasm_interface_types : self . wasm_interface_types ,
357
368
} )
358
369
}
359
370
@@ -506,6 +517,7 @@ fn unexported_unused_lld_things(module: &mut Module) {
506
517
507
518
impl Output {
508
519
pub fn js ( & self ) -> & str {
520
+ assert ! ( !self . wasm_interface_types) ;
509
521
& self . js
510
522
}
511
523
@@ -518,6 +530,23 @@ impl Output {
518
530
}
519
531
520
532
fn _emit ( & self , out_dir : & Path ) -> Result < ( ) , Error > {
533
+ let wasm_name = if self . wasm_interface_types {
534
+ self . stem . clone ( )
535
+ } else {
536
+ format ! ( "{}_bg" , self . stem)
537
+ } ;
538
+ let wasm_path = out_dir
539
+ . join ( wasm_name)
540
+ . with_extension ( "wasm" ) ;
541
+ fs:: create_dir_all ( out_dir) ?;
542
+ let wasm_bytes = self . module . emit_wasm ( ) ?;
543
+ fs:: write ( & wasm_path, wasm_bytes)
544
+ . with_context ( |_| format ! ( "failed to write `{}`" , wasm_path. display( ) ) ) ?;
545
+
546
+ if self . wasm_interface_types {
547
+ return Ok ( ( ) )
548
+ }
549
+
521
550
// Write out all local JS snippets to the final destination now that
522
551
// we've collected them from all the programs.
523
552
for ( identifier, list) in self . snippets . iter ( ) {
@@ -554,7 +583,6 @@ impl Output {
554
583
} else {
555
584
"js"
556
585
} ;
557
- fs:: create_dir_all ( out_dir) ?;
558
586
let js_path = out_dir. join ( & self . stem ) . with_extension ( extension) ;
559
587
fs:: write ( & js_path, reset_indentation ( & self . js ) )
560
588
. with_context ( |_| format ! ( "failed to write `{}`" , js_path. display( ) ) ) ?;
@@ -565,10 +593,6 @@ impl Output {
565
593
. with_context ( |_| format ! ( "failed to write `{}`" , ts_path. display( ) ) ) ?;
566
594
}
567
595
568
- let wasm_path = out_dir
569
- . join ( format ! ( "{}_bg" , self . stem) )
570
- . with_extension ( "wasm" ) ;
571
-
572
596
if self . mode . nodejs ( ) {
573
597
let js_path = wasm_path. with_extension ( extension) ;
574
598
let shim = self . generate_node_wasm_import ( & self . module , & wasm_path) ;
@@ -583,9 +607,6 @@ impl Output {
583
607
. with_context ( |_| format ! ( "failed to write `{}`" , ts_path. display( ) ) ) ?;
584
608
}
585
609
586
- let wasm_bytes = self . module . emit_wasm ( ) ?;
587
- fs:: write ( & wasm_path, wasm_bytes)
588
- . with_context ( |_| format ! ( "failed to write `{}`" , wasm_path. display( ) ) ) ?;
589
610
Ok ( ( ) )
590
611
}
591
612
0 commit comments