Skip to content

Commit c8015aa

Browse files
Use wasi-virt for componentized binaries
1 parent 1c23a33 commit c8015aa

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/ruby_wasm/packager.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def package(executor, dest_dir, options)
4444
fs.remove_stdlib(executor)
4545
end
4646

47-
if full_build_options[:target] == "wasm32-unknown-wasip1" && !features.support_dynamic_linking?
47+
if full_build_options[:target] == "wasm32-unknown-wasip1" && !features.support_component_model?
4848
# wasi-vfs supports only WASI target
4949
wasi_vfs = RubyWasmExt::WasiVfs.new
5050
wasi_vfs.map_dir("/bundle", fs.bundle_dir)
@@ -54,6 +54,27 @@ def package(executor, dest_dir, options)
5454
end
5555
wasm_bytes = ruby_core.link_gem_exts(executor, fs.ruby_root, fs.bundle_dir, wasm_bytes)
5656

57+
if features.support_component_model?
58+
tmp_file = "tmp/ruby.component.wasm"
59+
tmp_virt_file = "tmp/ruby.component.virt.wasm"
60+
File.write(tmp_file, wasm_bytes)
61+
args = [
62+
"wasi-virt", "--stderr=allow",
63+
"--allow-random", "--allow-clocks", "--allow-exit",
64+
"--stdout=allow", "--stdin=allow",
65+
"--allow-all",
66+
"--debug"
67+
]
68+
[["/bundle", fs.bundle_dir], ["/usr", File.dirname(fs.ruby_root)]].each do |guest, host|
69+
args += ["--mount", "#{guest}=#{host}"]
70+
end
71+
args += ["--out", tmp_virt_file]
72+
args += [tmp_file]
73+
74+
executor.system(*args)
75+
wasm_bytes = File.binread(tmp_virt_file)
76+
end
77+
5778
wasm_bytes = RubyWasmExt.preinitialize(wasm_bytes) if options[:optimize]
5879
wasm_bytes
5980
end

lib/ruby_wasm/packager/core.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ def derive_build
306306
return @build if @build
307307
__skip__ = build ||= RubyWasm::Build.new(
308308
name, **@packager.full_build_options, target: target,
309+
wasi_vfs: nil
309310
)
310311
build.crossruby.user_exts = user_exts(build)
311312
# Emscripten uses --global-base=1024 by default, but it conflicts with

0 commit comments

Comments
 (0)