ruby_wasm 2.5.1-arm64-darwin → 2.5.2-arm64-darwin

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: abea19f7078ec3b3fe28c43a75b79beddf89b4e201a475afea5b35e37f53a083
4
- data.tar.gz: 2f50628b80582c5b149742141c93852f7277ddefefaba8ced488f55b2cde8ac9
3
+ metadata.gz: 0bc9bf417e81232b7ad9cc364ac5f43198922e4daf28c1f033c340c4a49930c2
4
+ data.tar.gz: bdda5e2d30ef54b607c596fe62a067bc52033954dc96721a060ce73f8e16f3e8
5
5
  SHA512:
6
- metadata.gz: 48136b66102e5f7da55c8683bfab4f8b5937d48f88217c64c5f7e2ae7637ef1b65c7601cd94028e6d79eda6ad5b8e49fe69d395c3dadb9fca492a66e86c732e5
7
- data.tar.gz: ee71dd976e19ffa18370aaacc4b47fed6557f3a7a797132c41dcef40c079310afdea3c46babbc857b2667422989270f87e5b1eda66da35bc0f57b28bb9f55411
6
+ metadata.gz: 1ce149c253ad849a6cffa1dfde843fd254d8930cf1082ff53ddd1056022acff6176156539c1126ccf3ade4fc8a8b1b72d1cb31e7e7fe132f2cfd443c7c8c31cb
7
+ data.tar.gz: 4cad8ce6d5e581baaa25247723389308bb479841421745f68d13884ce17e5f95f42bbb281c52915312599100e6bc7ac8cc009d00b8ed6e4d49afe376931c5da0
data/CONTRIBUTING.md CHANGED
@@ -124,5 +124,5 @@ $ npm install --save @ruby/wasm-wasi@latest
124
124
  # or if you want the nightly snapshot
125
125
  $ npm install --save @ruby/wasm-wasi@next
126
126
  # or you can specify the exact snapshot version
127
- $ npm install --save @ruby/wasm-wasi@2.5.1-2024-04-21-a
127
+ $ npm install --save @ruby/wasm-wasi@2.5.2-2024-05-04-a
128
128
  ```
data/README.md CHANGED
@@ -17,17 +17,17 @@ Try ruby.wasm in [TryRuby](https://try.ruby-lang.org/playground#code=puts+RUBY_D
17
17
  - [Complete Examples](https://github.com/ruby/ruby.wasm/tree/main/packages/npm-packages/ruby-wasm-wasi/example)
18
18
  - [Community Showcase](https://github.com/ruby/ruby.wasm/wiki/Showcase)
19
19
 
20
- ## Quick Example: Ruby on browser
20
+ ## Quick Example: Ruby on Web browser
21
21
 
22
22
  Create and save `index.html` page with the following contents:
23
23
 
24
24
  ```html
25
25
  <html>
26
- <script src="https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.1/dist/browser.script.iife.js"></script>
26
+ <script src="https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.2/dist/browser.script.iife.js"></script>
27
27
  <script type="text/ruby">
28
28
  require "js"
29
29
 
30
- puts RUBY_VERSION # => Hello, world! (printed to the browser console)
30
+ puts RUBY_VERSION # (Printed to the Web browser console)
31
31
  JS.global[:document].write "Hello, world!"
32
32
  </script>
33
33
  </html>
data/Rakefile CHANGED
@@ -29,7 +29,8 @@ NPM_PACKAGES = [
29
29
  name: "ruby-head-wasm-wasi",
30
30
  ruby_version: "head",
31
31
  gemfile: "packages/npm-packages/ruby-wasm-wasi/Gemfile",
32
- target: "wasm32-unknown-wasip1"
32
+ target: "wasm32-unknown-wasip1",
33
+ enable_component_model: true,
33
34
  },
