-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlink.mjs
More file actions
49 lines (44 loc) · 1.68 KB
/
Copy pathlink.mjs
File metadata and controls
49 lines (44 loc) · 1.68 KB
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
39
40
41
42
43
44
45
46
47
48
49
// SPDX-License-Identifier: PMPL-1.0-or-later
// INT-01 / #178 — cross-module WASM link+execute acceptance harness.
//
// Proves that two SEPARATELY-compiled AffineScript modules link and run
// across the wasm module boundary:
// callee.wasm ← module CrossCallee; pub fn consume(own x: Int) -> Int { x }
// caller.wasm ← use CrossCallee::{consume}; pub fn main() -> Int { consume(42) }
//
// Usage: deno run --allow-read=<dir> link.mjs <callee.wasm> <caller.wasm>
// Exits 0 and prints PASS iff caller.main() === 42 via the cross-module call.
const [calleePath, callerPath] = Deno.args;
if (!calleePath || !callerPath) {
console.error("usage: link.mjs <callee.wasm> <caller.wasm>");
Deno.exit(64);
}
// Minimal WASI shim — the AffineScript wasm imports fd_write for println-style
// codegen; cross-module linking is what is under test, not I/O.
const wasiStub = new Proxy({}, { get: () => () => 0 });
const callee = await WebAssembly.instantiate(
await Deno.readFile(calleePath),
{ wasi_snapshot_preview1: wasiStub },
);
const consume = callee.instance.exports.consume;
if (typeof consume !== "function") {
console.error("FAIL: callee does not export a callable `consume`");
Deno.exit(2);
}
let caller;
try {
caller = await WebAssembly.instantiate(
await Deno.readFile(callerPath),
{ wasi_snapshot_preview1: wasiStub, CrossCallee: { consume } },
);
} catch (e) {
console.error("FAIL: caller did not link against CrossCallee.consume:", e.message);
Deno.exit(3);
}
const r = caller.instance.exports.main();
if (r === 42) {
console.log("PASS: cross-module call CrossCallee.consume(42) === 42");
Deno.exit(0);
}
console.error(`FAIL: expected 42, got ${r}`);
Deno.exit(5);