flan/test/wasm-run.mjs
Joseph Ferano b14793517b The hash, asked of the second target and compared to the first
sand-headless imports no raylib so that it can run here, and the point of the
case is not that a module exists — it is that the number matches native byte
for byte, which is only possible because rand-f32 is Flan's rather than libc's.
It does, at -O2 and at -O0; -O0 is the cheap way to say the agreement is not a
coincidence of how LLVM folded the float arithmetic. values and machine run
there too, which is where a 32-bit pointer would have shown.

Four separate things can be missing — clang's wasm target, the sysroot, the
builtins, a WASI runtime — so the skip is a probe rather than a lookup: build
the smallest program and run it, and print what went wrong. A which(1) would go
red on the machine where Node is too old, with a reason nobody could read.

No wasmtime and no wasmer here, so the runner is node:wasi, with wasmtime and
wasmer preferred if either appears. --no-warnings because node:wasi writes to
stderr on every run and this harness compares combined output.
2026-09-11 19:43:35 +07:00

24 lines
1011 B
JavaScript

// A WASI host, so the acceptance table can run a wasm32 build without a
// wasmtime or wasmer being installed. Node has had node:wasi since 16; it is
// still flagged experimental, hence --no-warnings at the call site, and before
// Node 20 it needs --experimental-wasi-unstable-preview1 as well. The
// acceptance test probes rather than assumes: if this file cannot run the
// module, the wasm case is skipped with what went wrong.
//
// preopens is empty on purpose. sand-headless reads nothing and writes one
// line to stdout, which is the whole point of it being the cross-target case.
import { WASI } from 'node:wasi';
import { readFile } from 'node:fs/promises';
const [, , file, ...rest] = process.argv;
const wasi = new WASI({
version: 'preview1',
args: [file, ...rest],
env: {},
preopens: {},
returnOnExit: true,
});
const mod = await WebAssembly.compile(await readFile(file));
const inst = await WebAssembly.instantiate(mod, wasi.getImportObject());
process.exitCode = wasi.start(inst);