Skip to content

Commit 7fb033d

Browse files
Fix @bytecodealliance/preview2-shim compatibility
By disabling sockets and adding http handlers, we can run the tests
1 parent 833cb01 commit 7fb033d

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

ext/ruby_wasm/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ impl WasiVirt {
249249
fn allow_all(&self) -> Result<(), Error> {
250250
self.virt(|virt| {
251251
virt.allow_all();
252+
// Disable sockets for now since `sockets/ip-name-lookup` is not
253+
// supported by @bytecodealliance/preview2-shim yet
254+
virt.sockets(false);
252255
Ok(())
253256
})
254257
}

packages/npm-packages/ruby-wasm-wasi/test/init.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async function initComponentRubyVM({ suppressStderr } = { suppressStderr: false
7373
return module;
7474
}
7575
const vm = await RubyVM._instantiate(async (jsRuntime) => {
76-
const { cli, clocks, filesystem, io, random, sockets } = preview2Shim;
76+
const { cli, clocks, filesystem, io, random, sockets, http } = preview2Shim;
7777
if (process.env.RUBY_BUILD_ROOT) {
7878
filesystem._setPreopens({
7979
"/usr": path.join(process.env.RUBY_BUILD_ROOT, "usr"),
@@ -103,6 +103,9 @@ async function initComponentRubyVM({ suppressStderr } = { suppressStderr: false
103103
"wasi:io/streams": io.streams,
104104
"wasi:random/random": random.random,
105105
"wasi:sockets/tcp": sockets.tcp,
106+
"wasi:http/types": http.types,
107+
"wasi:http/incoming-handler": http.incomingHandler,
108+
"wasi:http/outgoing-handler": http.outgoingHandler,
106109
})
107110
return root.rubyRuntime;
108111
}, {})

packages/npm-packages/ruby-wasm-wasi/tools/run-test-unit.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const instantiateComponent = async (rootTestFile) => {
3535
return WebAssembly.compile(buffer);
3636
}
3737
const vm = await RubyVM._instantiate(async (jsRuntime) => {
38-
const { cli, clocks, filesystem, io, random, sockets } = preview2Shim;
38+
const { cli, clocks, filesystem, io, random, sockets, http } = preview2Shim;
3939
const dirname = path.dirname(new URL(import.meta.url).pathname);
4040
const preopens = { "/__root__": path.join(dirname, "..") };
4141
if (process.env.RUBY_ROOT) {
@@ -66,6 +66,9 @@ const instantiateComponent = async (rootTestFile) => {
6666
"wasi:io/streams": io.streams,
6767
"wasi:random/random": random.random,
6868
"wasi:sockets/tcp": sockets.tcp,
69+
"wasi:http/types": http.types,
70+
"wasi:http/incoming-handler": http.incomingHandler,
71+
"wasi:http/outgoing-handler": http.outgoingHandler,
6972
})
7073
return root.rubyRuntime;
7174
}, {

0 commit comments

Comments
 (0)