Compiling to WASM for JS

Following a few posts I was able to get Crystal to compile to WASM with wasi. From what I understand, WASI is just the basic WASM without any Javascript stuff added. It sounds like in order to get WASM actually in the web, it needs to target emscripten?

Has anyone had success doing this?

> crystal build -o sum.wasm --target wasm32-emscripten

In /usr/share/crystal/src/

 1 | require "c/stdlib"
Error: can't find file 'c/stdlib'

I tried to changing the target, but get some missing libs. I know for the WASI stuff, I needed to build GitHub - lbguilherme/wasm-libs and copy the wasi libs over. I assume I’m missing something for doing emscripten, but I’m not sure what.

I also have wasmer installed, but didn’t see any docs on converting the format over (if that’s even a thing)… My goal is to use WebAssembly.instantiateStreaming() - WebAssembly | MDN and access WASM functions from javascript.

1 Like

These shards should hell with what you’re looking for:


@noaheverett had a tutorial about webassembly in Crystal at WebAssembly Host Functions in Crystal by @noah | Glue


Yeah, I read those. They are really great posts! Though, they are meant for server-side WASM, and not client-side. Still totally recommended though. Thanks

1 Like