Awesome
ruby.wasm
ruby.wasm is a collection of WebAssembly ports of the CRuby. It enables running Ruby application on browsers, WASI compatible WebAssembly runtimes, and Edge Computing platforms.
Try ruby.wasm (no installation needed)
Try ruby.wasm in TryRuby in your browser.
Quick Links
Quick Example: Ruby on Web browser
Create and save index.html
page with the following contents:
<html>
<script src="https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.6.2/dist/browser.script.iife.js"></script>
<script type="text/ruby">
require "js"
puts RUBY_VERSION # (Printed to the Web browser console)
JS.global[:document].write "Hello, world!"
</script>
</html>
Quick Example: How to package your Ruby application as a WASI application
Dependencies: wasmtime
$ gem install ruby_wasm
# Download a prebuilt Ruby release
$ curl -LO https://github.com/ruby/ruby.wasm/releases/latest/download/ruby-3.3-wasm32-unknown-wasip1-full.tar.gz
$ tar xfz ruby-3.3-wasm32-unknown-wasip1-full.tar.gz
# Extract ruby binary not to pack itself
$ mv ruby-3.3-wasm32-unknown-wasip1-full/usr/local/bin/ruby ruby.wasm
# Put your app code
$ mkdir src
$ echo "puts 'Hello'" > src/my_app.rb
# Pack the whole directory under /usr and your app dir
$ rbwasm pack ruby.wasm --dir ./src::/src --dir ./ruby-3.3-wasm32-unknown-wasip1-full/usr::/usr -o my-ruby-app.wasm
# Run the packed scripts
$ wasmtime my-ruby-app.wasm /src/my_app.rb
Hello
npm packages (for JavaScript host environments)
See the README.md
of each package for more detail and its usage.
Prebuilt binaries
This project distributes prebuilt Ruby binaries in GitHub Releases. A build is a combination of ruby version, profile, and target.
Supported Target Triples
<table> <thead> <tr> <th>Triple</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td><code>wasm32-unknown-wasip1</code></td> <td>Targeting <a href="https://github.com/WebAssembly/WASI/tree/main/legacy/preview1">WASI Preview1</a> compatible environments <br>(e.g. Node.js, browsers with polyfill, <a href="https://github.com/bytecodealliance/wasmtime">wasmtime</a>, and so on)</td> </tr> <tr> <td><code>wasm32-unknown-emscripten</code></td> <td>Targeting JavaScript environments including Node.js and browsers</td> </tr> </tbody> </table>Profiles
<table> <thead> <tr> <th>Profile</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td><code>minimal</code></td> <td>No standard extension libraries (like <code>json</code>, <code>yaml</code>, or <code>stringio</code>)</td> </tr> <tr> <td><code>full</code></td> <td>All standard extension libraries</td> </tr> </tbody> </table>Notable Limitations
The current WASI target build does not yet support Thread
related APIs. Specifically, WASI does not yet have an API for creating and managing threads yet.
Also there is no support for networking. It is one of the goal of WASI to support networking in the future, but it is not yet implemented.
Contributing
See CONTRIBUTING.md for how to build and test, and how to contribute to this project. Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/ruby.wasm