ruby_wasm 2.5.0.pre.1 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +10 -6
- data/Cargo.lock +625 -456
- data/Gemfile +1 -1
- data/README.md +8 -15
- data/Rakefile +2 -3
- data/benchmarks/vm_deep_call.rb +2 -2
- data/builders/wasm32-unknown-emscripten/Dockerfile +1 -1
- data/builders/wasm32-unknown-wasi/Dockerfile +1 -1
- data/docs/cheat_sheet.md +8 -8
- data/ext/ruby_wasm/Cargo.toml +3 -4
- data/ext/ruby_wasm/src/lib.rs +11 -0
- data/lib/ruby_wasm/build/product/crossruby.rb +4 -0
- data/lib/ruby_wasm/build/product/wasi_vfs.rb +0 -38
- data/lib/ruby_wasm/build/product/zlib.rb +2 -2
- data/lib/ruby_wasm/cli.rb +24 -2
- data/lib/ruby_wasm/packager/file_system.rb +15 -14
- data/lib/ruby_wasm/packager.rb +2 -2
- data/lib/ruby_wasm/rake_task.rb +1 -0
- data/lib/ruby_wasm/version.rb +1 -1
- data/package-lock.json +5 -5
- 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 +8 -5
- data/{tasks → rakelib}/version.rake +2 -0
- data/sig/ruby_wasm/build.rbs +0 -4
- data/sig/ruby_wasm/cli.rbs +3 -0
- data/sig/ruby_wasm/ext.rbs +3 -1
- metadata +9 -10
- data/ruby_wasm.gemspec +0 -32
- /data/{tasks → rakelib}/check.rake +0 -0
- /data/{tasks → rakelib}/ci.rake +0 -0
data/Gemfile
CHANGED
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.
|
26
|
+
<script src="https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.0/dist/browser.script.iife.js"></script>
|
27
27
|
<script type="text/ruby">
|
28
28
|
require "js"
|
29
29
|
|
@@ -35,25 +35,26 @@ Create and save `index.html` page with the following contents:
|
|
35
35
|
|
36
36
|
## Quick Example: How to package your Ruby application as a WASI application
|
37
37
|
|
38
|
-
Dependencies: [
|
38
|
+
Dependencies: [wasmtime](https://github.com/bytecodealliance/wasmtime)
|
39
39
|
|
40
40
|
```console
|
41
|
+
$ gem install ruby_wasm
|
41
42
|
# Download a prebuilt Ruby release
|
42
|
-
$ curl -LO https://github.com/ruby/ruby.wasm/releases/latest/download/ruby-3.
|
43
|
-
$ tar xfz ruby-3.
|
43
|
+
$ curl -LO https://github.com/ruby/ruby.wasm/releases/latest/download/ruby-3.3-wasm32-unknown-wasi-full.tar.gz
|
44
|
+
$ tar xfz ruby-3.3-wasm32-unknown-wasi-full.tar.gz
|
44
45
|
|
45
46
|
# Extract ruby binary not to pack itself
|
46
|
-
$ mv 3.
|
47
|
+
$ mv ruby-3.3-wasm32-unknown-wasi-full/usr/local/bin/ruby ruby.wasm
|
47
48
|
|
48
49
|
# Put your app code
|
49
50
|
$ mkdir src
|
50
51
|
$ echo "puts 'Hello'" > src/my_app.rb
|
51
52
|
|
52
53
|
# Pack the whole directory under /usr and your app dir
|
53
|
-
$
|
54
|
+
$ rbwasm pack ruby.wasm --dir ./src::/src --dir ./ruby-3.3-wasm32-unknown-wasi-full/usr::/usr -o my-ruby-app.wasm
|
54
55
|
|
55
56
|
# Run the packed scripts
|
56
|
-
$ wasmtime my-ruby-app.wasm
|
57
|
+
$ wasmtime my-ruby-app.wasm /src/my_app.rb
|
57
58
|
Hello
|
58
59
|
```
|
59
60
|
|
@@ -137,14 +138,6 @@ A _build_ is a combination of ruby version, _profile_, and _target_.
|
|
137
138
|
<td><code>full</code></td>
|
138
139
|
<td>All standard extension libraries</td>
|
139
140
|
</tr>
|
140
|
-
<tr>
|
141
|
-
<td><code>*-js</code></td>
|
142
|
-
<td>Enabled JS interoperability, only usable with npm package</td>
|
143
|
-
</tr>
|
144
|
-
<tr>
|
145
|
-
<td><code>*-debug</code></td>
|
146
|
-
<td>With DWARF info and <a href="https://webassembly.github.io/spec/core/appendix/custom.html#name-section" rel="nofollow"><code>name</code> section</a> for debugging</td>
|
147
|
-
</tr>
|
148
141
|
</tbody>
|
149
142
|
</table>
|
150
143
|
|
data/Rakefile
CHANGED
@@ -8,8 +8,6 @@ require "bundler/gem_tasks"
|
|
8
8
|
require "ruby_wasm/rake_task"
|
9
9
|
require "ruby_wasm/packager"
|
10
10
|
|
11
|
-
Dir.glob("tasks/**.rake").each { |f| import f }
|
12
|
-
|
13
11
|
BUILD_SOURCES = %w[3.3 3.2 head]
|
14
12
|
BUILD_PROFILES = %w[full minimal]
|
15
13
|
|
@@ -43,7 +41,8 @@ NPM_PACKAGES = [
|
|
43
41
|
ruby_version: "3.2",
|
44
42
|
gemfile: "packages/npm-packages/ruby-wasm-wasi/Gemfile",
|
45
43
|
target: "wasm32-unknown-wasi"
|
46
|
-
}
|
44
|
+
},
|
45
|
+
{ name: "ruby-wasm-wasi", target: "wasm32-unknown-wasi" }
|
47
46
|
]
|
48
47
|
|
49
48
|
STANDALONE_PACKAGES = [
|
data/benchmarks/vm_deep_call.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
#
|
3
3
|
# Example runs
|
4
4
|
# $ ruby vm_deep_call.rb
|
5
|
-
# $ RUBY_EXE="wasmtime run --
|
6
|
-
# $ RUBY_EXE="wasmtime run --env RUBY_FIBER_MACHINE_STACK_SIZE=20971520 --
|
5
|
+
# $ RUBY_EXE="wasmtime run --dir /::/ head-wasm32-unknown-wasi-minimal/usr/local/bin/ruby --" ruby vm_deep_call.rb
|
6
|
+
# $ RUBY_EXE="wasmtime run --env RUBY_FIBER_MACHINE_STACK_SIZE=20971520 --dir /::/ head-wasm32-unknown-wasi-minimal/usr/local/bin/ruby --" ruby vm_deep_call.rb
|
7
7
|
|
8
8
|
def vm_rec n
|
9
9
|
vm_rec n - 1 if n > 0
|
@@ -22,7 +22,7 @@ ENV PATH=/usr/bin:$PATH
|
|
22
22
|
ENV RUSTUP_HOME=/usr/local/rustup \
|
23
23
|
CARGO_HOME=/usr/local/cargo \
|
24
24
|
PATH=/usr/local/cargo/bin:$PATH \
|
25
|
-
RUST_VERSION=1.
|
25
|
+
RUST_VERSION=1.75
|
26
26
|
|
27
27
|
RUN set -eux pipefail; \
|
28
28
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \
|
@@ -26,7 +26,7 @@ RUN set -eux pipefail; \
|
|
26
26
|
ENV RUSTUP_HOME=/usr/local/rustup \
|
27
27
|
CARGO_HOME=/usr/local/cargo \
|
28
28
|
PATH=/usr/local/cargo/bin:$PATH \
|
29
|
-
RUST_VERSION=1.
|
29
|
+
RUST_VERSION=1.75
|
30
30
|
|
31
31
|
RUN set -eux pipefail; \
|
32
32
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \
|
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.5.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.5.0/dist/browser/+esm";
|
55
|
+
const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.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.5.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.5.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.5.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.5.0/dist/browser/+esm";
|
147
|
+
const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.0/dist/ruby+stdlib.wasm");
|
148
148
|
const module = await WebAssembly.compileStreaming(response);
|
149
149
|
const { vm } = await DefaultRubyVM(module);
|
150
150
|
|
data/ext/ruby_wasm/Cargo.toml
CHANGED
@@ -11,7 +11,6 @@ crate-type = ["cdylib"]
|
|
11
11
|
|
12
12
|
[dependencies]
|
13
13
|
magnus = "0.6.2"
|
14
|
-
wizer = "
|
15
|
-
|
16
|
-
|
17
|
-
wasi-vfs-cli = { git = "https://github.com/kateinoigakukun/wasi-vfs/", rev = "b1e4e5d9cd6322e8745e67c092b495973835a94f" }
|
14
|
+
wizer = "4.0.0"
|
15
|
+
wasi-vfs-cli = { git = "https://github.com/kateinoigakukun/wasi-vfs/", tag = "0.5.2" }
|
16
|
+
structopt = "0.3.26"
|
data/ext/ruby_wasm/src/lib.rs
CHANGED
@@ -7,6 +7,7 @@ use magnus::{
|
|
7
7
|
wrap, Error, ExceptionClass, RModule, Ruby,
|
8
8
|
};
|
9
9
|
use wizer::Wizer;
|
10
|
+
use structopt::StructOpt;
|
10
11
|
|
11
12
|
static RUBY_WASM: value::Lazy<RModule> =
|
12
13
|
value::Lazy::new(|ruby| ruby.define_module("RubyWasmExt").unwrap());
|
@@ -35,6 +36,15 @@ struct WasiVfsInner {
|
|
35
36
|
struct WasiVfs(std::cell::RefCell<WasiVfsInner>);
|
36
37
|
|
37
38
|
impl WasiVfs {
|
39
|
+
fn run_cli(args: Vec<String>) -> Result<(), Error> {
|
40
|
+
wasi_vfs_cli::App::from_iter(args).execute().map_err(|e| {
|
41
|
+
Error::new(
|
42
|
+
exception::standard_error(),
|
43
|
+
format!("failed to run wasi vfs cli: {}", e),
|
44
|
+
)
|
45
|
+
})
|
46
|
+
}
|
47
|
+
|
38
48
|
fn new() -> Self {
|
39
49
|
Self(std::cell::RefCell::new(WasiVfsInner { map_dirs: vec![] }))
|
40
50
|
}
|
@@ -63,6 +73,7 @@ fn init(ruby: &Ruby) -> Result<(), Error> {
|
|
63
73
|
|
64
74
|
let wasi_vfs = module.define_class("WasiVfs", ruby.class_object())?;
|
65
75
|
wasi_vfs.define_singleton_method("new", function!(WasiVfs::new, 0))?;
|
76
|
+
wasi_vfs.define_singleton_method("run_cli", function!(WasiVfs::run_cli, 1))?;
|
66
77
|
wasi_vfs.define_method("map_dir", method!(WasiVfs::map_dir, 2))?;
|
67
78
|
wasi_vfs.define_method("pack", method!(WasiVfs::pack, 1))?;
|
68
79
|
Ok(())
|
@@ -298,6 +298,10 @@ module RubyWasm
|
|
298
298
|
args << %Q(WASI_SDK_PATH=#{wasi_sdk_path.wasi_sdk_path})
|
299
299
|
when "wasm32-unknown-emscripten"
|
300
300
|
ldflags.concat(%w[-s MODULARIZE=1])
|
301
|
+
env_emcc_ldflags = ENV["RUBY_WASM_EMCC_LDFLAGS"] || ""
|
302
|
+
unless env_emcc_ldflags.empty?
|
303
|
+
ldflags << env_emcc_ldflags
|
304
|
+
end
|
301
305
|
else
|
302
306
|
raise "unknown target: #{target}"
|
303
307
|
end
|
@@ -7,11 +7,6 @@ module RubyWasm
|
|
7
7
|
def initialize(build_dir)
|
8
8
|
@build_dir = build_dir
|
9
9
|
@need_fetch_lib = ENV["LIB_WASI_VFS_A"].nil?
|
10
|
-
installed_cli_path =
|
11
|
-
ENV["WASI_VFS_CLI"] || Toolchain.find_path("wasi-vfs")
|
12
|
-
@need_fetch_cli = installed_cli_path.nil?
|
13
|
-
@cli_path =
|
14
|
-
installed_cli_path || File.join(cli_product_build_dir, "wasi-vfs")
|
15
10
|
end
|
16
11
|
|
17
12
|
def lib_product_build_dir
|
@@ -26,18 +21,6 @@ module RubyWasm
|
|
26
21
|
ENV["LIB_WASI_VFS_A"] || File.join(lib_product_build_dir, "libwasi_vfs.a")
|
27
22
|
end
|
28
23
|
|
29
|
-
def cli_product_build_dir
|
30
|
-
File.join(
|
31
|
-
@build_dir,
|
32
|
-
RbConfig::CONFIG["host"],
|
33
|
-
"wasi-vfs-#{WASI_VFS_VERSION}"
|
34
|
-
)
|
35
|
-
end
|
36
|
-
|
37
|
-
def cli_bin_path
|
38
|
-
@cli_path
|
39
|
-
end
|
40
|
-
|
41
24
|
def name
|
42
25
|
"wasi-vfs-#{WASI_VFS_VERSION}-#{RbConfig::CONFIG["host"]}"
|
43
26
|
end
|
@@ -58,26 +41,5 @@ module RubyWasm
|
|
58
41
|
executor.mv File.join(tmpdir, "libwasi_vfs.a"), lib_wasi_vfs_a
|
59
42
|
end
|
60
43
|
end
|
61
|
-
|
62
|
-
def install_cli
|
63
|
-
return if !@need_fetch_cli || File.exist?(cli_bin_path)
|
64
|
-
FileUtils.mkdir_p cli_product_build_dir
|
65
|
-
zipfile = File.join(cli_product_build_dir, "wasi-vfs-cli.zip")
|
66
|
-
system "curl", "-L", "-o", zipfile, self.cli_download_url
|
67
|
-
system "unzip", zipfile, "-d", cli_product_build_dir
|
68
|
-
end
|
69
|
-
|
70
|
-
def cli_download_url
|
71
|
-
assets = [
|
72
|
-
[/x86_64-linux/, "wasi-vfs-cli-x86_64-unknown-linux-gnu.zip"],
|
73
|
-
[/x86_64-darwin/, "wasi-vfs-cli-x86_64-apple-darwin.zip"],
|
74
|
-
[/arm64e?-darwin/, "wasi-vfs-cli-aarch64-apple-darwin.zip"]
|
75
|
-
]
|
76
|
-
asset = assets.find { |os, _| os =~ RUBY_PLATFORM }&.at(1)
|
77
|
-
if asset.nil?
|
78
|
-
raise "unsupported platform for fetching wasi-vfs CLI: #{RUBY_PLATFORM}"
|
79
|
-
end
|
80
|
-
"https://github.com/kateinoigakukun/wasi-vfs/releases/download/v#{WASI_VFS_VERSION}/#{asset}"
|
81
|
-
end
|
82
44
|
end
|
83
45
|
end
|
@@ -4,7 +4,7 @@ module RubyWasm
|
|
4
4
|
class ZlibProduct < AutoconfProduct
|
5
5
|
attr_reader :target
|
6
6
|
|
7
|
-
ZLIB_VERSION = "1.3"
|
7
|
+
ZLIB_VERSION = "1.3.1"
|
8
8
|
|
9
9
|
def initialize(build_dir, target, toolchain)
|
10
10
|
@build_dir = build_dir
|
@@ -46,7 +46,7 @@ module RubyWasm
|
|
46
46
|
"-o",
|
47
47
|
tarball_path,
|
48
48
|
"-L",
|
49
|
-
"https://
|
49
|
+
"https://github.com/madler/zlib/releases/download/v#{ZLIB_VERSION}/zlib-#{ZLIB_VERSION}.tar.gz"
|
50
50
|
executor.system "tar",
|
51
51
|
"xzf",
|
52
52
|
tarball_path,
|
data/lib/ruby_wasm/cli.rb
CHANGED
@@ -9,7 +9,7 @@ module RubyWasm
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def run(args)
|
12
|
-
available_commands = %w[build]
|
12
|
+
available_commands = %w[build pack]
|
13
13
|
parser =
|
14
14
|
OptionParser.new do |opts|
|
15
15
|
opts.banner = <<~USAGE
|
@@ -32,7 +32,10 @@ module RubyWasm
|
|
32
32
|
case command
|
33
33
|
when "build"
|
34
34
|
build(args)
|
35
|
+
when "pack"
|
36
|
+
pack(args)
|
35
37
|
else
|
38
|
+
@stderr.puts "Unknown command: #{command}"
|
36
39
|
@stderr.puts parser
|
37
40
|
exit
|
38
41
|
end
|
@@ -141,6 +144,11 @@ module RubyWasm
|
|
141
144
|
end
|
142
145
|
end
|
143
146
|
|
147
|
+
def pack(args)
|
148
|
+
self.require_extension
|
149
|
+
RubyWasmExt::WasiVfs.run_cli([$0, "pack", *args])
|
150
|
+
end
|
151
|
+
|
144
152
|
private
|
145
153
|
|
146
154
|
def build_config(options)
|
@@ -148,6 +156,10 @@ module RubyWasm
|
|
148
156
|
case options[:profile]
|
149
157
|
when "full"
|
150
158
|
config[:default_exts] = RubyWasm::Packager::ALL_DEFAULT_EXTS
|
159
|
+
env_additional_exts = ENV["RUBY_WASM_ADDITIONAL_EXTS"] || ""
|
160
|
+
unless env_additional_exts.empty?
|
161
|
+
config[:default_exts] += "," + env_additional_exts
|
162
|
+
end
|
151
163
|
when "minimal"
|
152
164
|
config[:default_exts] = ""
|
153
165
|
else
|
@@ -180,7 +192,7 @@ module RubyWasm
|
|
180
192
|
end
|
181
193
|
|
182
194
|
def do_build(executor, tmpdir, packager, options)
|
183
|
-
|
195
|
+
self.require_extension
|
184
196
|
wasm_bytes = packager.package(executor, tmpdir, options)
|
185
197
|
RubyWasm.logger.info "Size: #{SizeFormatter.format(wasm_bytes.size)}"
|
186
198
|
case options[:output]
|
@@ -191,5 +203,15 @@ module RubyWasm
|
|
191
203
|
RubyWasm.logger.debug "Wrote #{options[:output]}"
|
192
204
|
end
|
193
205
|
end
|
206
|
+
|
207
|
+
def require_extension
|
208
|
+
# Tries to require the extension for the given Ruby version first
|
209
|
+
begin
|
210
|
+
RUBY_VERSION =~ /(\d+\.\d+)/
|
211
|
+
require_relative "#{Regexp.last_match(1)}/ruby_wasm.so"
|
212
|
+
rescue LoadError
|
213
|
+
require_relative "ruby_wasm.so"
|
214
|
+
end
|
215
|
+
end
|
194
216
|
end
|
195
217
|
end
|
@@ -98,6 +98,7 @@ class RubyWasm::Packager::FileSystem
|
|
98
98
|
def each_gem_require_path(&block)
|
99
99
|
each_gem_extension_path(&block)
|
100
100
|
@packager.specs.each do |spec|
|
101
|
+
# Use raw_require_paths to exclude extensions
|
101
102
|
spec.raw_require_paths.each do |require_path|
|
102
103
|
source = File.expand_path(require_path, spec.full_gem_path)
|
103
104
|
next unless File.exist?(source)
|
@@ -114,20 +115,20 @@ class RubyWasm::Packager::FileSystem
|
|
114
115
|
@packager.specs.each do |spec|
|
115
116
|
next unless File.exist?(spec.full_gem_path)
|
116
117
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
118
|
+
# spec.files is only valid before the gem is packaged.
|
119
|
+
if spec.source.path?
|
120
|
+
relative_paths = spec.files
|
121
|
+
else
|
122
|
+
# All files in .gem are required.
|
123
|
+
relative_paths = Dir.children(spec.full_gem_path)
|
124
|
+
end
|
125
|
+
relative_paths.each do |require_path|
|
126
|
+
source = File.expand_path(require_path, spec.full_gem_path)
|
127
|
+
next unless File.exist?(source)
|
128
|
+
relative =
|
129
|
+
File.join(bundle_relative_path, "gems", spec.full_name, require_path)
|
130
|
+
yield relative, source
|
131
|
+
end
|
131
132
|
end
|
132
133
|
end
|
133
134
|
|
data/lib/ruby_wasm/packager.rb
CHANGED
@@ -89,7 +89,7 @@ class RubyWasm::Packager
|
|
89
89
|
"head" => {
|
90
90
|
type: "github",
|
91
91
|
repo: "ruby/ruby",
|
92
|
-
rev: "
|
92
|
+
rev: "master",
|
93
93
|
patches: patches.map { |p| File.expand_path(p) }
|
94
94
|
},
|
95
95
|
"3.3" => {
|
@@ -98,7 +98,7 @@ class RubyWasm::Packager
|
|
98
98
|
},
|
99
99
|
"3.2" => {
|
100
100
|
type: "tarball",
|
101
|
-
url: "https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.
|
101
|
+
url: "https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.3.tar.gz"
|
102
102
|
}
|
103
103
|
}
|
104
104
|
sources.each { |name, source| source[:name] = name }
|
data/lib/ruby_wasm/rake_task.rb
CHANGED
data/lib/ruby_wasm/version.rb
CHANGED
data/package-lock.json
CHANGED
@@ -5482,7 +5482,7 @@
|
|
5482
5482
|
},
|
5483
5483
|
"packages/npm-packages/ruby-3.2-wasm-wasi": {
|
5484
5484
|
"name": "@ruby/3.2-wasm-wasi",
|
5485
|
-
"version": "2.
|
5485
|
+
"version": "2.5.0",
|
5486
5486
|
"license": "MIT",
|
5487
5487
|
"dependencies": {
|
5488
5488
|
"@ruby/wasm-wasi": "^2.0.0"
|
@@ -5490,7 +5490,7 @@
|
|
5490
5490
|
},
|
5491
5491
|
"packages/npm-packages/ruby-3.3-wasm-wasi": {
|
5492
5492
|
"name": "@ruby/3.3-wasm-wasi",
|
5493
|
-
"version": "2.
|
5493
|
+
"version": "2.5.0",
|
5494
5494
|
"license": "MIT",
|
5495
5495
|
"dependencies": {
|
5496
5496
|
"@ruby/wasm-wasi": "^2.0.0"
|
@@ -5498,12 +5498,12 @@
|
|
5498
5498
|
},
|
5499
5499
|
"packages/npm-packages/ruby-head-wasm-emscripten": {
|
5500
5500
|
"name": "@ruby/head-wasm-emscripten",
|
5501
|
-
"version": "2.
|
5501
|
+
"version": "2.5.0",
|
5502
5502
|
"license": "MIT"
|
5503
5503
|
},
|
5504
5504
|
"packages/npm-packages/ruby-head-wasm-wasi": {
|
5505
5505
|
"name": "@ruby/head-wasm-wasi",
|
5506
|
-
"version": "2.
|
5506
|
+
"version": "2.5.0",
|
5507
5507
|
"license": "MIT",
|
5508
5508
|
"dependencies": {
|
5509
5509
|
"@ruby/wasm-wasi": "^2.0.0"
|
@@ -5519,7 +5519,7 @@
|
|
5519
5519
|
},
|
5520
5520
|
"packages/npm-packages/ruby-wasm-wasi": {
|
5521
5521
|
"name": "@ruby/wasm-wasi",
|
5522
|
-
"version": "2.
|
5522
|
+
"version": "2.5.0",
|
5523
5523
|
"license": "MIT",
|
5524
5524
|
"dependencies": {
|
5525
5525
|
"tslib": "^2.6.1"
|
data/{tasks → rakelib}/doc.rake
RENAMED
@@ -4,7 +4,12 @@ require "ruby_wasm/version"
|
|
4
4
|
RDoc::Task.new do |doc|
|
5
5
|
doc.main = "README.md"
|
6
6
|
doc.title = "ruby.wasm Documentation"
|
7
|
-
doc.rdoc_files =
|
7
|
+
doc.rdoc_files =
|
8
|
+
FileList.new %w[
|
9
|
+
*.md
|
10
|
+
packages/gems/js/ext/**/*.c
|
11
|
+
packages/gems/js/lib/**/*.rb
|
12
|
+
]
|
8
13
|
end
|
9
14
|
|
10
15
|
namespace :doc do
|
@@ -7,7 +7,8 @@ namespace :format do
|
|
7
7
|
"Rakefile",
|
8
8
|
"lib/**/*.rb",
|
9
9
|
"ext/**/*.rb",
|
10
|
-
"
|
10
|
+
"test/**/*.rb",
|
11
|
+
"rakelib/**/*.rake",
|
11
12
|
"packages/**/*.rb"
|
12
13
|
]
|
13
14
|
)
|
@@ -19,7 +20,7 @@ namespace :format do
|
|
19
20
|
end
|
20
21
|
|
21
22
|
task :c do
|
22
|
-
sh "find
|
23
|
+
sh "find packages/gems/ ext/ -iname *.h -o -iname *.c | xargs clang-format -i"
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
data/{tasks → rakelib}/gem.rake
RENAMED
@@ -10,7 +10,10 @@ end
|
|
10
10
|
begin
|
11
11
|
require "rb_sys/extensiontask"
|
12
12
|
|
13
|
-
|
13
|
+
gemspec = Gem::Specification.load("ruby_wasm.gemspec")
|
14
|
+
RbSys::ExtensionTask.new("ruby_wasm", gemspec) do |ext|
|
15
|
+
ext.lib_dir = "lib/ruby_wasm"
|
16
|
+
end
|
14
17
|
rescue LoadError => e
|
15
18
|
task :compile do
|
16
19
|
$stderr.puts "Skipping compilation of ruby_wasm extension: #{e.message}"
|
@@ -1,11 +1,13 @@
|
|
1
1
|
wasi_vfs = RubyWasm::WasiVfsProduct.new(File.join(Dir.pwd, "build"))
|
2
2
|
wasi_sdk = TOOLCHAINS["wasi-sdk"]
|
3
3
|
tools = {
|
4
|
-
"WASI_VFS_CLI" =>
|
4
|
+
"WASI_VFS_CLI" => File.expand_path(File.join(__dir__, "..", "exe", "rbwasm")),
|
5
5
|
"WASMOPT" => wasi_sdk.wasm_opt
|
6
6
|
}
|
7
7
|
|
8
8
|
def npm_pkg_build_command(pkg)
|
9
|
+
# Skip if the package does not require building ruby
|
10
|
+
return nil unless pkg[:ruby_version] && pkg[:target]
|
9
11
|
[
|
10
12
|
"bundle",
|
11
13
|
"exec",
|
@@ -22,6 +24,7 @@ end
|
|
22
24
|
|
23
25
|
def npm_pkg_rubies_cache_key(pkg)
|
24
26
|
build_command = npm_pkg_build_command(pkg)
|
27
|
+
return nil unless build_command
|
25
28
|
require "open3"
|
26
29
|
cmd = build_command + ["--print-ruby-cache-key"]
|
27
30
|
stdout, status = Open3.capture2(*cmd)
|
@@ -38,10 +41,12 @@ namespace :npm do
|
|
38
41
|
pkg_dir = "#{Dir.pwd}/packages/npm-packages/#{pkg[:name]}"
|
39
42
|
|
40
43
|
namespace pkg[:name] do
|
41
|
-
build_command = npm_pkg_build_command(pkg)
|
42
|
-
|
43
44
|
desc "Build ruby for npm package #{pkg[:name]}"
|
44
45
|
task "ruby" do
|
46
|
+
build_command = npm_pkg_build_command(pkg)
|
47
|
+
# Skip if the package does not require building ruby
|
48
|
+
next unless build_command
|
49
|
+
|
45
50
|
env = {
|
46
51
|
# Share ./build and ./rubies in the same workspace
|
47
52
|
"RUBY_WASM_ROOT" => base_dir
|
@@ -93,7 +98,6 @@ namespace :npm do
|
|
93
98
|
|
94
99
|
desc "Make tarball for npm package #{pkg[:name]}"
|
95
100
|
task pkg[:name] do
|
96
|
-
wasi_vfs.install_cli
|
97
101
|
wasi_sdk.install_binaryen
|
98
102
|
Rake::Task["npm:#{pkg[:name]}:build"].invoke
|
99
103
|
sh "npm pack", chdir: pkg_dir
|
@@ -137,7 +141,6 @@ namespace :standalone do
|
|
137
141
|
|
138
142
|
desc "Build standalone package #{pkg[:name]}"
|
139
143
|
task "#{pkg[:name]}" => ["build:#{pkg[:build]}"] do
|
140
|
-
wasi_vfs.install_cli
|
141
144
|
wasi_sdk.install_binaryen
|
142
145
|
base_dir = Dir.pwd
|
143
146
|
sh tools,
|
@@ -35,4 +35,6 @@ task :bump_version, %i[version] do |t, args|
|
|
35
35
|
NPM_PACKAGES.each { |pkg| bump_version_npm_package(pkg[:name], version) }
|
36
36
|
# Update ./package-lock.json
|
37
37
|
sh "npm install"
|
38
|
+
# Update Gemfile.lock
|
39
|
+
sh "BUNDLE_GEMFILE=packages/npm-packages/ruby-wasm-wasi/Gemfile bundle install"
|
38
40
|
end
|
data/sig/ruby_wasm/build.rbs
CHANGED
@@ -135,12 +135,8 @@ module RubyWasm
|
|
135
135
|
def initialize: (String build_dir) -> void
|
136
136
|
def lib_product_build_dir: -> String
|
137
137
|
def lib_wasi_vfs_a: -> String
|
138
|
-
def cli_product_build_dir: -> String
|
139
|
-
def cli_bin_path: -> String
|
140
138
|
def name: -> String
|
141
139
|
def build: (BuildExecutor executor) -> void
|
142
|
-
def install_cli: -> bool?
|
143
|
-
def cli_download_url: -> String
|
144
140
|
end
|
145
141
|
|
146
142
|
class CrossRubyExtProduct < BuildProduct
|
data/sig/ruby_wasm/cli.rbs
CHANGED
@@ -8,6 +8,7 @@ module RubyWasm
|
|
8
8
|
def initialize: (stdout: IO, stderr: IO) -> void
|
9
9
|
|
10
10
|
def build: (Array[String] args) -> void
|
11
|
+
def pack: (Array[String] args) -> void
|
11
12
|
|
12
13
|
private
|
13
14
|
|
@@ -16,6 +17,8 @@ module RubyWasm
|
|
16
17
|
def derive_packager: (Hash[untyped, untyped] options) -> Packager
|
17
18
|
def do_print_ruby_cache_key: (Packager) -> void
|
18
19
|
def do_build: (BuildExecutor, string tmpdir, Packager, Hash[untyped, untyped] options) -> void
|
20
|
+
|
21
|
+
def require_extension: () -> void
|
19
22
|
end
|
20
23
|
|
21
24
|
self.@logger: Logger?
|
data/sig/ruby_wasm/ext.rbs
CHANGED
@@ -4,8 +4,10 @@ module RubyWasmExt
|
|
4
4
|
class WasiVfs
|
5
5
|
def initialize: () -> void
|
6
6
|
|
7
|
+
def self.run_cli: (Array[String] args) -> void
|
8
|
+
|
7
9
|
def map_dir: (String guest_path, String host_path) -> void
|
8
10
|
|
9
11
|
def pack: (Array[Integer] module_bytes) -> Array[Integer]
|
10
12
|
end
|
11
|
-
end
|
13
|
+
end
|