4 ms·
I was investigating using wasm/wasi to implement a parser that is currently written in javascript, such that I would still be able to use it in the browser but
by koch 4y ago
I was investigating using wasm/wasi to implement a parser that is currently written in javascript, such that I would still be able to use it in the browser but also open up other avenues for it to be used on other platforms.
I got bogged down in the wasi/wasm debate and terminology and different available runtimes (or whatever they should be called) - wasmtime, wasmer, wasmedge, fermyon, bytecode alliance... I probably would have spent more time and figured it out if I didn't want to learn rust right now. Seems rust is the best supported language for wasm as far as I can tell.
Otherwise admittedly I would have used a large token context ChatGPT to convert the library to rust for me, and then also have it compile it to wasm.
- flohofwoe 4y agoJust 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.
- antifa 4y agoThat was my experience. It was basically "use rust" or "nothing useful is implemented".