@@ -41,17 +41,11 @@ fn main() {
41
41
if file. extension ( ) . and_then ( |s| s. to_str ( ) ) != Some ( "wasm" ) {
42
42
continue ;
43
43
}
44
- wasms. push ( (
45
- "rust" ,
46
- file. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ,
47
- file. to_str ( ) . unwrap ( ) . to_string ( ) ,
48
- ) ) ;
44
+ let stem = file. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
49
45
50
- // Validate that the module can be translated to a component, using
51
- // the component-type custom sections. We don't yet consume this component
52
- // anywhere.
46
+ // Translate the canonical ABI module into a component.
53
47
let module = fs:: read ( & file) . expect ( "failed to read wasm file" ) ;
54
- ComponentEncoder :: default ( )
48
+ let component = ComponentEncoder :: default ( )
55
49
. module ( module. as_slice ( ) )
56
50
. expect ( "pull custom sections from module" )
57
51
. validate ( true )
@@ -62,6 +56,10 @@ fn main() {
62
56
"module {:?} can be translated to a component" ,
63
57
file
64
58
) ) ;
59
+ let component_path = out_dir. join ( format ! ( "{}.component.wasm" , stem) ) ;
60
+ fs:: write ( & component_path, component) . expect ( "write component to disk" ) ;
61
+
62
+ wasms. push ( ( "rust" , stem, component_path. to_str ( ) . unwrap ( ) . to_string ( ) ) ) ;
65
63
66
64
let dep_file = file. with_extension ( "d" ) ;
67
65
let deps = fs:: read_to_string ( & dep_file) . expect ( "failed to read dep file" ) ;
@@ -149,17 +147,11 @@ fn main() {
149
147
panic ! ( "failed to compile" ) ;
150
148
}
151
149
152
- wasms. push ( (
153
- "c" ,
154
- test_dir. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ,
155
- out_wasm. to_str ( ) . unwrap ( ) . to_string ( ) ,
156
- ) ) ;
150
+ let stem = test_dir. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
157
151
158
- // Validate that the module can be translated to a component, using
159
- // the component-type custom sections. We don't yet consume this component
160
- // anywhere.
152
+ // Translate the canonical ABI module into a component.
161
153
let module = fs:: read ( & out_wasm) . expect ( "failed to read wasm file" ) ;
162
- ComponentEncoder :: default ( )
154
+ let component = ComponentEncoder :: default ( )
163
155
. module ( module. as_slice ( ) )
164
156
. expect ( "pull custom sections from module" )
165
157
. validate ( true )
@@ -170,6 +162,10 @@ fn main() {
170
162
"module {:?} can be translated to a component" ,
171
163
out_wasm
172
164
) ) ;
165
+ let component_path = out_dir. join ( "c.component.wasm" ) ;
166
+ fs:: write ( & component_path, component) . expect ( "write component to disk" ) ;
167
+
168
+ wasms. push ( ( "c" , stem, component_path. to_str ( ) . unwrap ( ) . to_string ( ) ) ) ;
173
169
}
174
170
}
175
171
@@ -253,21 +249,15 @@ fn main() {
253
249
254
250
let out_wasm = out_dir. join ( "target/generated/wasm/teavm-wasm/classes.wasm" ) ;
255
251
256
- wasms. push ( (
257
- "java" ,
258
- test_dir. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ,
259
- out_wasm. to_str ( ) . unwrap ( ) . to_string ( ) ,
260
- ) ) ;
261
-
262
252
let imports = [ Interface :: parse_file ( test_dir. join ( "imports.wit" ) ) . unwrap ( ) ] ;
263
253
let interface = Interface :: parse_file ( test_dir. join ( "exports.wit" ) ) . unwrap ( ) ;
264
254
265
- // Validate that the module can be translated to a component, using
266
- // wit interfaces explicitly passed to ComponentEncoder, because the
267
- // TeaVM guest doesnt yet support putting component types into custom
268
- // sections.
255
+ // Translate the canonical ABI module into a component.
256
+ // The wit interfaces are explicitly passed to ComponentEncoder,
257
+ // because the TeaVM guest doesnt yet support putting component
258
+ // types into custom sections.
269
259
let module = fs:: read ( & out_wasm) . expect ( "failed to read wasm file" ) ;
270
- ComponentEncoder :: default ( )
260
+ let component = ComponentEncoder :: default ( )
271
261
. imports ( & imports)
272
262
. interface ( & interface)
273
263
. module ( module. as_slice ( ) )
@@ -280,6 +270,15 @@ fn main() {
280
270
"module {:?} can be translated to a component" ,
281
271
out_wasm
282
272
) ) ;
273
+ let component_path =
274
+ out_dir. join ( "target/generated/wasm/teavm-wasm/classes.component.wasm" ) ;
275
+ fs:: write ( & component_path, component) . expect ( "write component to disk" ) ;
276
+
277
+ wasms. push ( (
278
+ "java" ,
279
+ test_dir. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ,
280
+ component_path. to_str ( ) . unwrap ( ) . to_string ( ) ,
281
+ ) ) ;
283
282
}
284
283
}
285
284
0 commit comments