@@ -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
0 commit comments