34
35
  {
35
36
  name: "ruby-3.3-wasm-wasi",
data/docs/cheat_sheet.md CHANGED
@@ -38,7 +38,7 @@ The easiest way to run Ruby on browser is to use `browser.script.iife.js` script
38
38
 
39
39
  ```html
40
40
  <html>
41
- <script src="https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.1/dist/browser.script.iife.js"></script>
41
+ <script src="https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.2/dist/browser.script.iife.js"></script>
42
42
  <script type="text/ruby">
43
43
  require "js"
44
44
  JS.global[:document].write "Hello, world!"
@@ -51,8 +51,8 @@ If you want to control Ruby VM from JavaScript, you can use `@ruby/wasm-wasi` pa
51
51
  ```html
52
52
  <html>
53
53
  <script type="module">
54
- import { DefaultRubyVM } from "https://cdn.jsdelivr.net/npm/@ruby/wasm-wasi@2.5.1/dist/browser/+esm";
55
- const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.1/dist/ruby+stdlib.wasm");
54
+ import { DefaultRubyVM } from "https://cdn.jsdelivr.net/npm/@ruby/wasm-wasi@2.5.2/dist/browser/+esm";
55
+ const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.2/dist/ruby+stdlib.wasm");
56
56
  const module = await WebAssembly.compileStreaming(response);
57
57
  const { vm } = await DefaultRubyVM(module);
58
58
 
@@ -69,11 +69,11 @@ If you want to control Ruby VM from JavaScript, you can use `@ruby/wasm-wasi` pa
69
69
 
70
70
  ```html
71
71
  <html>
72
- <script src="https://cdn.jsdelivr.net/npm/@ruby/wasm-wasi@2.5.1/dist/browser.umd.js"></script>
72
+ <script src="https://cdn.jsdelivr.net/npm/@ruby/wasm-wasi@2.5.2/dist/browser.umd.js"></script>
73
73
  <script>
74
74
  const main = async () => {
75
75
  const { DefaultRubyVM } = window["ruby-wasm-wasi"];
76
- const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.1/dist/ruby+stdlib.wasm");
76
+ const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.2/dist/ruby+stdlib.wasm");
77
77
  const module = await WebAssembly.compileStreaming(response);
78
78
  const { vm } = await DefaultRubyVM(module);
79
79
 
@@ -128,7 +128,7 @@ end
128
128
 
129
129
  ```html
130
130
  <html>
131
- <script src="https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.1/dist/browser.script.iife.js"></script>
131
+ <script src="https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.2/dist/browser.script.iife.js"></script>
132
132
  <script type="text/ruby" data-eval="async">
133
133
  require "js"
134
134
 
@@ -143,8 +143,8 @@ Or using `@ruby/wasm-wasi` package API `RubyVM#evalAsync`:
143
143
  ```html
144
144
  <html>
145
145
  <script type="module">
146
- import { DefaultRubyVM } from "https://cdn.jsdelivr.net/npm/@ruby/wasm-wasi@2.5.1/dist/browser/+esm";
147
- const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.1/dist/ruby+stdlib.wasm");
146
+ import { DefaultRubyVM } from "https://cdn.jsdelivr.net/npm/@ruby/wasm-wasi@2.5.2/dist/browser/+esm";
147
+ const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.2/dist/ruby+stdlib.wasm");
148
148
  const module = await WebAssembly.compileStreaming(response);
149
149
  const { vm } = await DefaultRubyVM(module);
150
150
 
Binary file
Binary file
Binary file
@@ -5,11 +5,12 @@ module RubyWasm
5
5
  class CrossRubyExtProduct < BuildProduct
6
6
  attr_reader :name
7
7
 
8
- def initialize(srcdir, toolchain, ext_relative_path: nil)
8
+ def initialize(srcdir, toolchain, features:, ext_relative_path: nil)
9
9
  @srcdir, @toolchain = srcdir, toolchain
10
10
  # ext_relative_path is relative path from build dir
11
11
  # e.g. cgi-0.3.6/ext/cgi/escape
12
12
  @ext_relative_path = ext_relative_path || File.basename(srcdir)
13
+ @features = features
13
14
  @name = @ext_relative_path
14
15
  end
15
16
 
@@ -76,6 +77,7 @@ module RubyWasm
76
77
  "#{@srcdir}/extconf.rb",
77
78
  "--target-rbconfig=#{rbconfig_rb}",
78
79
  ]
80
+ extconf_args << "--enable-component-model" if @features.support_component_model?
79
81
  executor.system Gem.ruby, *extconf_args
80
82
  end
81
83
 
@@ -105,8 +107,10 @@ module RubyWasm
105
107
  # like "cgi/escape" instead of "escape"
106
108
  "-e",
107
109
  %Q(require "json"; File.write("#{metadata_json(crossruby)}", JSON.dump({target: $target}))),
108
- "-I#{crossruby.build_dir}"
110
+ "-I#{crossruby.build_dir}",
111
+ "--",
109
112
  ]
113
+ extconf_args << "--enable-component-model" if @features.support_component_model?
110
114
  # Clear RUBYOPT to avoid loading unrelated bundle setup
111
115
  executor.system crossruby.baseruby_path,
112
116
  *extconf_args,
@@ -4,10 +4,10 @@ module RubyWasm
4
4
 
5
5
  def initialize(
6
6
  build_dir:,
7
- revision: "251e84b89121751f79ac268629e9285082b2596d"
7
+ revision: "v0.24.0"
8
8
  )
9
9
  @build_dir = build_dir
10
- @tool_dir = File.join(@build_dir, "toolchain", "wit-bindgen")
10
+ @tool_dir = File.join(@build_dir, "toolchain", "wit-bindgen-#{revision}")
11
11
  @bin_path = File.join(@tool_dir, "bin", "wit-bindgen")
12
12
  @revision = revision
13
13
  end
data/lib/ruby_wasm/cli.rb CHANGED
@@ -169,11 +169,12 @@ module RubyWasm
169
169
  private
170
170
 
171
171
  def build_config(options)
172
+ build_source, all_default_exts = compute_build_source(options)
172
173
  # @type var config: Packager::build_config
173
- config = { target: options[:target_triplet], src: compute_build_source(options) }
174
+ config = { target: options[:target_triplet], src: build_source }
174
175
  case options[:profile]
175
176
  when "full"
176
- config[:default_exts] = config[:src][:all_default_exts]
177
+ config[:default_exts] = all_default_exts || ""
177
178
  env_additional_exts = ENV["RUBY_WASM_ADDITIONAL_EXTS"] || ""
178
179
  unless env_additional_exts.empty?
179
180
  config[:default_exts] += "," + env_additional_exts
@@ -203,7 +204,7 @@ module RubyWasm
203
204
  local_source = { type: "local", path: src_name }
204
205
  # @type var local_source: RubyWasm::Packager::build_source
205
206
  local_source = local_source.merge(name: "local", patches: [])
206
- return local_source
207
+ return [local_source, nil]
207
208
  end
208
209
  # Otherwise, it's an unknown source.
209
210
  raise(
@@ -212,7 +213,9 @@ module RubyWasm
212
213
  end
213
214
  # Apply user-specified patches in addition to bundled patches.
214
215
  source[:patches].concat(options[:patches])
215
- source
216
+ # @type var all_default_exts: String
217
+ __skip__ = all_default_exts = source[:all_default_exts]
218
+ [source, all_default_exts]
216
219
  end
217
220
 
218
221
  # Retrieves the alias definitions for the Ruby sources.
@@ -227,12 +230,12 @@ module RubyWasm
227
230
  },
228
231
  "3.3" => {
229
232
  type: "tarball",
230
- url: "https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.0.tar.gz",
233
+ url: "https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.1.tar.gz",
231
234
  all_default_exts: "bigdecimal,cgi/escape,continuation,coverage,date,dbm,digest/bubblebabble,digest,digest/md5,digest/rmd160,digest/sha1,digest/sha2,etc,fcntl,fiber,gdbm,json,json/generator,json/parser,nkf,objspace,pathname,psych,racc/cparse,rbconfig/sizeof,ripper,stringio,strscan,monitor,zlib,openssl",
232
235
  },
233
236
  "3.2" => {
234
237
  type: "tarball",
235
- url: "https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.3.tar.gz",
238
+ url: "https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.4.tar.gz",
236
239
  all_default_exts: "bigdecimal,cgi/escape,continuation,coverage,date,dbm,digest/bubblebabble,digest,digest/md5,digest/rmd160,digest/sha1,digest/sha2,etc,fcntl,fiber,gdbm,json,json/generator,json/parser,nkf,objspace,pathname,psych,racc/cparse,rbconfig/sizeof,ripper,stringio,strscan,monitor,zlib,openssl",
237
240
  }
238
241
  }
@@ -305,7 +308,10 @@ module RubyWasm
305
308
  end
306
309
  end
307
310
  RubyWasm.logger.info "Using Gemfile: #{definition.gemfiles}" if definition
308
- RubyWasm::Packager.new(root, build_config(options), definition)
311
+ RubyWasm::Packager.new(
312
+ root, build_config(options), definition,
313
+ features: RubyWasm::FeatureSet.derive_from_env
314
+ )
309
315
  end
310
316
 
311
317
  def do_print_ruby_cache_key(packager)
@@ -0,0 +1,30 @@
1
+ ##
2
+ # A set of feature flags that can be used to enable or disable experimental features.
3
+ class RubyWasm::FeatureSet
4
+ def initialize(features)
5
+ @features = features
6
+ end
7
+
8
+ # Maps the feature to the environment variable.
9
+ FEATURES = {
10
+ dynamic_linking: "RUBY_WASM_EXPERIMENTAL_DYNAMIC_LINKING",
11
+ component_model: "RUBY_WASM_EXPERIMENTAL_COMPONENT_MODEL",
12
+ }.freeze
13
+ private_constant :FEATURES
14
+
15
+ # Derives the feature set from the environment variables. A feature
16
+ # is enabled if the corresponding environment variable is set to "1",
17
+ # otherwise it is disabled.
18
+ def self.derive_from_env
19
+ values = FEATURES.transform_values { |key| ENV[key] == "1" }
20
+ new(values)
21
+ end
22
+
23
+ def support_dynamic_linking?
24
+ @features[:dynamic_linking]
25
+ end
26
+
27
+ def support_component_model?
28
+ @features[:component_model] || @features[:dynamic_linking]
29
+ end
30
+ end
@@ -20,7 +20,7 @@ class RubyWasm::Packager::Core
20
20
  @build_strategy ||=
21
21
  begin
22
22
  has_exts = @packager.specs.any? { |spec| spec.extensions.any? }
23
- if @packager.support_dynamic_linking?
23
+ if @packager.features.support_dynamic_linking?
24
24
  DynamicLinking.new(@packager)
25
25
  else
26
26
  StaticLinking.new(@packager)
@@ -37,7 +37,7 @@ class RubyWasm::Packager::Core
37
37
  raise NotImplementedError
38
38
  end
39
39
 
40
- def build_and_link_exts(executor)
40
+ def build_and_link_exts(executor, module_bytes)
41
41
  raise NotImplementedError
42
42
  end
43
43
 
@@ -93,7 +93,7 @@ class RubyWasm::Packager::Core
93
93
  build.crossruby.artifact
94
94
  end
95
95
 
96
- def build_and_link_exts(executor)
96
+ def build_and_link_exts(executor, module_bytes)
97
97
  build = derive_build
98
98
  self.build_exts(executor, build)
99
99
  self.link_exts(executor, build)
@@ -162,6 +162,7 @@ class RubyWasm::Packager::Core
162
162
  RubyWasm::CrossRubyExtProduct.new(
163
163
  ext_srcdir,
164
164
  build.toolchain,
165
+ features: @packager.features,
165
166
  ext_relative_path: ext_relative_path
166
167
  )
167
168
  end
@@ -258,6 +259,9 @@ class RubyWasm::Packager::Core
258
259
 
259
260
  def cache_key(digest)
260
261
  derive_build.cache_key(digest)
262
+ if enabled = @packager.features.support_component_model?
263
+ digest << enabled.to_s
264
+ end
261
265
  end
262
266
 
263
267
  def artifact
@@ -270,8 +274,9 @@ class RubyWasm::Packager::Core
270
274
 
271
275
  def derive_build
272
276
  return @build if @build
273
- __skip__ =
274
- build ||= RubyWasm::Build.new(name, **@packager.full_build_options, target: target)
277
+ __skip__ = build ||= RubyWasm::Build.new(
278
+ name, **@packager.full_build_options, target: target,
279
+ )
275
280
  build.crossruby.user_exts = user_exts(build)
276
281
  # Emscripten uses --global-base=1024 by default, but it conflicts with
277
282
  # --stack-first and -z stack-size since global-base 1024 is smaller than
@@ -296,10 +301,18 @@ class RubyWasm::Packager::Core
296
301
  build
297
302
  end
298
303
 
299
- def build_and_link_exts(executor)
300
- build = derive_build
301
- ruby_root = build.crossruby.dest_dir
302
- File.binread(File.join(ruby_root, "usr", "local", "bin", "ruby"))
304
+ def build_and_link_exts(executor, module_bytes)
305
+ return module_bytes unless @packager.features.support_component_model?
306
+
307
+ linker = RubyWasmExt::ComponentEncode.new
308
+ linker.validate(true)
309
+ linker.module(module_bytes)
310
+ linker.adapter(
311
+ "wasi_snapshot_preview1",
312
+ File.binread(RubyWasm::Packager::ComponentAdapter.wasi_snapshot_preview1("reactor"))
313
+ )
314
+
315
+ linker.encode()
303
316
  end
304
317
 
305
318
  def user_exts(build)
@@ -312,6 +325,7 @@ class RubyWasm::Packager::Core
312
325
  RubyWasm::CrossRubyExtProduct.new(
313
326
  ext_srcdir,
314
327
  build.toolchain,
328
+ features: @packager.features,
315
329
  ext_relative_path: ext_relative_path
316
330
  )
317
331
  end
@@ -327,6 +341,9 @@ class RubyWasm::Packager::Core
327
341
  exts = specs_with_extensions.sort
328
342
  hash = ::Digest::MD5.new
329
343
  specs_with_extensions.each { |spec, _| hash << spec.full_name }
344
+ if enabled = @packager.features.support_component_model?
345
+ hash << enabled.to_s
346
+ end
330
347
  exts.empty? ? base : "#{base}-#{hash.hexdigest}"
331
348
  end
332
349
  end
@@ -71,7 +71,7 @@ class RubyWasm::Packager::FileSystem
71
71
  usr/local/include
72
72
  ]
73
73
 
74
- patterns << "**/*.so" unless @packager.support_dynamic_linking?
74
+ patterns << "**/*.so" unless @packager.features.support_dynamic_linking?
75
75
  patterns.each do |pattern|
76
76
  Dir
77
77
  .glob(File.join(@dest_dir, pattern))
@@ -9,10 +9,12 @@ class RubyWasm::Packager
9
9
  # * build
10
10
  # @param config [Hash] The build config used for building Ruby.
11
11
  # @param definition [Bundler::Definition] The Bundler definition.
12
- def initialize(root, config = nil, definition = nil)
12
+ # @param features [RubyWasm::FeatureSet] The features used for packaging.
13
+ def initialize(root, config = nil, definition = nil, features: RubyWasm::FeatureSet.derive_from_env)
13
14
  @root = root
14
15
  @definition = definition
15
16
  @config = config
17
+ @features = features
16
18
  end
17
19
 
18
20
  # Packages the Ruby code into a Wasm binary. (including extensions)
@@ -27,13 +29,14 @@ class RubyWasm::Packager
27
29
 
28
30
  fs = RubyWasm::Packager::FileSystem.new(dest_dir, self)
29
31
  fs.package_ruby_root(tarball, executor)
30
- wasm_bytes = ruby_core.build_and_link_exts(executor)
32
+
33
+ wasm_bytes = File.binread(File.join(fs.ruby_root, "bin", "ruby"))
31
34
 
32
35
  fs.package_gems
33
36
  fs.remove_non_runtime_files(executor)
34
37
  fs.remove_stdlib(executor) unless options[:stdlib]
35
38
 
36
- if full_build_options[:target] == "wasm32-unknown-wasip1" && !support_dynamic_linking?
39
+ if full_build_options[:target] == "wasm32-unknown-wasip1"
37
40
  # wasi-vfs supports only WASI target
38
41
  wasi_vfs = RubyWasmExt::WasiVfs.new
39
42
  wasi_vfs.map_dir("/bundle", fs.bundle_dir)
@@ -41,6 +44,7 @@ class RubyWasm::Packager
41
44
 
42
45
  wasm_bytes = wasi_vfs.pack(wasm_bytes)
43
46
  end
47
+ wasm_bytes = ruby_core.build_and_link_exts(executor, wasm_bytes)
44
48
 
45
49
  wasm_bytes = RubyWasmExt.preinitialize(wasm_bytes) if options[:optimize]
46
50
  wasm_bytes
@@ -61,9 +65,8 @@ class RubyWasm::Packager
61
65
  @specs
62
66
  end
63
67
 
64
- # Checks if dynamic linking is supported.
65
- def support_dynamic_linking?
66
- ENV["RUBY_WASM_EXPERIMENTAL_DYNAMIC_LINKING"] == "1"
68
+ def features
69
+ @features
67
70
  end
68
71
 
69
72
  ALL_DEFAULT_EXTS =
@@ -1,3 +1,3 @@
1
1
  module RubyWasm
2
- VERSION = "2.5.1"
2
+ VERSION = "2.5.2"
3
3
  end
data/lib/ruby_wasm.rb CHANGED
@@ -3,6 +3,7 @@ require "logger"
3
3
  require_relative "ruby_wasm/version"
4
4
  require_relative "ruby_wasm/util"
5
5
  require_relative "ruby_wasm/build"
6
+ require_relative "ruby_wasm/feature_set"
6
7
  require_relative "ruby_wasm/packager"
7
8
  require_relative "ruby_wasm/packager/component_adapter"
8
9
  require_relative "ruby_wasm/packager/file_system"