{"id":15542467,"url":"https://github.com/maxfierke/crystal-wasm-tools","last_synced_at":"2025-04-23T17:11:59.163Z","repository":{"id":142527771,"uuid":"253636079","full_name":"maxfierke/crystal-wasm-tools","owner":"maxfierke","description":"Tools for compiling Crystal dependencies, bindings, etc. for use with wasm","archived":false,"fork":false,"pushed_at":"2020-09-29T04:13:12.000Z","size":5,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-23T17:11:53.017Z","etag":null,"topics":["crystal","crystal-lang","wasm"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maxfierke.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-06T23:08:38.000Z","updated_at":"2023-02-24T21:28:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"789fea22-c1d6-4fa2-b2d7-9c8fc5c7189c","html_url":"https://github.com/maxfierke/crystal-wasm-tools","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxfierke%2Fcrystal-wasm-tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxfierke%2Fcrystal-wasm-tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxfierke%2Fcrystal-wasm-tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxfierke%2Fcrystal-wasm-tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxfierke","download_url":"https://codeload.github.com/maxfierke/crystal-wasm-tools/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250477810,"owners_count":21437049,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crystal","crystal-lang","wasm"],"created_at":"2024-10-02T12:22:47.011Z","updated_at":"2025-04-23T17:11:59.158Z","avatar_url":"https://github.com/maxfierke.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# crystal-wasm-tools\nTools for compiling Crystal dependencies, bindings, etc. for use with WASM\n\nI'm currently working on targeting wasm32-wasi for Crystal. This keeps the focus\nrather narrow on things that are supported w/ roughly mainline LLVM. Initially,\nI focused on emscripten, but decided I didn't want to invest the effort getting\nsuper into the Emscripten internals, tools, etc.\n\n## Setting up prerequisites\n\n0. Make sure you've installed autoconf, automake, build-essential, etc.\n1. `mkdir -p ~/toolchains/crystal-wasm-libs/targets/wasm32-wasi`\n2. Download [latest release of wasi-sdk](https://github.com/WebAssembly/wasi-sdk/releases)\n3. Extract to `~/toolchains`. The resulting directory shoud be something like `~/toolchains/wasi-sdk-10.0`\n4. Run (and/or add to your shell): `export WASI_SDK_PATH=\"$HOME/toolchains/wasi-sdk-10.0`\n5. Install [WAVM](https://github.com/WAVM/WAVM)\n\n### Compiling libpcre for wasm\n\nI have a copy of libpcre w/ some minor changes to support building for WASI. The\nPR is here: https://github.com/maxfierke/libpcre/pull/1\n\nFor building Crystal programs for wasm32-wasi, we'll need a compiled version of\nlibpcre for the platform. Luckily, libpcre is super easy to compile for wasm32-wasi.\n\n1. Clone my fork of libpcre:\n   ```sh\n   git clone git@github.com:maxfierke/libpcre.git -b mf-wasm32-wasi-cross-compile\n   ```\n2. `cd libpcre`\n3. Run `./build_for_crystal.sh`. This should compile successfully and place the\n   compiled `.a` static library in `targets/wasm32-wasi`\n4. `cp targets/wasm32-wasi/*.a ~/toolchains/crystal-wasm-libs/targets/wasm32-wasi`\n\n## Compiling Crystal for wasm\n\nI have a fork of crystal with a small-level of support for wasm32-wasi. It can\ncompile for it, and simple binaries can execute in WAVM.\n\n0. Follow usual instructions for [installing Crystal on your platform](https://crystal-lang.org/install/). You may need\n   to also [install some additional packages](https://github.com/crystal-lang/crystal/wiki/All-required-libraries)\n   for your platform.\n1. Run `git clone git@github.com:maxfierke/crystal.git -b mf-spike_wasm_take_two crystal-wasm`\n2. `cd crystal-wasm`\n3. `make clean \u0026\u0026 make` to compile the compiler\n4. Run `spec/run_wasm_spec.sh` to run the full spec suite\n\nYou can use `spec/run_wasm_spec.sh` as a basis for how to cross-compile programs\nfor wasm.\n\n## Caveats\n\n* This is _very_, _very_ rough. Many APIs are not supported at all (e.g.\n  most IO, signals, sockets, Process, GC, concurrency, OpenSSL, Zlib, Big, etc.)\n* There is **no support for exceptions**. This is mostly due to a limitation\n  WebAssembly itself. The exception handling proposal is still in development.\n  Some runtimes have varying levels of support for it, but the codegen from LLVM\n  requires LLVM master, isn't supported in wasi-sdk, etc. As a result, any code\n  that throws exceptions will crash (if it throws). This alone _severely_ limits\n  use of Crystal on wasm, as a lot of code relies on exception handling, including\n  parts of the stdlib.\n* There are [strange require order dependencies I don't understand](https://github.com/maxfierke/crystal/commit/56a6a148853ef26f52c0ebfd7cfe08887ec9e88f)\n\n## Future Plans\n\n* Add support for some polling-based stuff using `poll_oneoff`\n\n* Add support for stuff that uses libgmp. should unblock a few specs.\n\n* Add support for stuff that uses OpenSSL. [Prior work](https://github.com/wapm-packages/OpenSSL) shows\n  that OpenSSL can be compiled in some form for wasm. None of the networking APIs\n  or things that use signals, but appears the crypto side might work out okay.\n\n* Add support for stuff that uses zlib. Likely similar story as libpcre or openssl.\n  zlib shouldn't depend on too many unsupported libc APIs.\n\n* Add support for emulated mman and emulated signals. Maybe this'll help?\n\n* Add support for bohem gc. theoretically it has been compiled for asm.js and w/\n  emscripten. remains to be seen if there's enough there for wasi\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxfierke%2Fcrystal-wasm-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxfierke%2Fcrystal-wasm-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxfierke%2Fcrystal-wasm-tools/lists"}