2 ms·
Just wrap the core functionality into a 'pure' WASM module which doesn't need to access 'system APIs', and then if needed write two thin wrappers, one for the '
by flohofwoe 4y ago
Just wrap the core functionality into a 'pure' WASM module which doesn't need to access 'system APIs', and then if needed write two thin wrappers, one for the 'web personality' and one for the 'WASI personality'.
WASI has the advantage that many compilers support it directly, e.g. in Zig:
> cat hello.zig
const print = @import("std").debug.print;
pub fn main() void {
print("Hello World!\n", .{});
}
> zig build-exe hello.zig -target wasm32-wasi
> wasmtime hello.wasm
Hello World!
Or if you prefer C:
> cat hello.c
#include <stdio.h>
int main() {
printf("Hello World!\n");
}
> zig cc hello.c -o hello.wasm -target wasm32-wasi
> wasmtime hello.wasm
Hello World!
(I guess Rust can do the same, or for a purely clang-based solution see: https://github.com/WebAssembly/wasi-sdk https://github.com/WebAssembly/wasi-sdk).
...while for web compatibility, you'll always need some sort of shim solution to talk to the Javascript APIs.