@@ -44,7 +44,7 @@ def package(executor, dest_dir, options)
44
44
fs . remove_stdlib ( executor )
45
45
end
46
46
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 ?
48
48
# wasi-vfs supports only WASI target
49
49
wasi_vfs = RubyWasmExt ::WasiVfs . new
50
50
wasi_vfs . map_dir ( "/bundle" , fs . bundle_dir )
@@ -54,6 +54,27 @@ def package(executor, dest_dir, options)
54
54
end
55
55
wasm_bytes = ruby_core . link_gem_exts ( executor , fs . ruby_root , fs . bundle_dir , wasm_bytes )
56
56
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
+
57
78
wasm_bytes = RubyWasmExt . preinitialize ( wasm_bytes ) if options [ :optimize ]
58
79
wasm_bytes
59
80
end
0 commit comments