-
Notifications
You must be signed in to change notification settings - Fork 13.3k
/
Copy pathrmake.rs
38 lines (33 loc) · 1.18 KB
/
rmake.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//@ only-wasm32-wasip1
extern crate run_make_support;
use run_make_support::{rustc, tmp_dir, wasmparser};
use std::path::Path;
fn main() {
rustc().input("foo.rs").target("wasm32-wasip1").run();
verify_symbols(&tmp_dir().join("foo.wasm"));
rustc().input("foo.rs").target("wasm32-wasip1").opt().run();
verify_symbols(&tmp_dir().join("foo.wasm"));
rustc().input("bar.rs").target("wasm32-wasip1").run();
verify_symbols(&tmp_dir().join("bar.wasm"));
rustc().input("bar.rs").target("wasm32-wasip1").opt().run();
verify_symbols(&tmp_dir().join("bar.wasm"));
}
fn verify_symbols(path: &Path) {
eprintln!("verify {path:?}");
let file = std::fs::read(&path).unwrap();
for payload in wasmparser::Parser::new(0).parse_all(&file) {
let payload = payload.unwrap();
if let wasmparser::Payload::ExportSection(s) = payload {
for e in s {
let e = e.unwrap();
if e.kind != wasmparser::ExternalKind::Func {
continue;
}
if e.name == "foo" {
continue;
}
panic!("unexpected export {e:?}");
}
}
}
}