Tools for compiling Crystal dependencies, bindings, etc. for use with wasm
MIT License
Tools for compiling Crystal dependencies, bindings, etc. for use with WASM
I'm currently working on targeting wasm32-wasi for Crystal. This keeps the focus rather narrow on things that are supported w/ roughly mainline LLVM. Initially, I focused on emscripten, but decided I didn't want to invest the effort getting super into the Emscripten internals, tools, etc.
mkdir -p ~/toolchains/crystal-wasm-libs/targets/wasm32-wasi
~/toolchains
. The resulting directory shoud be something like ~/toolchains/wasi-sdk-10.0
export WASI_SDK_PATH="$HOME/toolchains/wasi-sdk-10.0
I have a copy of libpcre w/ some minor changes to support building for WASI. The PR is here: https://github.com/maxfierke/libpcre/pull/1
For building Crystal programs for wasm32-wasi, we'll need a compiled version of libpcre for the platform. Luckily, libpcre is super easy to compile for wasm32-wasi.
git clone [email protected]:maxfierke/libpcre.git -b mf-wasm32-wasi-cross-compile
cd libpcre
./build_for_crystal.sh
. This should compile successfully and place the.a
static library in targets/wasm32-wasi
cp targets/wasm32-wasi/*.a ~/toolchains/crystal-wasm-libs/targets/wasm32-wasi
I have a fork of crystal with a small-level of support for wasm32-wasi. It can compile for it, and simple binaries can execute in WAVM.
git clone [email protected]:maxfierke/crystal.git -b mf-spike_wasm_take_two crystal-wasm
cd crystal-wasm
make clean && make
to compile the compilerspec/run_wasm_spec.sh
to run the full spec suiteYou can use spec/run_wasm_spec.sh
as a basis for how to cross-compile programs
for wasm.
Add support for some polling-based stuff using poll_oneoff
Add support for stuff that uses libgmp. should unblock a few specs.
Add support for stuff that uses OpenSSL. Prior work shows that OpenSSL can be compiled in some form for wasm. None of the networking APIs or things that use signals, but appears the crypto side might work out okay.
Add support for stuff that uses zlib. Likely similar story as libpcre or openssl. zlib shouldn't depend on too many unsupported libc APIs.
Add support for emulated mman and emulated signals. Maybe this'll help?
Add support for bohem gc. theoretically it has been compiled for asm.js and w/ emscripten. remains to be seen if there's enough there for wasi