-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Add WASI based WebAssembly support #5407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add WASI based WebAssembly support #5407
Conversation
|
@ioquatix You might want to look at the coroutine implementation. |
62b1147 to
337b9df
Compare
337b9df to
4733026
Compare
3e3f6d7 to
f8407ef
Compare
f8407ef to
7a62eb9
Compare
7a62eb9 to
d1dfe42
Compare
d1dfe42 to
65639f1
Compare
d88368f to
74ed76e
Compare
clang does not yet support stack-protector for wasm
These flags are very wasi-libc version specific, so updating wasi-libc may break the build. But supporting multiple wasi-libc versions in ruby doesn't have much benefit because wasi-libc is not installed in most systems.
configure.ac: setup build tools and register objects main.c: wrap main with rb_wasm_rt_start to handle asyncify unwinds tool/m4/ruby_wasm_tools.m4: setup default command based on WASI_SDK_PATH environment variable. checks wasm-opt which is used for asyncify. tool/wasm-clangw wasm/wasm-opt: a clang wrapper which replaces real wasm-opt with do-nothing wasm-opt to avoid misoptimization before asyncify. asyncify is performed at POSTLINK, but clang linker driver tries to run optimization by wasm-opt unconditionally. inlining pass at wasm level breaks asyncify's assumption, so should not optimize before POSTLIK. wasm/GNUmakefile.in: wasm specific rules to compile objects
set the default coroutine_type as asyncify when wasi
WASI currently does not yet support signal
WebAssembly has function local infinite registers and stack values, but there is no way to scan the values in a call stack for now. This implementation uses Asyncify to spilling out wasm locals into linear memory.
This implementation does nothing around preemptive context switching because there is no native thread.
Add a hook point to initialize extra extension libraries. The default hook function is replaced when linking a strong `Init_extra_exts` symbol. A builder can insert an object file that defines Init_extra_exts by XLDFLAGS.
WASI doesn't support spawning a new process for now.
RB_WAITFD_PRI uses POLLPRI for other platforms, but wasi-libc doesn't have POLLPRI for now.
74ed76e to
f91b794
Compare
|
Hello, I am trying to follow the build instruction in the comment, but I get the following error while running Output of Output of Does there any steps I have missed? Thanks! |
|
@supechicken It seems you're trying to build an unsupported ext |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
@supechicken @eat4toast Can you file your question to https://bugs.ruby-lang.org/ ? This tracker is not support space. |
Sorry, I will move the question. |
|
I think the instruction document below to run Ruby with WebAssembly support, created in this PR is useful for someone to try to do. So, let me put the link here. Because this PR URL is referred from the release note. |

WebAssembly / WASI port of Ruby
How to cross-build
Requirement
Steps
WASI_SDK_PATHenvironment variable to the root directory of the WASI SDK package.$ export WASI_SDK_PATH=/path/to/wasi-sdk-X.Y$ export PATH=path/to/binaryen:$PATHOut of bounds memory accesswhile running the produced ruby, you may need to increase the maximum size of stack.$ make installNow 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
Current Limitation
Threadsupport for now.Kernel.spawnandKernel.system