ruby_wasm 2.5.1 → 2.6.0

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: f509aedcac0dfbe264b9dff6984f1fbd71fbcac4a462783b0a3f8b182410440b
4
+ data.tar.gz: 390c1306c8c7b28d8583ebdf9bcdd69ff72d1ad56435923871090dbabb301421
5
5
  SHA512:
6
- metadata.gz: 551d4bf9b6f7485f3a286363671a1f990729a0c626dd0b2b18324146826c3176873301359003ed3978c2a36d1e5ed46d9ddce93b213968bf59f0f9302f02901d
7
- data.tar.gz: 48ca26f8ccb3e18b39a541e3ab3c41a154a3ddec56890d0b87f3fb88a2d6f16b509558c316cb75182fa80a29c94e76f760731a0d75b0fd089d5b4415cfd46513
6
+ metadata.gz: 1cf577ede9835215d5b8a23936ed515e6e104dba588a52b1bb43127e9e907648d3739c8b452448804266ef955767c12b2a251061e36f61b6f78185e830fad41e
7
+ data.tar.gz: eb7cc82ef12d8ca024ce0e24a47b57aea938ad422c76a9f26a41dfc18d35103cb5efa37986850e23b712e494ebc6adad259005ef13e730bc5c2910d5c4ba9dac
data/CONTRIBUTING.md CHANGED
@@ -110,7 +110,8 @@ $ git commit -m"Bump version to 0.6.0"
110
110
  $ git tag 0.6.0
111
111
  $ git push origin 0.6.0
112
112
  $ for pkg in pkg/ruby_wasm-*; do gem push $pkg; done
113
- $ (cd packages/gems/js/ && gem build && gem push js-*.gem)
113
+ $ gem build && gem push ruby_wasm-*.gem && rm ruby_wasm-*.gem
114
+ $ (cd packages/gems/js/ && gem build && gem push js-*.gem && rm js-*.gem)
114
115
  ```
115
116
 
116
117
  ## Release Channels
@@ -124,5 +125,5 @@ $ npm install --save @ruby/wasm-wasi@latest
124
125
  # or if you want the nightly snapshot
125
126
  $ npm install --save @ruby/wasm-wasi@next
126
127
  # or you can specify the exact snapshot version
127
- $ npm install --save @ruby/wasm-wasi@2.5.1-2024-04-21-a
128
+ $ npm install --save @ruby/wasm-wasi@2.6.0-2024-05-05-a
128
129
  ```
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.6.0/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.6.0/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.6.0/dist/browser/+esm";
55
+ const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.6.0/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.6.0/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.6.0/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.6.0/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.6.0/dist/browser/+esm";
147
+ const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.6.0/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
 
@@ -33,6 +34,7 @@ module RubyWasm
33
34
  def make_args(crossruby)
34
35
  make_args = []
35
36
  make_args << "CC=#{@toolchain.cc}"
37
+ make_args << "CXX=#{@toolchain.cc}"
36
38
  make_args << "LD=#{@toolchain.ld}"
37
39
  make_args << "AR=#{@toolchain.ar}"
38
40
  make_args << "RANLIB=#{@toolchain.ranlib}"
@@ -76,6 +78,7 @@ module RubyWasm
76
78
  "#{@srcdir}/extconf.rb",
77
79
  "--target-rbconfig=#{rbconfig_rb}",
78
80
  ]
81
+ extconf_args << "--enable-component-model" if @features.support_component_model?
79
82
  executor.system Gem.ruby, *extconf_args
80
83
  end
81
84
 
@@ -105,8 +108,10 @@ module RubyWasm
105
108
  # like "cgi/escape" instead of "escape"
106
109
  "-e",
107
110
  %Q(require "json"; File.write("#{metadata_json(crossruby)}", JSON.dump({target: $target}))),
108
- "-I#{crossruby.build_dir}"
111
+ "-I#{crossruby.build_dir}",
112
+ "--",
109
113
  ]
114
+ extconf_args << "--enable-component-model" if @features.support_component_model?
110
115
  # Clear RUBYOPT to avoid loading unrelated bundle setup
111
116
  executor.system crossruby.baseruby_path,
112
117
  *extconf_args,
@@ -26,6 +26,7 @@ module RubyWasm
26
26
  def tools_args
27
27
  args = []
28
28
  args << "CC=#{@toolchain.cc}"
29
+ args << "CXX=#{@toolchain.cxx}"
29
30
  args << "LD=#{@toolchain.ld}"
30
31
  args << "AR=#{@toolchain.ar}"
31
32
  args << "RANLIB=#{@toolchain.ranlib}"
@@ -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
@@ -43,7 +43,7 @@ module RubyWasm
43
43
  tool
44
44
  end
45
45
 
46
- %i[cc ranlib ld ar].each do |name|
46
+ %i[cc cxx ranlib ld ar].each do |name|
47
47
  define_method(name) do
48
48
  @tools_cache ||= {}
49
49
  @tools_cache[name] ||= find_tool(name)
@@ -84,6 +84,7 @@ module RubyWasm
84
84
 
85
85
  @tools = {
86
86
  cc: "#{wasi_sdk_path}/bin/clang",
87
+ cxx: "#{wasi_sdk_path}/bin/clang++",
87
88
  ld: "#{wasi_sdk_path}/bin/clang",
88
89
  ar: "#{wasi_sdk_path}/bin/llvm-ar",
89
90
  ranlib: "#{wasi_sdk_path}/bin/llvm-ranlib"
@@ -178,7 +179,7 @@ module RubyWasm
178
179
 
179
180
  class Emscripten < Toolchain
180
181
  def initialize
181
- @tools = { cc: "emcc", ld: "emcc", ar: "emar", ranlib: "emranlib" }
182
+ @tools = { cc: "emcc", cxx: "em++", ld: "emcc", ar: "emar", ranlib: "emranlib" }
182
183
  @name = "emscripten"
183
184
  end
184
185
 
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.6.0"
3
3
  end