Skip to content

Commit eece090

Browse files
author
Pat Hickey
committed
test build: replace wasm modules used for testing with the component encoding
1 parent e6edcc2 commit eece090

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

crates/test-helpers/build.rs

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,11 @@ fn main() {
4141
if file.extension().and_then(|s| s.to_str()) != Some("wasm") {
4242
continue;
4343
}
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();
4945

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.
5347
let module = fs::read(&file).expect("failed to read wasm file");
54-
ComponentEncoder::default()
48+
let component = ComponentEncoder::default()
5549
.module(module.as_slice())
5650
.expect("pull custom sections from module")
5751
.validate(true)
@@ -62,6 +56,10 @@ fn main() {
6256
"module {:?} can be translated to a component",
6357
file
6458
));
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()));
6563

6664
let dep_file = file.with_extension("d");
6765
let deps = fs::read_to_string(&dep_file).expect("failed to read dep file");
@@ -149,17 +147,11 @@ fn main() {
149147
panic!("failed to compile");
150148
}
151149

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();
157151

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.
161153
let module = fs::read(&out_wasm).expect("failed to read wasm file");
162-
ComponentEncoder::default()
154+
let component = ComponentEncoder::default()
163155
.module(module.as_slice())
164156
.expect("pull custom sections from module")
165157
.validate(true)
@@ -170,6 +162,10 @@ fn main() {
170162
"module {:?} can be translated to a component",
171163
out_wasm
172164
));
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()));
173169
}
174170
}
175171

@@ -253,21 +249,15 @@ fn main() {
253249

254250
let out_wasm = out_dir.join("target/generated/wasm/teavm-wasm/classes.wasm");
255251

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-
262252
let imports = [Interface::parse_file(test_dir.join("imports.wit")).unwrap()];
263253
let interface = Interface::parse_file(test_dir.join("exports.wit")).unwrap();
264254

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.
269259
let module = fs::read(&out_wasm).expect("failed to read wasm file");
270-
ComponentEncoder::default()
260+
let component = ComponentEncoder::default()
271261
.imports(&imports)
272262
.interface(&interface)
273263
.module(module.as_slice())
@@ -280,6 +270,15 @@ fn main() {
280270
"module {:?} can be translated to a component",
281271
out_wasm
282272
));
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+
));
283282
}
284283
}
285284

0 commit comments

Comments
 (0)