Giter Club home page Giter Club logo

ruby.wasm's Introduction

ruby.wasm

Build 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 Example: Ruby on browser

Create and save index.html page with the following contents:

<html>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/browser.script.iife.js"></script>
  <script type="text/ruby">
    puts "Hello, world!"
  </script>
</html>

Quick Example: How to package your Ruby application as a WASI application

Dependencies: wasi-vfs, wasmtime

# Download a prebuilt Ruby release
$ curl -LO https://github.com/ruby/ruby.wasm/releases/latest/download/ruby-3_2-wasm32-unknown-wasi-full.tar.gz
$ tar xfz ruby-3_2-wasm32-unknown-wasi-full.tar.gz

# Extract ruby binary not to pack itself
$ mv 3_2-wasm32-unknown-wasi-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
$ wasi-vfs pack ruby.wasm --mapdir /src::./src --mapdir /usr::./3_2-wasm32-unknown-wasi-full/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.

Package Description npm
ruby-3_2-wasm-wasi CRuby 3.2 built on WASI with JS interop support npm version
ruby-head-wasm-wasi HEAD CRuby built on WASI with JS interop support npm version
ruby-head-wasm-emscripten HEAD CRuby built on Emscripten (not well tested) npm version

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

Triple Description
wasm32-unknown-wasi Targeting WASI-compatible environments (e.g. Node.js, browsers with polyfill, wasmtime, and so on)
wasm32-unknown-emscripten Targeting JavaScript environments including Node.js and browsers

Profiles

Profile Description
minimal No standard extension libraries (like json, yaml, or stringio)
full All standard extension libraries
*-js Enabled JS interoperability, only usable with npm package
*-debug With DWARF info and name section for debugging

Note: * is a wildcard that represents any other profile name except for itself, applied recursively. For example, minimal-full-js-debug is a valid profile.

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

ruby.wasm's People

Contributors

kateinoigakukun avatar dependabot[bot] avatar makenowjust avatar ledsun avatar kyanny avatar mame avatar hparker avatar kaiquekandykoga avatar richardboehme avatar shugo avatar skryukov avatar kojix2 avatar woxtu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.