Feature #18462


Proposal to merge WASI based WebAssembly support

Added by katei (Yuta Saito) 21 days ago. Updated 13 days ago.

Target version:


Proposal to merge WASI based WebAssembly support

This is an initial port of WASI based WebAssembly support.
This enables a CRuby binary to be available on Web browser, Serverless Edge environment, and other WebAssembly/WASI embedders.
Currently this port passes basic and bootstrap test suites not using Thread API.

The upstreaming PR on ruby/ruby is here:


For example, CRuby already supports WebAssembly target by Emscripten, but Emscripten heavily depends on JavaScript to emulate some missing features in WebAssembly itself.

In short the WASI is an effort to define a standard set of syscalls for WebAssembly modules, allowing WebAssembly modules to not only be portable across architectures but also be portable across environments implementing this standard set of system calls. The environments includes non JS environments, Edge Computing platforms, IoT devices, and so on.

This is a proposal ticket to support WASI based WebAssembly target.

This is a part of Ruby Association Grant project


  • WASI: A system call interface for WebAssembly
  • wasi-libc: A libc implementation for WebAssembly programs built on top of WASI system calls.

Current Limitation of WebAssembly and WASI


Currently WebAssembly has no threads, and WASI doesn't provide any API to create a thread, but they are on the roadmap. This means doesn't work on this target, and it raises ENOSUP for now.

Register operations

Current WebAssembly doesn't allow to touch the program counter, but they are also on the roadmap.
This limitation makes it hard to implement setjmp/longjmp and context-switching on this target, and wasi-libc doesn't provide such implementations.

And also WebAssembly has function local infinite registers, but there is no way to scan the values in a call stack for now.
This limitation makes it unable to mark living objects by Conservative GC in a simple way.

Patch Overview

This patch is a set of minor changes:

Adapt to wasi-libc API

wasi-libc is almost compatible with other libc implementations, but it doesn't have some functions.
So this patch adds stub implementations for them.

Add no thread variant

As mentioned above, WebAssembly has no thread, so this patch adds a thread_none.c, which is a sibling of thread_win32.c and thread_pthread.c. This implementation does nothing around preemptive context switching because there is no native thread.

Emulate setjmp/longjmp, coroutine, and register scan by Asyncify

As mentioned above, WebAssembly has no context switching feature, but there is an userland technique to pause and resume a WebAssembly process by binary transformation.
This technique is called Asyncify.
This patch utilizes it to emulate setjmp/longjmp, coroutine, and register scan for GC.

Updated by mame (Yusuke Endoh) 14 days ago

At the previous dev-meeting, katei (Yuta Saito) elaborated this proposal and implementation approach himself. The patch is still being checked in detail by nobu (Nobuyoshi Nakada), but we agreed that it looks great.

Because WASI is actively being developed, we will need to keep up with their changes and feature additions. We need a maintainer of WASI platform. ko1 (Koichi Sasada) and I recommend him as a committer and a platform maintainer for WASI in #18488.

This will be a big new feature for Ruby 3.2. matz (Yukihiro Matsumoto) Do you accept this proposal?

Updated by matz (Yukihiro Matsumoto) 13 days ago




Also available in: Atom PDF