Skip to content

Commit 54ee0d5

Browse files
Make RUBY_BUILD_ROOT optional with component model setup
1 parent b842a82 commit 54ee0d5

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ async function initComponentRubyVM({ suppressStderr } = { suppressStderr: false
7474
}
7575
const vm = await RubyVM._instantiate(async (jsRuntime) => {
7676
const { cli, clocks, filesystem, io, random, sockets } = preview2Shim;
77-
filesystem._setPreopens({
78-
"/usr": path.join(process.env.RUBY_BUILD_ROOT, "usr"),
79-
"/bundle": path.join(process.env.RUBY_BUILD_ROOT, "bundle"),
80-
})
77+
if (process.env.RUBY_BUILD_ROOT) {
78+
filesystem._setPreopens({
79+
"/usr": path.join(process.env.RUBY_BUILD_ROOT, "usr"),
80+
"/bundle": path.join(process.env.RUBY_BUILD_ROOT, "bundle"),
81+
})
82+
}
8183
cli._setArgs(["ruby.wasm"].concat(process.argv.slice(2)));
8284
cli._setCwd("/")
8385
const root = await instantiate(getCoreModule, {

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ const instantiateComponent = async (rootTestFile) => {
3737
const vm = await RubyVM._instantiate(async (jsRuntime) => {
3838
const { cli, clocks, filesystem, io, random, sockets } = preview2Shim;
3939
const dirname = path.dirname(new URL(import.meta.url).pathname);
40-
filesystem._setPreopens({
41-
"/__root__": path.join(dirname, ".."),
42-
"/usr": path.join(process.env.RUBY_BUILD_ROOT, "usr"),
43-
"/bundle": path.join(process.env.RUBY_BUILD_ROOT, "bundle"),
44-
})
40+
const preopens = { "/__root__": path.join(dirname, "..") };
41+
if (process.env.RUBY_ROOT) {
42+
preopens["/usr"] = path.join(process.env.RUBY_ROOT, "usr");
43+
preopens["/bundle"] = path.join(process.env.RUBY_ROOT, "bundle");
44+
}
45+
filesystem._setPreopens(preopens);
4546
cli._setArgs(["ruby.wasm"].concat(process.argv.slice(2)));
4647
cli._setCwd("/")
4748
const root = await instantiate(getCoreModule, {

0 commit comments

Comments
 (0)