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.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +13 -9
- data/Cargo.lock +705 -451
- data/Gemfile +1 -1
- data/README.md +12 -19
- data/Rakefile +9 -9
- data/benchmarks/vm_deep_call.rb +2 -2
- data/docs/cheat_sheet.md +8 -8
- data/ext/ruby_wasm/Cargo.toml +6 -5
- data/ext/ruby_wasm/src/lib.rs +208 -7
- data/lib/ruby_wasm/build/executor.rb +4 -0
- data/lib/ruby_wasm/build/product/crossruby.rb +57 -23
- data/lib/ruby_wasm/build/product/libyaml.rb +5 -3
- data/lib/ruby_wasm/build/product/openssl.rb +7 -2
- data/lib/ruby_wasm/build/product/product.rb +3 -3
- data/lib/ruby_wasm/build/product/ruby_source.rb +3 -3
- data/lib/ruby_wasm/build/product/wasi_vfs.rb +1 -39
- data/lib/ruby_wasm/build/product/zlib.rb +5 -3
- data/lib/ruby_wasm/build/target.rb +24 -0
- data/lib/ruby_wasm/build/toolchain.rb +1 -1
- data/lib/ruby_wasm/build.rb +7 -3
- data/lib/ruby_wasm/cli.rb +171 -13
- data/lib/ruby_wasm/feature_set.rb +30 -0
- data/lib/ruby_wasm/packager/component_adapter/wasi_snapshot_preview1.command.wasm +0 -0
- data/lib/ruby_wasm/packager/component_adapter/wasi_snapshot_preview1.reactor.wasm +0 -0
- data/lib/ruby_wasm/packager/component_adapter.rb +14 -0
- data/lib/ruby_wasm/packager/core.rb +192 -4
- data/lib/ruby_wasm/packager/file_system.rb +20 -17
- data/lib/ruby_wasm/packager.rb +21 -83
- data/lib/ruby_wasm/rake_task.rb +2 -0
- data/lib/ruby_wasm/version.rb +1 -1
- data/lib/ruby_wasm.rb +2 -0
- data/package-lock.json +410 -133
- data/package.json +3 -3
- data/{tasks → rakelib}/ci.rake +3 -3
- data/{tasks → rakelib}/doc.rake +6 -1
- data/{tasks → rakelib}/format.rake +3 -2
- data/{tasks → rakelib}/gem.rake +4 -1
- data/{tasks → rakelib}/packaging.rake +34 -17
- data/{tasks → rakelib}/version.rake +2 -0
- data/sig/ruby_wasm/build.rbs +36 -31
- data/sig/ruby_wasm/cli.rbs +30 -3
- data/sig/ruby_wasm/ext.rbs +28 -3
- data/sig/ruby_wasm/feature_set.rbs +12 -0
- data/sig/ruby_wasm/packager.rbs +44 -7
- metadata +16 -15
- data/builders/wasm32-unknown-emscripten/Dockerfile +0 -43
- data/builders/wasm32-unknown-emscripten/entrypoint.sh +0 -7
- data/builders/wasm32-unknown-wasi/Dockerfile +0 -47
- data/builders/wasm32-unknown-wasi/entrypoint.sh +0 -7
- data/ruby_wasm.gemspec +0 -32
- /data/{tasks → rakelib}/check.rake +0 -0
data/lib/ruby_wasm/packager.rb
CHANGED
@@ -2,11 +2,19 @@
|
|
2
2
|
class RubyWasm::Packager
|
3
3
|
# Initializes a new instance of the RubyWasm::Packager class.
|
4
4
|
#
|
5
|
+
# @param root [String] The root directory of the Ruby project.
|
6
|
+
# The root directory (will) contain the following files:
|
7
|
+
# * build_manifest.json
|
8
|
+
# * rubies
|
9
|
+
# * build
|
5
10
|
# @param config [Hash] The build config used for building Ruby.
|
6
11
|
# @param definition [Bundler::Definition] The Bundler definition.
|
7
|
-
|
12
|
+
# @param features [RubyWasm::FeatureSet] The features used for packaging.
|
13
|
+
def initialize(root, config = nil, definition = nil, features: RubyWasm::FeatureSet.derive_from_env)
|
14
|
+
@root = root
|
8
15
|
@definition = definition
|
9
16
|
@config = config
|
17
|
+
@features = features
|
10
18
|
end
|
11
19
|
|
12
20
|
# Packages the Ruby code into a Wasm binary. (including extensions)
|
@@ -21,15 +29,13 @@ class RubyWasm::Packager
|
|
21
29
|
|
22
30
|
fs = RubyWasm::Packager::FileSystem.new(dest_dir, self)
|
23
31
|
fs.package_ruby_root(tarball, executor)
|
24
|
-
|
25
|
-
ruby_wasm_bin = File.expand_path("bin/ruby", fs.ruby_root)
|
26
|
-
wasm_bytes = File.binread(ruby_wasm_bin).bytes
|
32
|
+
wasm_bytes = ruby_core.build_and_link_exts(executor)
|
27
33
|
|
28
34
|
fs.package_gems
|
29
35
|
fs.remove_non_runtime_files(executor)
|
30
36
|
fs.remove_stdlib(executor) unless options[:stdlib]
|
31
37
|
|
32
|
-
if full_build_options[:target] == "wasm32-unknown-
|
38
|
+
if full_build_options[:target] == "wasm32-unknown-wasip1" && !features.support_component_model?
|
33
39
|
# wasi-vfs supports only WASI target
|
34
40
|
wasi_vfs = RubyWasmExt::WasiVfs.new
|
35
41
|
wasi_vfs.map_dir("/bundle", fs.bundle_dir)
|
@@ -52,79 +58,22 @@ class RubyWasm::Packager
|
|
52
58
|
# Retrieves the specs from the Bundler definition, excluding the excluded gems.
|
53
59
|
def specs
|
54
60
|
return [] unless @definition
|
55
|
-
@
|
56
|
-
|
57
|
-
|
58
|
-
# Checks if dynamic linking is supported.
|
59
|
-
def support_dynamic_linking?
|
60
|
-
@ruby_channel == "head"
|
61
|
-
end
|
62
|
-
|
63
|
-
# Retrieves the root directory of the Ruby project.
|
64
|
-
# The root directory contains the following stuff:
|
65
|
-
# * patches/*.patch
|
66
|
-
# * build_manifest.json
|
67
|
-
# * rubies
|
68
|
-
# * build
|
69
|
-
def root
|
70
|
-
__skip__ =
|
71
|
-
@root ||=
|
72
|
-
begin
|
73
|
-
if explicit = ENV["RUBY_WASM_ROOT"]
|
74
|
-
File.expand_path(explicit)
|
75
|
-
elsif defined?(Bundler)
|
76
|
-
Bundler.root
|
77
|
-
else
|
78
|
-
Dir.pwd
|
79
|
-
end
|
80
|
-
rescue Bundler::GemfileNotFound
|
81
|
-
Dir.pwd
|
82
|
-
end
|
61
|
+
@specs ||= @definition.resolve.materialize(@definition.requested_dependencies)
|
62
|
+
.reject { |spec| EXCLUDED_GEMS.include?(spec.name) }
|
63
|
+
@specs
|
83
64
|
end
|
84
65
|
|
85
|
-
|
86
|
-
|
87
|
-
patches = Dir[File.join(root, "patches", "*.patch")]
|
88
|
-
sources = {
|
89
|
-
"head" => {
|
90
|
-
type: "github",
|
91
|
-
repo: "ruby/ruby",
|
92
|
-
rev: "997124fc0b7697bb9383e8feb8e1d88017c4bcb8",
|
93
|
-
patches: patches.map { |p| File.expand_path(p) }
|
94
|
-
},
|
95
|
-
"3.3" => {
|
96
|
-
type: "tarball",
|
97
|
-
url: "https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.0.tar.gz"
|
98
|
-
},
|
99
|
-
"3.2" => {
|
100
|
-
type: "tarball",
|
101
|
-
url: "https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.2.tar.gz"
|
102
|
-
}
|
103
|
-
}
|
104
|
-
sources.each { |name, source| source[:name] = name }
|
105
|
-
|
106
|
-
build_manifest = File.join(root, "build_manifest.json")
|
107
|
-
if File.exist?(build_manifest)
|
108
|
-
begin
|
109
|
-
manifest = JSON.parse(File.read(build_manifest))
|
110
|
-
manifest["ruby_revisions"].each do |name, rev|
|
111
|
-
sources[name][:rev] = rev
|
112
|
-
end
|
113
|
-
rescue StandardError => e
|
114
|
-
RubyWasm.logger.warn "Failed to load build_manifest.json: #{e}"
|
115
|
-
end
|
116
|
-
end
|
117
|
-
sources
|
66
|
+
def features
|
67
|
+
@features
|
118
68
|
end
|
119
69
|
|
120
70
|
ALL_DEFAULT_EXTS =
|
121
|
-
"
|
71
|
+
"cgi/escape,continuation,coverage,date,digest/bubblebabble,digest,digest/md5,digest/rmd160,digest/sha1,digest/sha2,etc,fcntl,json,json/generator,json/parser,objspace,pathname,psych,rbconfig/sizeof,ripper,stringio,strscan,monitor,zlib,openssl"
|
122
72
|
|
123
73
|
# Retrieves the build options used for building Ruby itself.
|
124
74
|
def build_options
|
125
75
|
default = {
|
126
|
-
target: "wasm32-unknown-
|
127
|
-
src: "3.3",
|
76
|
+
target: RubyWasm::Target.new("wasm32-unknown-wasip1"),
|
128
77
|
default_exts: ALL_DEFAULT_EXTS
|
129
78
|
}
|
130
79
|
override = @config || {}
|
@@ -135,25 +84,14 @@ class RubyWasm::Packager
|
|
135
84
|
# Retrieves the resolved build options
|
136
85
|
def full_build_options
|
137
86
|
options = build_options
|
138
|
-
build_dir = File.join(root, "build")
|
139
|
-
rubies_dir = File.join(root, "rubies")
|
87
|
+
build_dir = File.join(@root, "build")
|
88
|
+
rubies_dir = File.join(@root, "rubies")
|
140
89
|
toolchain = RubyWasm::Toolchain.get(options[:target], build_dir)
|
141
|
-
src =
|
142
|
-
if options[:src].is_a?(Hash)
|
143
|
-
options[:src]
|
144
|
-
else
|
145
|
-
src_name = options[:src]
|
146
|
-
aliases = self.class.build_source_aliases(root)
|
147
|
-
aliases[src_name] ||
|
148
|
-
raise(
|
149
|
-
"Unknown Ruby source: #{src_name} (available: #{aliases.keys.join(", ")})"
|
150
|
-
)
|
151
|
-
end
|
152
90
|
options.merge(
|
153
91
|
toolchain: toolchain,
|
154
92
|
build_dir: build_dir,
|
155
93
|
rubies_dir: rubies_dir,
|
156
|
-
src: src
|
94
|
+
src: options[:src]
|
157
95
|
)
|
158
96
|
end
|
159
97
|
end
|
data/lib/ruby_wasm/rake_task.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "rake/tasklib"
|
2
|
+
require_relative "./util"
|
2
3
|
require_relative "./build"
|
3
4
|
|
4
5
|
class RubyWasm::BuildTask < ::Rake::TaskLib
|
@@ -15,6 +16,7 @@ class RubyWasm::BuildTask < ::Rake::TaskLib
|
|
15
16
|
**options,
|
16
17
|
&block
|
17
18
|
)
|
19
|
+
target = Target.new(target)
|
18
20
|
@build =
|
19
21
|
RubyWasm::Build.new(
|
20
22
|
name,
|
data/lib/ruby_wasm/version.rb
CHANGED
data/lib/ruby_wasm.rb
CHANGED
@@ -3,7 +3,9 @@ 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"
|
8
|
+
require_relative "ruby_wasm/packager/component_adapter"
|
7
9
|
require_relative "ruby_wasm/packager/file_system"
|
8
10
|
require_relative "ruby_wasm/packager/core"
|
9
11
|
|