rust/tests/run-make/wasm-export-all-symbols/rmake.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.6 KiB
Rust
Raw Normal View History

//@ only-wasm32-wasip1
use run_make_support::{fs_wrapper, rustc, wasmparser};
use std::collections::HashMap;
use std::path::Path;
use wasmparser::ExternalKind::*;
fn main() {
test(&[]);
test(&["-O"]);
test(&["-Clto"]);
}
fn test(args: &[&str]) {
eprintln!("running with {args:?}");
rustc().input("bar.rs").target("wasm32-wasip1").args(args).run();
rustc().input("foo.rs").target("wasm32-wasip1").args(args).run();
rustc().input("main.rs").target("wasm32-wasip1").args(args).run();
verify_exports(Path::new("foo.wasm"), &[("foo", Func), ("FOO", Global), ("memory", Memory)]);
verify_exports(
Path::new("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 = fs_wrapper::read(path);
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);
}
}