ruby_wasm 2.5.0.pre.1 → 2.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +13 -9
  3. data/Cargo.lock +705 -451
  4. data/Gemfile +1 -1
  5. data/README.md +12 -19
  6. data/Rakefile +9 -9
  7. data/benchmarks/vm_deep_call.rb +2 -2
  8. data/docs/cheat_sheet.md +8 -8
  9. data/ext/ruby_wasm/Cargo.toml +6 -5
  10. data/ext/ruby_wasm/src/lib.rs +208 -7
  11. data/lib/ruby_wasm/build/executor.rb +4 -0
  12. data/lib/ruby_wasm/build/product/crossruby.rb +57 -23
  13. data/lib/ruby_wasm/build/product/libyaml.rb +5 -3
  14. data/lib/ruby_wasm/build/product/openssl.rb +7 -2
  15. data/lib/ruby_wasm/build/product/product.rb +3 -3
  16. data/lib/ruby_wasm/build/product/ruby_source.rb +3 -3
  17. data/lib/ruby_wasm/build/product/wasi_vfs.rb +1 -39
  18. data/lib/ruby_wasm/build/product/zlib.rb +5 -3
  19. data/lib/ruby_wasm/build/target.rb +24 -0
  20. data/lib/ruby_wasm/build/toolchain.rb +1 -1
  21. data/lib/ruby_wasm/build.rb +7 -3
  22. data/lib/ruby_wasm/cli.rb +171 -13
  23. data/lib/ruby_wasm/feature_set.rb +30 -0
  24. data/lib/ruby_wasm/packager/component_adapter/wasi_snapshot_preview1.command.wasm +0 -0
  25. data/lib/ruby_wasm/packager/component_adapter/wasi_snapshot_preview1.reactor.wasm +0 -0
  26. data/lib/ruby_wasm/packager/component_adapter.rb +14 -0
  27. data/lib/ruby_wasm/packager/core.rb +192 -4
  28. data/lib/ruby_wasm/packager/file_system.rb +20 -17
  29. data/lib/ruby_wasm/packager.rb +21 -83
  30. data/lib/ruby_wasm/rake_task.rb +2 -0
  31. data/lib/ruby_wasm/version.rb +1 -1
  32. data/lib/ruby_wasm.rb +2 -0
  33. data/package-lock.json +410 -133
  34. data/package.json +3 -3
  35. data/{tasks → rakelib}/ci.rake +3 -3
  36. data/{tasks → rakelib}/doc.rake +6 -1
  37. data/{tasks → rakelib}/format.rake +3 -2
  38. data/{tasks → rakelib}/gem.rake +4 -1
  39. data/{tasks → rakelib}/packaging.rake +34 -17
  40. data/{tasks → rakelib}/version.rake +2 -0
  41. data/sig/ruby_wasm/build.rbs +36 -31
  42. data/sig/ruby_wasm/cli.rbs +30 -3
  43. data/sig/ruby_wasm/ext.rbs +28 -3
  44. data/sig/ruby_wasm/feature_set.rbs +12 -0
  45. data/sig/ruby_wasm/packager.rbs +44 -7
  46. metadata +16 -15
  47. data/builders/wasm32-unknown-emscripten/Dockerfile +0 -43
  48. data/builders/wasm32-unknown-emscripten/entrypoint.sh +0 -7
  49. data/builders/wasm32-unknown-wasi/Dockerfile +0 -47
  50. data/builders/wasm32-unknown-wasi/entrypoint.sh +0 -7
  51. data/ruby_wasm.gemspec +0 -32
  52. /data/{tasks → rakelib}/check.rake +0 -0
data/package.json CHANGED
@@ -5,8 +5,8 @@
5
5
  "packages/npm-packages/*"
6
6
  ],
7
7
  "devDependencies": {
8
- "@playwright/test": "^1.40.1",
9
- "@rollup/plugin-json": "^6.0.1",
10
- "rollup": "^4.6.1"
8
+ "@playwright/test": "^1.42.1",
9
+ "@rollup/plugin-json": "^6.1.0",
10
+ "rollup": "^4.13.2"
11
11
  }
12
12
  }
@@ -1,7 +1,7 @@
1
1
  def latest_build_sources
2
2
  BUILD_SOURCES
3
3
  .filter_map do |name|
