Skip to content

Commit a9fb5e2

Browse files
Apply wasi-vfs for Componentized version too
We will eventually use wasi-virt but for now, we use wasi-vfs for Componentized version too because we know that it works.
1 parent bb0127c commit a9fb5e2

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

lib/ruby_wasm/packager.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,22 @@ def package(executor, dest_dir, options)
2929

3030
fs = RubyWasm::Packager::FileSystem.new(dest_dir, self)
3131
fs.package_ruby_root(tarball, executor)
32-
wasm_bytes = ruby_core.build_and_link_exts(executor)
32+
33+
wasm_bytes = File.binread(File.join(fs.ruby_root, "bin", "ruby"))
3334

3435
fs.package_gems
3536
fs.remove_non_runtime_files(executor)
3637
fs.remove_stdlib(executor) unless options[:stdlib]
3738

38-
if full_build_options[:target] == "wasm32-unknown-wasip1" && !features.support_component_model?
39+
if full_build_options[:target] == "wasm32-unknown-wasip1"
3940
# wasi-vfs supports only WASI target
4041
wasi_vfs = RubyWasmExt::WasiVfs.new
4142
wasi_vfs.map_dir("/bundle", fs.bundle_dir)
4243
wasi_vfs.map_dir("/usr", File.dirname(fs.ruby_root))
4344

4445
wasm_bytes = wasi_vfs.pack(wasm_bytes)
4546
end
47+
wasm_bytes = ruby_core.build_and_link_exts(executor, wasm_bytes)
4648

4749
wasm_bytes = RubyWasmExt.preinitialize(wasm_bytes) if options[:optimize]
4850
wasm_bytes

lib/ruby_wasm/packager/core.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def build(executor, options)
3737
raise NotImplementedError
3838
end
3939

40-
def build_and_link_exts(executor)
40+
def build_and_link_exts(executor, module_bytes)
4141
raise NotImplementedError
4242
end
4343

@@ -93,7 +93,7 @@ def build(executor, options)
9393
build.crossruby.artifact
9494
end
9595

96-
def build_and_link_exts(executor)
96+
def build_and_link_exts(executor, module_bytes)
9797
build = derive_build
9898
self.build_exts(executor, build)
9999
self.link_exts(executor, build)
@@ -276,7 +276,6 @@ def derive_build
276276
return @build if @build
277277
__skip__ = build ||= RubyWasm::Build.new(
278278
name, **@packager.full_build_options, target: target,
279-
wasi_vfs: @packager.features.support_component_model? ? nil : :default
280279
)
281280
build.crossruby.user_exts = user_exts(build)
282281
# Emscripten uses --global-base=1024 by default, but it conflicts with
@@ -302,10 +301,7 @@ def derive_build
302301
build
303302
end
304303

305-
def build_and_link_exts(executor)
306-
build = derive_build
307-
ruby_root = build.crossruby.dest_dir
308-
module_bytes = File.binread(File.join(ruby_root, "usr", "local", "bin", "ruby"))
304+
def build_and_link_exts(executor, module_bytes)
309305
return module_bytes unless @packager.features.support_component_model?
310306

311307
linker = RubyWasmExt::ComponentEncode.new

sig/ruby_wasm/packager.rbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class RubyWasm::Packager
5656
@packager: RubyWasm::Packager
5757
def initialize: (RubyWasm::Packager) -> void
5858
def build: (RubyWasm::BuildExecutor, untyped options) -> String
59-
def build_and_link_exts: (RubyWasm::BuildExecutor) -> bytes
59+
def build_and_link_exts: (RubyWasm::BuildExecutor, bytes module_bytes) -> bytes
6060

6161
extend Forwardable
6262

@@ -72,7 +72,7 @@ class RubyWasm::Packager
7272
def initialize: (RubyWasm::Packager) -> void
7373
def build: (RubyWasm::BuildExecutor, untyped options) -> String
7474
def specs_with_extensions: () -> Array[[untyped, Array[string]]]
75-
def build_and_link_exts: (RubyWasm::BuildExecutor) -> bytes
75+
def build_and_link_exts: (RubyWasm::BuildExecutor, bytes module_bytes) -> bytes
7676
end
7777

7878
class DynamicLinking < RubyWasm::Packager::Core::BuildStrategy

0 commit comments

Comments
 (0)