7141379559
This commit rewrites a number of `run-make` tests centered around wasm to instead use `rmake.rs` and additionally use the `wasm32-wasip1` target instead of `wasm32-unknown-unknown`. Testing no longer requires Node.js and additionally uses the `wasmparser` crate from crates.io to parse outputs and power assertions.
60 lines
1.7 KiB
Rust
60 lines
1.7 KiB
Rust
extern crate run_make_support;
|
|
|
|
use run_make_support::{out_dir, rustc, wasmparser};
|
|
use std::collections::HashMap;
|
|
use std::path::Path;
|
|
use wasmparser::ExternalKind::*;
|
|
|
|
fn main() {
|
|
if std::env::var("TARGET").unwrap() != "wasm32-wasip1" {
|
|
return;
|
|
}
|
|
|
|
test(&[]);
|
|
test(&["-O"]);
|
|
test(&["-Clto"]);
|
|
}
|
|
|
|
fn test(args: &[&str]) {
|
|
eprintln!("running with {args:?}");
|
|
rustc().arg("bar.rs").arg("--target=wasm32-wasip1").args(args).run();
|
|
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").args(args).run();
|
|
rustc().arg("main.rs").arg("--target=wasm32-wasip1").args(args).run();
|
|
|
|
verify_exports(
|
|
&out_dir().join("foo.wasm"),
|
|
&[("foo", Func), ("FOO", Global), ("memory", Memory)],
|
|
);
|
|
verify_exports(
|
|
&out_dir().join("main.wasm"),
|
|
&[
|
|
("foo", Func),
|
|
("FOO", Global),
|
|
("_start", Func),
|
|
("__main_void", Func),
|
|
("memory", Memory),
|
|
],
|
|
);
|
|
}
|
|
|
|
fn verify_exports(path: &Path, exports: &[(&str, wasmparser::ExternalKind)]) {
|
|
println!("verify {path:?}");
|
|
let file = std::fs::read(path).unwrap();
|
|
let mut wasm_exports = HashMap::new();
|
|
for payload in wasmparser::Parser::new(0).parse_all(&file) {
|
|
let payload = payload.unwrap();
|
|
if let wasmparser::Payload::ExportSection(s) = payload {
|
|
for export in s {
|
|
let export = export.unwrap();
|
|
wasm_exports.insert(export.name, export.kind);
|
|
}
|
|
}
|
|
}
|
|
|
|
eprintln!("found exports {wasm_exports:?}");
|
|
|
|
assert_eq!(exports.len(), wasm_exports.len());
|
|
for (export, expected_kind) in exports {
|
|
assert_eq!(wasm_exports[export], *expected_kind);
|
|
}
|
|
}
|