mirror of
https://github.com/ruby/ruby.git
synced 2026-01-28 04:54:23 +00:00
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.
WebAssembly / WASI port of Ruby
How to cross-build
Requirement
- Ruby (the same version as the building target version) (baseruby)
- GNU make
- WASI SDK 14.0 or later
- Binaryen version 91
- Linux or macOS build machine
Steps
- Download a prebuilt WASI SDK package from WASI SDK release page.
- Set
WASI_SDK_PATHenvironment variable to the root directory of the WASI SDK package.
$ export WASI_SDK_PATH=/path/to/wasi-sdk-X.Y
- Download a prebuilt binaryen from Binaryen release page
- Set PATH environment variable to lookup binaryen tools
$ export PATH=path/to/binaryen:$PATH
- Configure
- You can select which extensions you want to build.
- If you got
Out of bounds memory accesswhile 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
- 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
Threadsupport for now. - Spawning a new process is not supported. e.g.
Kernel.spawnandKernel.system