@@ -3,6 +3,7 @@ use std::fs;
3
3
use std:: path:: PathBuf ;
4
4
use std:: process:: Command ;
5
5
use wit_bindgen_core:: { wit_parser:: Interface , Direction , Generator } ;
6
+ use wit_component:: ComponentEncoder ;
6
7
7
8
fn main ( ) {
8
9
let out_dir = PathBuf :: from ( std:: env:: var_os ( "OUT_DIR" ) . unwrap ( ) ) ;
@@ -13,14 +14,18 @@ fn main() {
13
14
let mut cmd = Command :: new ( "cargo" ) ;
14
15
cmd. arg ( "build" )
15
16
. current_dir ( "../test-rust-wasm" )
16
- . arg ( "--target=wasm32-wasi " )
17
+ . arg ( "--target=wasm32-unknown-unknown " )
17
18
. env ( "CARGO_TARGET_DIR" , & out_dir)
18
19
. env ( "CARGO_PROFILE_DEV_DEBUG" , "1" )
19
20
. env ( "RUSTFLAGS" , "-Clink-args=--export-table" )
20
21
. env_remove ( "CARGO_ENCODED_RUSTFLAGS" ) ;
21
22
let status = cmd. status ( ) . unwrap ( ) ;
22
23
assert ! ( status. success( ) ) ;
23
- for file in out_dir. join ( "wasm32-wasi/debug" ) . read_dir ( ) . unwrap ( ) {
24
+ for file in out_dir
25
+ . join ( "wasm32-unknown-unknown/debug" )
26
+ . read_dir ( )
27
+ . unwrap ( )
28
+ {
24
29
let file = file. unwrap ( ) . path ( ) ;
25
30
if file. extension ( ) . and_then ( |s| s. to_str ( ) ) != Some ( "wasm" ) {
26
31
continue ;
@@ -31,6 +36,26 @@ fn main() {
31
36
file. to_str ( ) . unwrap ( ) . to_string ( ) ,
32
37
) ) ;
33
38
39
+ // TODO: add an adapter for snapshot 1, and go back to compiling this target for
40
+ // wasm32-wasi
41
+ let module = fs:: read ( & file) . expect ( "failed to read wasm file" ) ;
42
+ match ComponentEncoder :: default ( )
43
+ . module ( module. as_slice ( ) )
44
+ . expect ( "pull custom sections from module" )
45
+ . validate ( true )
46
+ . encode ( )
47
+ {
48
+ Ok ( _) => { }
49
+ Err ( e) => {
50
+ if ![ "invalid" , "handles" ]
51
+ . iter ( )
52
+ . any ( |s| * s == file. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) )
53
+ {
54
+ panic ! ( "component encoder for {:?} failed: {:?}" , file, e) ;
55
+ }
56
+ }
57
+ }
58
+
34
59
let dep_file = file. with_extension ( "d" ) ;
35
60
let deps = fs:: read_to_string ( & dep_file) . expect ( "failed to read dep file" ) ;
36
61
for dep in deps
0 commit comments