ruby_wasm 2.5.1 → 2.5.2

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: 141bd526a7aa152f05058c93841d80f242c72137591183a9d5f891bf5ee715fe
4
- data.tar.gz: 2f491189cc5667b6f601e08c1685ace9fc9992738d264c76587487a91f4bde0b
3
+ metadata.gz: a8c30db752d99a73771fdaf73c72a139b22757ba34d0cfd20b6b319eb2dae41f
4
+ data.tar.gz: c00f1796d9e1b2008c6e08690f41e4d8037d43732ce6894480f2ab34bee6439d
5
5
  SHA512:
6
- metadata.gz: 551d4bf9b6f7485f3a286363671a1f990729a0c626dd0b2b18324146826c3176873301359003ed3978c2a36d1e5ed46d9ddce93b213968bf59f0f9302f02901d
7
- data.tar.gz: 48ca26f8ccb3e18b39a541e3ab3c41a154a3ddec56890d0b87f3fb88a2d6f16b509558c316cb75182fa80a29c94e76f760731a0d75b0fd089d5b4415cfd46513
6
+ metadata.gz: 6e78b6ceb43db9a27b9928aa048b1c4b0ab647053e6205ca68e9d5b1cdb2bee685828e7716ff87a6553a8216d6fe60682af9a76640cb2aab56c8c9f74ebdd5ef
7
+ data.tar.gz: 6fe16881179f2cfee7c54c24d8d963a774d041e5c225f1cad07300c33ecb04d2cccf7c95b7748cc1a1b48685c1305da781752a7cff27fec5d9ce54482c52b853
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
@@ -23,7 +23,7 @@ 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
 
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
 
@@ -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
@@ -230,12 +230,12 @@ module RubyWasm
230
230
  },
231
231
  "3.3" => {
232
232
  type: "tarball",
233
- 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",
234
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",
235
235
  },
236
236
  "3.2" => {
237
237
  type: "tarball",
238
- 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",
239
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",
240
240
  }
241
241
  }
@@ -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,7 @@ 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
- module_bytes = File.binread(File.join(ruby_root, "usr", "local", "bin", "ruby"))
304
+ def build_and_link_exts(executor, module_bytes)
303
305
  return module_bytes unless @packager.features.support_component_model?
304
306
 
305
307
  linker = RubyWasmExt::ComponentEncode.new
@@ -323,6 +325,7 @@ class RubyWasm::Packager::Core
323
325
  RubyWasm::CrossRubyExtProduct.new(
324
326
  ext_srcdir,
325
327
  build.toolchain,
328
+ features: @packager.features,
326
329
  ext_relative_path: ext_relative_path
327
330
  )
328
331
  end
@@ -338,6 +341,9 @@ class RubyWasm::Packager::Core
338
341
  exts = specs_with_extensions.sort
339
342
  hash = ::Digest::MD5.new
340
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
341
347
  exts.empty? ? base : "#{base}-#{hash.hexdigest}"
342
348
  end
343
349
  end
@@ -29,13 +29,14 @@ class RubyWasm::Packager
29
29
 
30
30
  fs = RubyWasm::Packager::FileSystem.new(dest_dir, self)
31
31
  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"))
33
34
 
34
35
  fs.package_gems
35
36
  fs.remove_non_runtime_files(executor)
36
37
  fs.remove_stdlib(executor) unless options[:stdlib]
37
38
 
38
- if full_build_options[:target] == "wasm32-unknown-wasip1" && !features.support_component_model?
39
+ if full_build_options[:target] == "wasm32-unknown-wasip1"
39
40
  # wasi-vfs supports only WASI target
40
41
  wasi_vfs = RubyWasmExt::WasiVfs.new
41
42
  wasi_vfs.map_dir("/bundle", fs.bundle_dir)
@@ -43,6 +44,7 @@ class RubyWasm::Packager
43
44
 
44
45
  wasm_bytes = wasi_vfs.pack(wasm_bytes)
45
46
  end
47
+ wasm_bytes = ruby_core.build_and_link_exts(executor, wasm_bytes)
46
48
 
47
49
  wasm_bytes = RubyWasmExt.preinitialize(wasm_bytes) if options[:optimize]
48
50
  wasm_bytes
@@ -1,3 +1,3 @@
1
1
  module RubyWasm
2
- VERSION = "2.5.1"
2
+ VERSION = "2.5.2"
3
3
  end