A Ruby gem to quickly get started with WebAssembly
The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:
This is the repo for the
wasmgem and also a place to start a conversation about Ruby and WebAssembly, and how our community might leverage this new capability. For some background, check out my blog post on the subject. This is largely an experiment at the moment — there are plenty of things this gem doesn't do, but it's a starting point and will hopefully get you up and running quickly so we can learn and explore together.
Feel free to open an issue about anything at all, even just to chat. Enjoy!
raketo build this gem and install locally.
rake mruby_latestto set the MRuby submodule to the latest release and
rake mruby_masterto switch to the master branch.
rake build_mrubyto build an MRuby static library for WebAssembly, which will be placed in the
assets/directory (a prebuilt one is already there).
When a new version of MRuby is released, update the version number in the
rake mruby_latest, and
Get it with
gem install wasm
Once installed, you'll have access to the
ruby-wasmcommand-line utility. Use this utility to build and serve Ruby apps for WebAssembly. Running it without any options will print its usage. Troubleshoot your WebAssembly toolchain with
What this gem currently does: - Compile a single Ruby script to a binary
What it doesn't do yet (maybe something you'd like to work on 🤔): - Build several scripts at a time, or pull in others via
First, make sure you have the WebAssembly toolchain installed and activated — see the "Getting Started" guide for details.
Start by cloning this repo (the
--recursiveoption also grabs the MRuby submodule and initializes it):
git clone --recursive https://github.com/blacktm/ruby-wasm.git
cdinto the directory. Notice there's a file called
hello.rb— we're going to build it for WebAssembly!
Make sure you have this
wasmgem installed. Remember, you can check for issues using
Now, we'll build (or compile) the "Hello Ruby!" app using:
ruby-wasm build hello.rb
This will create a
build/directory and generate the following files: -
app.wasm— Our compiled Ruby app in binary WebAssembly format -
.wasmbinary and initialize the WebAssembly environment (learn more) -
ruby-wasm serveto do this.
Finally, open your favorite web browser and go to
http://localhost:8000/app.html. Open your web inspector / developer tools and you'll see "Hello Ruby!" printed in the console. Exciting! 🙌