ruby_wasm 2.5.1-x86_64-linux → 2.6.0-x86_64-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +3 -2
- data/README.md +3 -3
- data/Rakefile +2 -1
- data/docs/cheat_sheet.md +8 -8
- data/lib/ruby_wasm/3.1/ruby_wasm.so +0 -0
- data/lib/ruby_wasm/3.2/ruby_wasm.so +0 -0
- data/lib/ruby_wasm/3.3/ruby_wasm.so +0 -0
- data/lib/ruby_wasm/build/product/crossruby.rb +7 -2
- data/lib/ruby_wasm/build/product/product.rb +1 -0
- data/lib/ruby_wasm/build/toolchain/wit_bindgen.rb +2 -2
- data/lib/ruby_wasm/build/toolchain.rb +3 -2
- data/lib/ruby_wasm/cli.rb +13 -7
- data/lib/ruby_wasm/feature_set.rb +30 -0
- data/lib/ruby_wasm/packager/core.rb +26 -9
- data/lib/ruby_wasm/packager/file_system.rb +1 -1
- data/lib/ruby_wasm/packager.rb +9 -6
- data/lib/ruby_wasm/version.rb +1 -1
- data/lib/ruby_wasm.rb +1 -0
- data/package-lock.json +5512 -7233
- data/package.json +2 -2
- data/rakelib/check.rake +23 -10
- data/rakelib/packaging.rake +18 -3
- data/sig/ruby_wasm/build.rbs +3 -1
- data/sig/ruby_wasm/cli.rbs +1 -1
- data/sig/ruby_wasm/ext.rbs +10 -0
- data/sig/ruby_wasm/feature_set.rbs +12 -0
- data/sig/ruby_wasm/packager.rbs +11 -5
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d69112f5aefba12d8665858c3757370e0fab11f220bcc1251b3a6b1a9ec97bd6
|
4
|
+
data.tar.gz: 2b08321d68e9c3182e2e016ec2b8745c6ab607d0accce27fe8e49f8a820ecf40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 939bee0e263e176f0d5523e240d95b7a19ca24d717c02901d209f7c0bffd02b37090e10ea3e6b5f2a688f7cee862aae16ac1f019cb839a7229e61d67470481e6
|
7
|
+
data.tar.gz: f09011523f3be736fbfe014c267662dcd429aec32a5883a82de2ad622112c6b0853f57d40a19143b267745a0ca5ca0598cf87ea439728be034d3defb2d0cbd4f
|
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
|
-
$
|
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.
|
128
|
+
$ npm install --save @ruby/wasm-wasi@2.6.0-2024-05-05-a
|
128
129
|
```
|
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.
|
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
|
|
30
|
-
puts RUBY_VERSION #
|
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.
|
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.
|
55
|
-
const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.
|
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.
|
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.
|
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.
|
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.
|
147
|
-
const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.
|
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
|
|
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
|
|
@@ -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,
|
@@ -4,10 +4,10 @@ module RubyWasm
|
|
4
4
|
|
5
5
|
def initialize(
|
6
6
|
build_dir:,
|
7
|
-
revision: "
|
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
@@ -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:
|
174
|
+
config = { target: options[:target_triplet], src: build_source }
|
174
175
|
case options[:profile]
|
175
176
|
when "full"
|
176
|
-
config[: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
|
-
|
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.
|
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.
|
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(
|
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
|
-
|
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
|
-
|
301
|
-
|
302
|
-
|
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))
|
data/lib/ruby_wasm/packager.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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"
|
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
|
-
|
65
|
-
|
66
|
-
ENV["RUBY_WASM_EXPERIMENTAL_DYNAMIC_LINKING"] == "1"
|
68
|
+
def features
|
69
|
+
@features
|
67
70
|
end
|
68
71
|
|
69
72
|
ALL_DEFAULT_EXTS =
|
data/lib/ruby_wasm/version.rb
CHANGED
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"
|