mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-17 15:01:23 +00:00
More reuse of a parity_wasm::Module
in the test runner
This commit updates the test runner to only deserialize a `Module` once and then directly pass it to the `wasm-bindgen` config, avoiding pulling in a public dependency with the same strategy as the `wasm-gc-api` crate for now. This reduces the runtime of this step for `wasm-bindgen-test-runner` from ~0.23s to ~0.19s on my machine.
This commit is contained in:
@ -50,16 +50,6 @@ fn rmain() -> Result<(), Error> {
|
||||
fs::create_dir(&tmpdir)
|
||||
.context("creating temporary directory")?;
|
||||
|
||||
// For now unconditionally generate wasm-bindgen code tailored for node.js,
|
||||
// but eventually we'll want more options here for browsers!
|
||||
let mut b = Bindgen::new();
|
||||
b.debug(true)
|
||||
.nodejs(true)
|
||||
.input_path(&wasm_file_to_test)
|
||||
.keep_debug(false)
|
||||
.generate(&tmpdir)
|
||||
.context("executing `wasm-bindgen` over the wasm file")?;
|
||||
|
||||
let module = wasm_file_to_test.file_stem()
|
||||
.and_then(|s| s.to_str())
|
||||
.ok_or_else(|| format_err!("invalid filename passed in"))?;
|
||||
@ -118,12 +108,12 @@ fn rmain() -> Result<(), Error> {
|
||||
// execute, and then those objects are passed into wasm for it to execute
|
||||
// when it sees fit.
|
||||
let mut wasm = Vec::new();
|
||||
let wasm_file = tmpdir.join(format!("{}_bg.wasm", module));
|
||||
File::open(wasm_file).and_then(|mut f| f.read_to_end(&mut wasm))
|
||||
File::open(&wasm_file_to_test)
|
||||
.and_then(|mut f| f.read_to_end(&mut wasm))
|
||||
.context("failed to read wasm file")?;
|
||||
let module = Module::deserialize(&mut &wasm[..])
|
||||
let wasm = Module::deserialize(&mut &wasm[..])
|
||||
.context("failed to deserialize wasm module")?;
|
||||
if let Some(exports) = module.export_section() {
|
||||
if let Some(exports) = wasm.export_section() {
|
||||
for export in exports.entries() {
|
||||
if !export.field().starts_with("__wbg_test") {
|
||||
continue
|
||||
@ -135,6 +125,16 @@ fn rmain() -> Result<(), Error> {
|
||||
// And as a final addendum, exit with a nonzero code if any tests fail.
|
||||
js_to_execute.push_str("if (!cx.run(tests)) exit(1);\n");
|
||||
|
||||
// For now unconditionally generate wasm-bindgen code tailored for node.js,
|
||||
// but eventually we'll want more options here for browsers!
|
||||
let mut b = Bindgen::new();
|
||||
b.debug(true)
|
||||
.nodejs(true)
|
||||
.input_module(module, wasm, |m| parity_wasm::serialize(m).unwrap())
|
||||
.keep_debug(false)
|
||||
.generate(&tmpdir)
|
||||
.context("executing `wasm-bindgen` over the wasm file")?;
|
||||
|
||||
let js_path = tmpdir.join("run.js");
|
||||
File::create(&js_path)
|
||||
.and_then(|mut f| f.write_all(js_to_execute.as_bytes()))
|
||||
|
Reference in New Issue
Block a user