Skip to content

Commit

Permalink
Fix @bytecodealliance/preview2-shim compatibility
Browse files Browse the repository at this point in the history
By disabling sockets and adding http handlers, we can run the tests
  • Loading branch information
kateinoigakukun committed Jun 28, 2024
1 parent 833cb01 commit 7fb033d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ext/ruby_wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ impl WasiVirt {
fn allow_all(&self) -> Result<(), Error> {
self.virt(|virt| {
virt.allow_all();
// Disable sockets for now since `sockets/ip-name-lookup` is not
// supported by @bytecodealliance/preview2-shim yet
virt.sockets(false);
Ok(())
})
}
Expand Down
5 changes: 4 additions & 1 deletion packages/npm-packages/ruby-wasm-wasi/test/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async function initComponentRubyVM({ suppressStderr } = { suppressStderr: false
return module;
}
const vm = await RubyVM._instantiate(async (jsRuntime) => {
const { cli, clocks, filesystem, io, random, sockets } = preview2Shim;
const { cli, clocks, filesystem, io, random, sockets, http } = preview2Shim;
if (process.env.RUBY_BUILD_ROOT) {
filesystem._setPreopens({
"/usr": path.join(process.env.RUBY_BUILD_ROOT, "usr"),
Expand Down Expand Up @@ -103,6 +103,9 @@ async function initComponentRubyVM({ suppressStderr } = { suppressStderr: false
"wasi:io/streams": io.streams,
"wasi:random/random": random.random,
"wasi:sockets/tcp": sockets.tcp,
"wasi:http/types": http.types,
"wasi:http/incoming-handler": http.incomingHandler,
"wasi:http/outgoing-handler": http.outgoingHandler,
})
return root.rubyRuntime;
}, {})
Expand Down
5 changes: 4 additions & 1 deletion packages/npm-packages/ruby-wasm-wasi/tools/run-test-unit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const instantiateComponent = async (rootTestFile) => {
return WebAssembly.compile(buffer);
}
const vm = await RubyVM._instantiate(async (jsRuntime) => {
const { cli, clocks, filesystem, io, random, sockets } = preview2Shim;
const { cli, clocks, filesystem, io, random, sockets, http } = preview2Shim;
const dirname = path.dirname(new URL(import.meta.url).pathname);
const preopens = { "/__root__": path.join(dirname, "..") };
if (process.env.RUBY_ROOT) {
Expand Down Expand Up @@ -66,6 +66,9 @@ const instantiateComponent = async (rootTestFile) => {
"wasi:io/streams": io.streams,
"wasi:random/random": random.random,
"wasi:sockets/tcp": sockets.tcp,
"wasi:http/types": http.types,
"wasi:http/incoming-handler": http.incomingHandler,
"wasi:http/outgoing-handler": http.outgoingHandler,
})
return root.rubyRuntime;
}, {
Expand Down

0 comments on commit 7fb033d

Please sign in to comment.