4
- src = RubyWasm::Packager.build_source_aliases(LIB_ROOT)[name]
4
+ src = RubyWasm::CLI.build_source_aliases(LIB_ROOT)[name]
5
5
  case src[:type]
6
6
  when "github"
7
7
  url = "repos/#{src[:repo]}/commits/#{src[:rev]}"
@@ -23,7 +23,7 @@ def release_note
23
23
  EOS
24
24
 
25
25
  BUILD_SOURCES.each do |name|
26
- source = RubyWasm::Packager.build_source_aliases(LIB_ROOT)[name]
26
+ source = RubyWasm::CLI.build_source_aliases(LIB_ROOT)[name]
27
27
  case source[:type]
28
28
  when "github"
29
29
  output +=
@@ -86,7 +86,7 @@ def rake_task_matrix
86
86
  task: "standalone:#{pkg[:name]}",
87
87
  artifact: "packages/standalone/#{pkg[:name]}/dist",
88
88
  artifact_name: "standalone-#{pkg[:name]}",
89
- builder: "wasm32-unknown-wasi",
89
+ builder: "wasm32-unknown-wasip1",
90
90
  rubies_cache_key: ruby_cache_keys[pkg[:build]]
91
91
  }
92
92
  end
@@ -4,7 +4,12 @@ require "ruby_wasm/version"
4
4
  RDoc::Task.new do |doc|
5
5
  doc.main = "README.md"
6
6
  doc.title = "ruby.wasm Documentation"
7
- doc.rdoc_files = FileList.new %w[*.md ext/**/*.c ext/**/*.rb]
7
+ doc.rdoc_files =
8
+ FileList.new %w[
9
+ *.md
10
+ packages/gems/js/ext/**/*.c
11
+ packages/gems/js/lib/**/*.rb
12
+ ]
8
13
  end
9
14
 
10
15
  namespace :doc do
@@ -7,7 +7,8 @@ namespace :format do
7
7
  "Rakefile",
8
8
  "lib/**/*.rb",
9
9
  "ext/**/*.rb",
10
- "tasks/**/*.rake",
10
+ "test/**/*.rb",
11
+ "rakelib/**/*.rake",
11
12
  "packages/**/*.rb"
12
13
  ]
13
14
  )
@@ -19,7 +20,7 @@ namespace :format do
19
20
  end
20
21
 
21
22
  task :c do
22
- sh "find ./ext -iname *.h -o -iname *.c | xargs clang-format -i"
23
+ sh "find packages/gems/ ext/ -iname *.h -o -iname *.c | xargs clang-format -i"
23
24
  end
24
25
  end
25
26
 
@@ -10,7 +10,10 @@ end
10
10
  begin
11
11
  require "rb_sys/extensiontask"
12
12
 
13
- RbSys::ExtensionTask.new("ruby_wasm") { |ext| ext.lib_dir = "lib/ruby_wasm" }
13
+ gemspec = Gem::Specification.load("ruby_wasm.gemspec")
14
+ RbSys::ExtensionTask.new("ruby_wasm", gemspec) do |ext|
15
+ ext.lib_dir = "lib/ruby_wasm"
16
+ end
14
17
  rescue LoadError => e
15
18
  task :compile do
16
19
  $stderr.puts "Skipping compilation of ruby_wasm extension: #{e.message}"
@@ -1,11 +1,13 @@
1
1
  wasi_vfs = RubyWasm::WasiVfsProduct.new(File.join(Dir.pwd, "build"))
2
2
  wasi_sdk = TOOLCHAINS["wasi-sdk"]
3
3
  tools = {
4
- "WASI_VFS_CLI" => wasi_vfs.cli_bin_path,
4
+ "WASI_VFS_CLI" => File.expand_path(File.join(__dir__, "..", "exe", "rbwasm")),
5
5
  "WASMOPT" => wasi_sdk.wasm_opt
6
6
  }
7
7
 
8
8
  def npm_pkg_build_command(pkg)
