1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/wasm
git a892e5599e * expand tabs. [ci skip]
Tabs were expanded because the file did not have any tab indentation in unedited lines.
Please update your editor config, and use misc/expand_tabs.rb in the pre-commit hook.
2022-01-19 11:19:20 +09:00
..
tests [wasm] add unit test suite for fiber, register scan, sjlj in platform dir 2022-01-19 11:19:06 +09:00
asyncify.h
fiber.c
fiber.h
GNUmakefile.in [wasm] add unit test suite for fiber, register scan, sjlj in platform dir 2022-01-19 11:19:06 +09:00
machine.c
machine.h
machine_core.S
missing.c
README.md [wasm] wasm/README.md: write a brief instruction to cross build 2022-01-19 11:19:06 +09:00
runtime.c
setjmp.c * expand tabs. [ci skip] 2022-01-19 11:19:20 +09:00
setjmp.h
setjmp_core.S
wasm-opt

WebAssembly / WASI port of Ruby

How to cross-build

Requirement

Steps

  1. Download a prebuilt WASI SDK package from WASI SDK release page.
  2. Set WASI_SDK_PATH environment variable to the root directory of the WASI SDK package.
$ export WASI_SDK_PATH=/path/to/wasi-sdk-X.Y
  1. Download a prebuilt binaryen from Binaryen release page
  2. Set PATH environment variable to lookup binaryen tools
$ export PATH=path/to/binaryen:$PATH
  1. Configure
  • You can select which extensions you want to build.
  • If you got Out of bounds memory access while running the produced ruby, you may need to increase the maximum size of stack.
$ ./configure LDFLAGS="-Xlinker -zstack-size=16777216" \
  --host wasm32-unknown-wasi \
  --with-destdir=./ruby-wasm32-wasi \
  --with-static-linked-ext \
  --with-ext=ripper,monitor
  1. Make
$ make install

Now you have a WASI compatible ruby binary. You can run it by any WebAssembly runtime like wasmtime, wasmer, Node.js, or browser with WASI polyfill.

Note: it may take a long time (~20 sec) for the first time for JIT compilation

$ wasmtime ruby-wasm32-wasi/usr/local/bin/ruby --mapdir /::./ruby-wasm32-wasi/ -- -e 'puts RUBY_PLATFORM'
wasm32-wasi

Current Limitation

  • No Thread support for now.
  • Spawning a new process is not supported. e.g. Kernel.spawn and Kernel.system