9
+ # Skip if the package does not require building ruby
10
+ return nil unless pkg[:ruby_version] && pkg[:target]
9
11
  [
10
12
  "bundle",
11
13
  "exec",
@@ -22,6 +24,7 @@ end
22
24
 
23
25
  def npm_pkg_rubies_cache_key(pkg)
24
26
  build_command = npm_pkg_build_command(pkg)
27
+ return nil unless build_command
25
28
  require "open3"
26
29
  cmd = build_command + ["--print-ruby-cache-key"]
27
30
  stdout, status = Open3.capture2(*cmd)
@@ -38,16 +41,19 @@ namespace :npm do
38
41
  pkg_dir = "#{Dir.pwd}/packages/npm-packages/#{pkg[:name]}"
39
42
 
40
43
  namespace pkg[:name] do
41
- build_command = npm_pkg_build_command(pkg)
42
-
43
44
  desc "Build ruby for npm package #{pkg[:name]}"
44
45
  task "ruby" do
46
+ build_command = npm_pkg_build_command(pkg)
47
+ # Skip if the package does not require building ruby
48
+ next unless build_command
49
+
45
50
  env = {
46
51
  # Share ./build and ./rubies in the same workspace
47
52
  "RUBY_WASM_ROOT" => base_dir
48
53
  }
54
+ cwd = nil
49
55
  if gemfile_path = pkg[:gemfile]
50
- env["BUNDLE_GEMFILE"] = File.join(base_dir, gemfile_path)
56
+ cwd = File.dirname(gemfile_path)
51
57
  else
52
58
  # Explicitly disable rubygems integration since Bundler finds
53
59
  # Gemfile in the repo root directory.
@@ -55,16 +61,18 @@ namespace :npm do
55
61
  end
56
62
  dist_dir = File.join(pkg_dir, "dist")
57
63
  mkdir_p dist_dir
58
- if pkg[:target] == "wasm32-unknown-wasi"
59
- sh env,
60
- *build_command,
61
- "--no-stdlib",
62
- "-o",
63
- File.join(dist_dir, "ruby.wasm")
64
- sh env,
65
- *build_command,
66
- "-o",
67
- File.join(dist_dir, "ruby.debug+stdlib.wasm")
64
+ if pkg[:target].start_with?("wasm32-unknown-wasi")
65
+ Dir.chdir(cwd || base_dir) do
66
+ sh env,
67
+ *build_command,
68
+ "--no-stdlib",
69
+ "-o",
70
+ File.join(dist_dir, "ruby.wasm")
71
+ sh env,
72
+ *build_command,
73
+ "-o",
74
+ File.join(dist_dir, "ruby.debug+stdlib.wasm")
75
+ end
68
76
  sh wasi_sdk.wasm_opt,
69
77
  "--strip-debug",
70
78
  File.join(dist_dir, "ruby.wasm"),
@@ -76,7 +84,9 @@ namespace :npm do
76
84
  "-o",
77
85
  File.join(dist_dir, "ruby+stdlib.wasm")
78
86
  elsif pkg[:target] == "wasm32-unknown-emscripten"
79
- sh env, *build_command, "-o", "/dev/null"
87
+ Dir.chdir(cwd || base_dir) do
88
+ sh env, *build_command, "-o", "/dev/null"
89
+ end
80
90
  end
81
91
  end
82
92
 
@@ -93,7 +103,6 @@ namespace :npm do
93
103
 
94
104
  desc "Make tarball for npm package #{pkg[:name]}"
95
105
  task pkg[:name] do
96
- wasi_vfs.install_cli
97
106
  wasi_sdk.install_binaryen
98
107
  Rake::Task["npm:#{pkg[:name]}:build"].invoke
99
108
  sh "npm pack", chdir: pkg_dir
@@ -137,7 +146,6 @@ namespace :standalone do
137
146
 
138
147
  desc "Build standalone package #{pkg[:name]}"
139
148
  task "#{pkg[:name]}" => ["build:#{pkg[:build]}"] do
140
- wasi_vfs.install_cli
141
149
  wasi_sdk.install_binaryen
142
150
  base_dir = Dir.pwd
143
151
  sh tools,
@@ -146,3 +154,12 @@ namespace :standalone do
146
154
  end
147
155
  end
148
156
  end
157
+
158
+ namespace :gem do
159
+ task :update_component_adapters do
160
+ ["command", "reactor"].each do |exec_model|
161
+ sh "curl", "-L", "-o", "lib/ruby_wasm/packager/component_adapter/wasi_snapshot_preview1.#{exec_model}.wasm",
162
+ "https://github.com/bytecodealliance/wasmtime/releases/download/v19.0.1/wasi_snapshot_preview1.#{exec_model}.wasm"
163
+ end
164
+ end
165
+ end
@@ -35,4 +35,6 @@ task :bump_version, %i[version] do |t, args|
35
35
  NPM_PACKAGES.each { |pkg| bump_version_npm_package(pkg[:name], version) }
36
36
  # Update ./package-lock.json
37
37
  sh "npm install"
38
+ # Update Gemfile.lock
39
+ sh "BUNDLE_GEMFILE=packages/npm-packages/ruby-wasm-wasi/Gemfile bundle install"
38
40
  end
@@ -5,17 +5,29 @@ module RubyWasm
5
5
  def cache_key: (Digest::SHA256 digest) -> void
6
6
  end
7
7
 
8
+ class Target
9
+ include _Cacheable
10
+
11
+ @triple: String
12
+ @pic: bool
13
+
14
+ attr_reader triple: String
15
+
16
+ def initialize: (String triple, ?pic: bool) -> void
17
+ def pic?: -> bool
18
+ end
19
+
8
20
  class Build
9
21
  include _Cacheable
10
22
 
11
- @target: String
23
+ @target: Target
12
24
  @build_dir: String
13
25
  @rubies_dir: String
14
26
  @toolchain: Toolchain
15
27
  @libyaml: LibYAMLProduct
16
28
  @zlib: ZlibProduct
17
29
  @openssl: OpenSSLProduct
18
- @wasi_vfs: WasiVfsProduct
30
+ @wasi_vfs: WasiVfsProduct?
19
31
  @baseruby: BaseRubyProduct
20
32
  @crossruby: CrossRubyProduct
21
33
  @source: BuildSource
@@ -24,11 +36,12 @@ module RubyWasm
24
36
 
25
37
  def initialize: (
26
38
  string name,
27
- target: String,
39
+ target: Target,
28
40
  src: Packager::build_source,
29
41
  toolchain: Toolchain?,
30
42
  build_dir: string,
31
43
  rubies_dir: string,
44
+ ?wasi_vfs: :default | WasiVfsProduct?,
32
45
  **untyped
33
46
  ) -> void
34
47
  def crossruby: () -> CrossRubyProduct
@@ -36,10 +49,10 @@ module RubyWasm
36
49
 
37
50
  class BuildParams
38
51
  attr_accessor name: String
39
- attr_accessor target: String
52
+ attr_accessor target: Target
40
53
  attr_accessor default_exts: String
41
54
 
42
- def initialize: (name: string, target: string, default_exts: string) -> void
55
+ def initialize: (name: string, target: Target, default_exts: string) -> void
43
56
  end
44
57
 
45
58
  class BuildProduct
@@ -47,10 +60,10 @@ module RubyWasm
47
60
  end
48
61
 
49
62
  class AutoconfProduct < BuildProduct
50
- @target: String
63
+ @target: Target
51
64
  @toolchain: Toolchain
52
65
 
53
- def initialize: (String target, Toolchain toolchain) -> void
66
+ def initialize: (Target target, Toolchain toolchain) -> void
54
67
  def system_triplet_args: -> Array[String]
55
68
  | -> Array[String]
56
69
  def tools_args: -> Array[String]
@@ -88,8 +101,8 @@ module RubyWasm
88
101
  ZLIB_VERSION: String
89
102
  @build_dir: String
90
103
 
91
- attr_reader target: String
92
- def initialize: (String build_dir, String target, Toolchain toolchain) -> void
104
+ attr_reader target: Target
105
+ def initialize: (String build_dir, Target target, Toolchain toolchain) -> void
93
106
  def product_build_dir: -> String
94
107
  def destdir: -> String
95
108
  def install_root: -> String
@@ -102,8 +115,8 @@ module RubyWasm
102
115
  LIBYAML_VERSION: String
103
116
  @build_dir: String
104
117
 
105
- attr_reader target: String
106
- def initialize: (String build_dir, String target, Toolchain toolchain) -> void
118
+ attr_reader target: Target
119
+ def initialize: (String build_dir, Target target, Toolchain toolchain) -> void
107
120
  def product_build_dir: -> String
108
121
  def destdir: -> String
109
122
  def install_root: -> String
@@ -115,8 +128,8 @@ module RubyWasm
115
128
  OPENSSL_VERSION: String
116
129
  @build_dir: String
117
130
 
118
- attr_reader target: String
119
- def initialize: (String build_dir, String target, Toolchain toolchain) -> void
131
+ attr_reader target: Target
132
+ def initialize: (String build_dir, Target target, Toolchain toolchain) -> void
120
133
  def product_build_dir: -> String
121
134
  def destdir: -> String
122
135
  def install_root: -> String
@@ -135,12 +148,8 @@ module RubyWasm
135
148
  def initialize: (String build_dir) -> void
136
149
  def lib_product_build_dir: -> String
137
150
  def lib_wasi_vfs_a: -> String
138
- def cli_product_build_dir: -> String
139
- def cli_bin_path: -> String
140
151
  def name: -> String
141
152
  def build: (BuildExecutor executor) -> void
142
- def install_cli: -> bool?
143
- def cli_download_url: -> String
144
153
  end
145
154
 
146
155
  class CrossRubyExtProduct < BuildProduct
@@ -161,6 +170,8 @@ module RubyWasm
161
170
  def build: (BuildExecutor executor, CrossRubyProduct crossruby) -> void
162
171
  def do_extconf: (BuildExecutor executor, CrossRubyProduct crossruby) -> void
163
172
  def do_install_rb: (BuildExecutor executor, CrossRubyProduct crossruby) -> void
173
+
174
+ private def do_legacy_extconf: (BuildExecutor executor, CrossRubyProduct crossruby) -> void
164
175
  end
165
176
 
166
177
  class CrossRubyProduct < AutoconfProduct
@@ -175,6 +186,7 @@ module RubyWasm
175
186
  @openssl: OpenSSLProduct
176
187
  @wasi_vfs: WasiVfsProduct
177
188
 
189
+ attr_reader target: Target
178
190
  attr_reader source: BuildSource
179
191
  attr_reader toolchain: Toolchain
180
192
  attr_accessor user_exts: Array[CrossRubyExtProduct]
@@ -187,6 +199,8 @@ module RubyWasm
187
199
  attr_accessor xldflags: Array[String]
188
200
  def initialize: (BuildParams params, String build_dir, String rubies_dir, BaseRubyProduct baseruby, BuildSource source, Toolchain toolchain) -> void
189
201
  def configure: (BuildExecutor executor, ?reconfigure: bool) -> void
202
+ def need_exts_build?: -> bool
203
+ def need_extinit_obj?: -> bool
190
204
  def build_exts: (BuildExecutor executor) -> void
191
205
  def build: (BuildExecutor executor, ?remake: bool, ?reconfigure: bool) -> void
192
206
  def clean: (BuildExecutor executor) -> void
@@ -195,7 +209,7 @@ module RubyWasm
195
209
  def ext_build_dir: -> String
196
210
  def with_libyaml: (LibYAMLProduct libyaml) -> LibYAMLProduct
197
211
  def with_zlib: (ZlibProduct zlib) -> ZlibProduct
198
- def with_wasi_vfs: (WasiVfsProduct wasi_vfs) -> WasiVfsProduct
212
+ def with_wasi_vfs: (WasiVfsProduct? wasi_vfs) -> WasiVfsProduct?
199
213
  def with_openssl: (OpenSSLProduct openssl) -> OpenSSLProduct
200
214
  def dest_dir: -> String
201
215
  def artifact: -> String
@@ -223,7 +237,7 @@ module RubyWasm
223
237
  def initialize: -> void
224
238
  def find_tool: (Symbol name) -> String
225
239
  def check_envvar: (untyped name) -> void
226
- def self.get: (String target, ?String? build_dir) -> (Toolchain)
240
+ def self.get: (Target target, ?String? build_dir) -> (Toolchain)
227
241
  def self.find_path: (String command) -> String?
228
242
  def self.check_executable: (String command) -> String
229
243
  def cc: -> String
@@ -277,6 +291,7 @@ module RubyWasm
277
291
  def cp_r: (FileUtils::pathlist src, path dest) -> void
278
292
  def mv: (FileUtils::pathlist src, path dest) -> void
279
293
  def mkdir_p: (FileUtils::pathlist list) -> void
294
+ def ln_s: (String src, String dest) -> void
280
295
  def write: (String path, _ToS data) -> void
281
296
 
282
297
  def begin_section: (Class klass, String name, String note) -> void
@@ -303,19 +318,9 @@ module RubyWasm
303
318
  end
304
319
 
305
320
  class BuildTask
306
- @build_dir: String
307
- @rubies_dir: String
308
- @openssl: OpenSSLProduct
309
-
321
+ @build: Build
310
322
  attr_accessor name: String
311
- attr_reader source: BuildSource
312
- attr_reader target: String
313
- attr_reader toolchain: Toolchain
314
- attr_reader libyaml: LibYAMLProduct
315
- attr_reader zlib: ZlibProduct
316
- attr_reader wasi_vfs: WasiVfsProduct
317
- attr_reader baseruby: BaseRubyProduct
318
- attr_reader crossruby: CrossRubyProduct
323
+
319
324
  def initialize: (String name, target: String, src: untyped, ?toolchain: Toolchain?, ?build_dir: String?, ?rubies_dir: String?, **untyped) -> void
320
325
  def hexdigest: -> String
321
326
  end
@@ -1,5 +1,25 @@
1
1
  module RubyWasm
2
2
  class CLI
3
+ type cli_options = {
4
+ print_ruby_cache_key: bool,
5
+ save_temps: bool,
6
+ output: String,
7
+
8
+ optimize: bool,
9
+ remake: bool,
10
+ reconfigure: bool,
11
+ clean: bool,
12
+
13
+ ruby_version: String,
14
+ target_triplet: String,
15
+ profile: String,
16
+ stdlib: bool,
17
+ disable_gems: bool,
18
+ gemfile: String?,
19
+ patches: Array[String],
20
+ format: String,
21
+ }
22
+
3
23
  DEFAULT_RUBIES_DIR: string
4
24
 
5
25
  @stdout: IO
@@ -8,14 +28,21 @@ module RubyWasm
8
28
  def initialize: (stdout: IO, stderr: IO) -> void
9
29
 
10
30
  def build: (Array[String] args) -> void
31
+ def pack: (Array[String] args) -> void
11
32
 
12
33
  private
13
34
 
14
- def build_config: (Hash[untyped, untyped] options) -> Hash[untyped, untyped]
35
+ def build_config: (cli_options options) -> Packager::build_config
36
+ def compute_build_source: (cli_options options) -> [Packager::build_source, String?]
37
+ def self.build_source_aliases: (string root) -> Hash[string, Packager::build_source]
38
+ def self.bundled_patches_path: () -> string
39
+ def root: () -> string
15
40
 
16
- def derive_packager: (Hash[untyped, untyped] options) -> Packager
41
+ def derive_packager: (cli_options options) -> Packager
17
42
  def do_print_ruby_cache_key: (Packager) -> void
18
- def do_build: (BuildExecutor, string tmpdir, Packager, Hash[untyped, untyped] options) -> void
43
+ def do_build: (BuildExecutor, string tmpdir, Packager, cli_options options) -> void
44
+
45
+ def require_extension: () -> void
19
46
  end
20
47
 
21
48
  self.@logger: Logger?
@@ -1,11 +1,36 @@
1
1
  module RubyWasmExt
2
- def self.preinitialize: (Array[Integer] module_bytes) -> Array[Integer]
2
+ type bytes = String
3
+
4
+ def self.preinitialize: (bytes module_bytes) -> bytes
3
5
 
4
6
  class WasiVfs
5
7
  def initialize: () -> void
6
8
 
9
+ def self.run_cli: (Array[String] args) -> void
10
+
7
11
  def map_dir: (String guest_path, String host_path) -> void
8
12
 
9
- def pack: (Array[Integer] module_bytes) -> Array[Integer]
13
+ def pack: (bytes module_bytes) -> bytes
14
+ end
15
+
16
+ class ComponentLink
17
+ def initialize: () -> void
18
+ def library: (String name, bytes module, bool dl_openable) -> void
19
+ def adapter: (String name, bytes module) -> void
20
+ def validate: (bool) -> void
21
+ def stack_size: (Integer) -> void
22
+ def stub_missing_functions: (bool) -> void
23
+ def use_built_in_libdl: (bool) -> void
24
+ def encode: () -> bytes
25
+ end
26
+
27
+ class ComponentEncode
28
+ def initialize: () -> void
29
+ def validate: (bool) -> void
30
+ def adapter: (String name, bytes module) -> void
31
+ def module: (bytes module) -> void
32
+ def realloc_via_memory_grow: (bool) -> void
33
+ def import_name_map: (Hash[String, String] map) -> void
34
+ def encode: () -> bytes
10
35
  end
11
- end
36
+ end
@@ -0,0 +1,12 @@
1
+ class RubyWasm::FeatureSet
2
+ @features: Hash[Symbol, bool]
3
+
4
+ def initialize: (Hash[Symbol, bool]) -> void
5
+
6
+ FEATURES: Hash[Symbol, String]
7
+
8
+ def self.derive_from_env: () -> RubyWasm::FeatureSet
9
+
10
+ def support_dynamic_linking?: () -> bool
11
+ def support_component_model?: () -> bool
12
+ end
@@ -1,11 +1,39 @@
1
1
 
2
2
  class RubyWasm::Packager
3
+ type build_source_github = {
4
+ type: "github",
5
+ repo: String,
6
+ rev: String,
7
+ }
8
+ type build_source_tarball = {
9
+ type: "tarball",
10
+ url: String,
11
+ }
12
+ type build_source_local = {
13
+ type: "local",
14
+ path: String,
15
+ }
16
+ type build_source = (build_source_github | build_source_tarball | build_source_local) & {
17
+ name: string,
18
+ patches: Array[String],
19
+ }
20
+
21
+ type build_config = {
22
+ target: String,
23
+ src: RubyWasm::Packager::build_source,
24
+ default_exts: String,
25
+ suffix: String,
26
+ }
27
+
28
+ type bytes = String
29
+
3
30
  @definition: untyped
4
- @config: Hash[untyped, untyped]
31
+ @config: build_config
32
+ @features: RubyWasm::FeatureSet
5
33
 
6
- def initialize: (untyped?, Hash[untyped, untyped]?) -> void
34
+ def initialize: (string root, build_config?, untyped? definition, features: RubyWasm::FeatureSet) -> void
7
35
 
8
- def package: (RubyWasm::BuildExecutor, string dest_dir, untyped options) -> Array[Integer]
36
+ def package: (RubyWasm::BuildExecutor, string dest_dir, untyped options) -> bytes
9
37
 
10
38
  @ruby_core_build: RubyWasm::Packager::Core?
11
39
  def ruby_core_build: () -> RubyWasm::Packager::Core
@@ -13,13 +41,10 @@ class RubyWasm::Packager
13
41
  EXCLUDED_GEMS: Array[string]
14
42
 
15
43
  def specs: () -> Array[untyped]
16
- def support_dynamic_linking?: () -> bool
44
+ def features: () -> RubyWasm::FeatureSet
17
45
 
18
46
  def root: () -> string
19
47
 
20
- type build_source = Hash[Symbol, (String | Array[String])]
21
- def self.build_source_aliases: (string root) -> Hash[string, build_source]
22
-
23
48
  ALL_DEFAULT_EXTS: string
24
49
 
25
50
  def build_options: () -> Hash[Symbol, untyped]
@@ -31,6 +56,7 @@ class RubyWasm::Packager
31
56
  @packager: RubyWasm::Packager
32
57
  def initialize: (RubyWasm::Packager) -> void
33
58
  def build: (RubyWasm::BuildExecutor, untyped options) -> String
59
+ def build_and_link_exts: (RubyWasm::BuildExecutor) -> bytes
34
60
 
35
61
  extend Forwardable
36
62
 
@@ -46,9 +72,16 @@ class RubyWasm::Packager
46
72
  def initialize: (RubyWasm::Packager) -> void
47
73
  def build: (RubyWasm::BuildExecutor, untyped options) -> String
48
74
  def specs_with_extensions: () -> Array[[untyped, Array[string]]]
75
+ def build_and_link_exts: (RubyWasm::BuildExecutor) -> bytes
49
76
  end
50
77
 
51
78
  class DynamicLinking < RubyWasm::Packager::Core::BuildStrategy
79
+ @build: RubyWasm::Build
80
+ def derive_build: () -> RubyWasm::Build
81
+ def build_exts: (RubyWasm::BuildExecutor, RubyWasm::Build) -> void
82
+ def name: () -> string
83
+
84
+ private def link_exts: (RubyWasm::BuildExecutor, RubyWasm::Build) -> bytes
52
85
  end
53
86
 
54
87
  class StaticLinking < RubyWasm::Packager::Core::BuildStrategy
@@ -88,4 +121,8 @@ class RubyWasm::Packager
88
121
  def ruby_version: () -> String
89
122
  def rubyarchdir: () -> String
90
123
  end
124
+
125
+ module ComponentAdapter
126
+ def self.wasi_snapshot_preview1: (String exec_model) -> String
127
+ end
91
128
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_wasm
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0.pre.1
4
+ version: 2.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuta Saito
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-04 00:00:00.000000000 Z
11
+ date: 2024-04-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby to WebAssembly toolkit. This gem takes Ruby code and Gemfile, and
14
14
  packages them with Ruby runtime into a WebAssembly binary.
@@ -31,10 +31,6 @@ files:
31
31
  - Rakefile
32
32
  - Steepfile
33
33
  - benchmarks/vm_deep_call.rb
34
- - builders/wasm32-unknown-emscripten/Dockerfile
35
- - builders/wasm32-unknown-emscripten/entrypoint.sh
36
- - builders/wasm32-unknown-wasi/Dockerfile
37
- - builders/wasm32-unknown-wasi/entrypoint.sh
38
34
  - docs/api.md
39
35
  - docs/cheat_sheet.md
40
36
  - docs/faq.md
@@ -59,10 +55,15 @@ files:
59
55
  - lib/ruby_wasm/build/product/ruby_source.rb
60
56
  - lib/ruby_wasm/build/product/wasi_vfs.rb
61
57
  - lib/ruby_wasm/build/product/zlib.rb
58
+ - lib/ruby_wasm/build/target.rb
62
59
  - lib/ruby_wasm/build/toolchain.rb
63
60
  - lib/ruby_wasm/build/toolchain/wit_bindgen.rb
64
61
  - lib/ruby_wasm/cli.rb
62
+ - lib/ruby_wasm/feature_set.rb
65
63
  - lib/ruby_wasm/packager.rb
64
+ - lib/ruby_wasm/packager/component_adapter.rb
65
+ - lib/ruby_wasm/packager/component_adapter/wasi_snapshot_preview1.command.wasm
66
+ - lib/ruby_wasm/packager/component_adapter/wasi_snapshot_preview1.reactor.wasm
66
67
  - lib/ruby_wasm/packager/core.rb
67
68
  - lib/ruby_wasm/packager/file_system.rb
68
69
  - lib/ruby_wasm/rake_task.rb
@@ -70,20 +71,20 @@ files:
70
71
  - lib/ruby_wasm/version.rb
71
72
  - package-lock.json
72
73
  - package.json
73
- - ruby_wasm.gemspec
74
+ - rakelib/check.rake
75
+ - rakelib/ci.rake
76
+ - rakelib/doc.rake
77
+ - rakelib/format.rake
78
+ - rakelib/gem.rake
79
+ - rakelib/packaging.rake
80
+ - rakelib/version.rake
74
81
  - sig/open_uri.rbs
75
82
  - sig/ruby_wasm/build.rbs
76
83
  - sig/ruby_wasm/cli.rbs
77
84
  - sig/ruby_wasm/ext.rbs
85
+ - sig/ruby_wasm/feature_set.rbs
78
86
  - sig/ruby_wasm/packager.rbs
79
87
  - sig/ruby_wasm/util.rbs
80
- - tasks/check.rake
81
- - tasks/ci.rake
82
- - tasks/doc.rake
83
- - tasks/format.rake
84
- - tasks/gem.rake
85
- - tasks/packaging.rake
86
- - tasks/version.rake
87
88
  - tools/clang-format-diff.sh
88
89
  - tools/exe/rbminify
89
90
  - tools/lib/syntax_tree/minify_ruby.rb
@@ -108,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
109
  - !ruby/object:Gem::Version
109
110
  version: '0'
110
111
  requirements: []
111
- rubygems_version: 3.5.3
112
+ rubygems_version: 3.4.19
112
113
  signing_key:
113
114
  specification_version: 4
114
115
  summary: Ruby to WebAssembly toolkit