Skip to content

Commit 3c33a99

Browse files
Add Ruby 3.4 support
1 parent 1998b72 commit 3c33a99

File tree

13 files changed

+174
-14
lines changed

13 files changed

+174
-14
lines changed

README.md

+10-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Create and save `index.html` page with the following contents:
2323

2424
```html
2525
<html>
26-
<script src="https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.7.0/dist/browser.script.iife.js"></script>
26+
<script src="https://cdn.jsdelivr.net/npm/@ruby/3.4-wasm-wasi@2.7.0/dist/browser.script.iife.js"></script>
2727
<script type="text/ruby">
2828
require "js"
2929
@@ -40,18 +40,18 @@ Dependencies: [wasmtime](https://github.com/bytecodealliance/wasmtime)
4040
```console
4141
$ gem install ruby_wasm
4242
# Download a prebuilt Ruby release
43-
$ curl -LO https://github.com/ruby/ruby.wasm/releases/latest/download/ruby-3.3-wasm32-unknown-wasip1-full.tar.gz
44-
$ tar xfz ruby-3.3-wasm32-unknown-wasip1-full.tar.gz
43+
$ curl -LO https://github.com/ruby/ruby.wasm/releases/latest/download/ruby-3.4-wasm32-unknown-wasip1-full.tar.gz
44+
$ tar xfz ruby-3.4-wasm32-unknown-wasip1-full.tar.gz
4545

4646
# Extract ruby binary not to pack itself
47-
$ mv ruby-3.3-wasm32-unknown-wasip1-full/usr/local/bin/ruby ruby.wasm
47+
$ mv ruby-3.4-wasm32-unknown-wasip1-full/usr/local/bin/ruby ruby.wasm
4848

4949
# Put your app code
5050
$ mkdir src
5151
$ echo "puts 'Hello'" > src/my_app.rb
5252

5353
# Pack the whole directory under /usr and your app dir
54-
$ rbwasm pack ruby.wasm --dir ./src::/src --dir ./ruby-3.3-wasm32-unknown-wasip1-full/usr::/usr -o my-ruby-app.wasm
54+
$ rbwasm pack ruby.wasm --dir ./src::/src --dir ./ruby-3.4-wasm32-unknown-wasip1-full/usr::/usr -o my-ruby-app.wasm
5555

5656
# Run the packed scripts
5757
$ wasmtime my-ruby-app.wasm /src/my_app.rb
@@ -71,6 +71,11 @@ See the `README.md` of each package for more detail and its usage.
7171
</tr>
7272
</thead>
7373
<tbody>
74+
<tr>
75+
<td><a href="/packages/npm-packages/ruby-3.4-wasm-wasi">@ruby/3.4-wasm-wasi</a></td>
76+
<td>CRuby 3.4 built on WASI with JS interop support</td>
77+
<td><a href="https://www.npmjs.com/package/@ruby/3.4-wasm-wasi" rel="nofollow"><img src="https://badge.fury.io/js/@ruby%2F3.4-wasm-wasi.svg" alt="npm version" style="max-width: 100%;"></a></td>
78+
</tr>
7479
<tr>
7580
<td><a href="/packages/npm-packages/ruby-3.3-wasm-wasi">@ruby/3.3-wasm-wasi</a></td>
7681
<td>CRuby 3.3 built on WASI with JS interop support</td>

Rakefile

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require "ruby_wasm/rake_task"
99
require "ruby_wasm/packager"
1010
require "ruby_wasm/cli"
1111

12-
BUILD_SOURCES = %w[3.3 3.2 head]
12+
BUILD_SOURCES = %w[3.4 3.3 3.2 head]
1313
BUILD_PROFILES = %w[full minimal]
1414

1515
BUILDS =
@@ -38,6 +38,12 @@ NPM_PACKAGES = [
3838
target: "wasm32-unknown-wasip2",
3939
enable_component_model: true,
4040
},
41+
{
42+
name: "ruby-3.4-wasm-wasi",
43+
ruby_version: "3.4",
44+
gemfile: "packages/npm-packages/ruby-3.3-wasm-wasi/Gemfile",
45+
target: "wasm32-unknown-wasip1"
46+
},
4147
{
4248
name: "ruby-3.3-wasm-wasi",
4349
ruby_version: "3.3",

docs/cheat_sheet.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
## Node.js
1010

11-
To install the package, install `@ruby/3.3-wasm-wasi` and `@ruby/wasm-wasi` from npm:
11+
To install the package, install `@ruby/3.4-wasm-wasi` and `@ruby/wasm-wasi` from npm:
1212

1313
```console
14-
npm install --save @ruby/3.3-wasm-wasi @ruby/wasm-wasi
14+
npm install --save @ruby/3.4-wasm-wasi @ruby/wasm-wasi
1515
```
1616

1717
Then instantiate a Ruby VM by the following code:
@@ -20,7 +20,7 @@ Then instantiate a Ruby VM by the following code:
2020
import fs from "fs/promises";
2121
import { DefaultRubyVM } from "@ruby/wasm-wasi/dist/node";
2222

23-
const binary = await fs.readFile("./node_modules/@ruby/3.3-wasm-wasi/dist/ruby.wasm");
23+
const binary = await fs.readFile("./node_modules/@ruby/3.4-wasm-wasi/dist/ruby.wasm");
2424
const module = await WebAssembly.compile(binary);
2525
const { vm } = await DefaultRubyVM(module);
2626
vm.eval(`puts "hello world"`);
@@ -38,7 +38,7 @@ The easiest way to run Ruby on browser is to use `browser.script.iife.js` script
3838

3939
```html
4040
<html>
41-
<script src="https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.7.0/dist/browser.script.iife.js"></script>
41+
<script src="https://cdn.jsdelivr.net/npm/@ruby/3.4-wasm-wasi@2.7.0/dist/browser.script.iife.js"></script>
4242
<script type="text/ruby">
4343
require "js"
4444
JS.global[:document].write "Hello, world!"
@@ -52,7 +52,7 @@ If you want to control Ruby VM from JavaScript, you can use `@ruby/wasm-wasi` pa
5252
<html>
5353
<script type="module">
5454
import { DefaultRubyVM } from "https://cdn.jsdelivr.net/npm/@ruby/wasm-wasi@2.7.0/dist/browser/+esm";
55-
const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.7.0/dist/ruby+stdlib.wasm");
55+
const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.4-wasm-wasi@2.7.0/dist/ruby+stdlib.wasm");
5656
const module = await WebAssembly.compileStreaming(response);
5757
const { vm } = await DefaultRubyVM(module);
5858
@@ -73,7 +73,7 @@ If you want to control Ruby VM from JavaScript, you can use `@ruby/wasm-wasi` pa
7373
<script>
7474
const main = async () => {
7575
const { DefaultRubyVM } = window["ruby-wasm-wasi"];
76-
const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.7.0/dist/ruby+stdlib.wasm");
76+
const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.4-wasm-wasi@2.7.0/dist/ruby+stdlib.wasm");
7777
const module = await WebAssembly.compileStreaming(response);
7878
const { vm } = await DefaultRubyVM(module);
7979
@@ -128,7 +128,7 @@ end
128128

129129
```html
130130
<html>
131-
<script src="https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.7.0/dist/browser.script.iife.js"></script>
131+
<script src="https://cdn.jsdelivr.net/npm/@ruby/3.4-wasm-wasi@2.7.0/dist/browser.script.iife.js"></script>
132132
<script type="text/ruby" data-eval="async">
133133
require "js"
134134
@@ -144,7 +144,7 @@ Or using `@ruby/wasm-wasi` package API `RubyVM#evalAsync`:
144144
<html>
145145
<script type="module">
146146
import { DefaultRubyVM } from "https://cdn.jsdelivr.net/npm/@ruby/wasm-wasi@2.7.0/dist/browser/+esm";
147-
const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.7.0/dist/ruby+stdlib.wasm");
147+
const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.4-wasm-wasi@2.7.0/dist/ruby+stdlib.wasm");
148148
const module = await WebAssembly.compileStreaming(response);
149149
const { vm } = await DefaultRubyVM(module);
150150

lib/ruby_wasm/cli.rb

+5
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ def self.build_source_aliases(root)
242242
rev: "master",
243243
all_default_exts: RubyWasm::Packager::ALL_DEFAULT_EXTS,
244244
},
245+
"3.4" => {
246+
type: "tarball",
247+
url: "https://cache.ruby-lang.org/pub/ruby/3.4/ruby-3.4.1.tar.gz",
248+
all_default_exts: "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",
249+
},
245250
"3.3" => {
246251
type: "tarball",
247252
url: "https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.3.tar.gz",

package-lock.json

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.tgz
2+
/tmp
3+
/bundle
4+
/vendor
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
# We build ./vendor/cache/js-{version}.gem just before evaluating this Gemfile
6+
# so that Bundler builds extensions even from the local gem. (gem extensions
7+
# from "path:" gems are not built by Bundler.)
8+
# Thus even we specify version of "js" gem here, it should always installed
9+
# from the ./vendor/cache/js-{version}.gem, not from rubygems.org. To achieve this,
10+
# we always use non-exist version during development.
11+
require_relative "../../gems/js/lib/js/version.rb"
12+
gem "js", JS::VERSION
13+
gem "ruby_wasm", path: "../../../", group: [:build]
14+
gem "power_assert"
15+
gem "test-unit"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
PATH
2+
remote: ../../..
3+
specs:
4+
ruby_wasm (2.7.0.dev)
5+
6+
GEM
7+
remote: https://rubygems.org/
8+
specs:
9+
js (2.7.0.dev)
10+
power_assert (2.0.3)
11+
test-unit (3.6.2)
12+
power_assert
13+
14+
PLATFORMS
15+
ruby
16+
x86_64-linux
17+
18+
DEPENDENCIES
19+
js (= 2.7.0.dev)
20+
power_assert
21+
ruby_wasm!
22+
test-unit
23+
24+
BUNDLED WITH
25+
2.6.0.dev
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# @ruby/3.4-wasm-wasi
2+
3+
[![npm version](https://badge.fury.io/js/@ruby%2F3.4-wasm-wasi.svg)](https://www.npmjs.com/package/@ruby/3.4-wasm-wasi)
4+
5+
This package provides WebAssembly binaries of CRuby built from the latest `3.4` source code targeting environments compatible with WASI Preview1.
6+
7+
See [`@ruby/wasm-wasi`](https://github.com/ruby/ruby.wasm/blob/main/packages/npm-packages/ruby-wasm-wasi/README.md) for how to use this package.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"name": "@ruby/3.4-wasm-wasi",
3+
"version": "2.7.0",
4+
"description": "Ruby 3.4 built on WASI",
5+
"main": "./dist/cjs/index.js",
6+
"module": "./dist/esm/index.js",
7+
"exports": {
8+
".": {
9+
"browser": "./dist/esm/index.js",
10+
"umd": "./dist/umd/index.js",
11+
"import": "./dist/esm/index.js",
12+
"require": "./dist/cjs/index.js"
13+
},
14+
"./dist/*": {
15+
"browser": "./dist/esm/*.js",
16+
"umd": "./dist/umd/*.js",
17+
"import": "./dist/esm/*.js",
18+
"require": "./dist/cjs/*.js"
19+
},
20+
"./*.wasm": {
21+
"browser": "./*.wasm",
22+
"umd": "./*.wasm",
23+
"import": "./*.wasm",
24+
"require": "./*.wasm"
25+
}
26+
},
27+
"files": [
28+
"dist",
29+
"README.md"
30+
],
31+
"scripts": {
32+
"test": "RUBY_NPM_PACKAGE_ROOT=../ruby-3.4-wasm-wasi npm -C ../ruby-wasm-wasi run test:run",
33+
"build:deps": "cd ../ruby-wasm-wasi && npm run build",
34+
"build:static:files": "../ruby-wasm-wasi/tools/pack-static-files.sh ./dist",
35+
"build:static:compat": "../ruby-wasm-wasi/tools/pack-compat-shim.mjs --dist=./dist --pkg=ruby-3.4-wasm-wasi",
36+
"build:static": "npm run build:static:files && npm run build:static:compat",
37+
"build:rollup": "rollup -c rollup.config.mjs",
38+
"build": "npm run build:deps && npm run build:static && npm run build:rollup && ../ruby-wasm-wasi/tools/post-build.sh ./dist"
39+
},
40+
"repository": "https://github.com/ruby/ruby.wasm",
41+
"homepage": "https://github.com/ruby/ruby.wasm/tree/main/packages/npm-packages/ruby-3.4-wasm-wasi",
42+
"publishConfig": {
43+
"access": "public"
44+
},
45+
"keywords": [
46+
"wasm",
47+
"webassembly",
48+
"wasi",
49+
"ruby"
50+
],
51+
"license": "MIT",
52+
"dependencies": {
53+
"@ruby/wasm-wasi": "^2.0.0"
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import json from "@rollup/plugin-json";
2+
import { nodeResolve } from "@rollup/plugin-node-resolve";
3+
import fs from "fs";
4+
import path from "path";
5+
6+
/** @type {import('rollup').RollupOptions[]} */
7+
export default [
8+
{
9+
input: "src/browser.script.js",
10+
output: [
11+
{
12+
file: "dist/browser.script.iife.js",
13+
format: "iife",
14+
banner: "/* " + fs.readFileSync(path.resolve("../../../NOTICE"), "utf8") + "*/",
15+
}
16+
],
17+
plugins: [
18+
json(), nodeResolve()
19+
],
20+
},
21+
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
import { main } from "@ruby/wasm-wasi/dist/browser.script"
3+
import * as pkg from "../package.json"
4+
5+
main(pkg)

packages/npm-packages/ruby-wasm-wasi/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ See [Cheat Sheet](https://github.com/ruby/ruby.wasm/blob/main/docs/cheat_sheet.m
1111
| Version | Package |
1212
| ------- | --------------------------------------------------------------------------------------------------------------- |
1313
| `head` | [`@ruby/head-wasm-wasi`](https://github.com/ruby/ruby.wasm/tree/main/packages/npm-packages/ruby-head-wasm-wasi) |
14+
| `3.4` | [`@ruby/3.4-wasm-wasi`](https://github.com/ruby/ruby.wasm/tree/main/packages/npm-packages/ruby-3.4-wasm-wasi) |
1415
| `3.3` | [`@ruby/3.3-wasm-wasi`](https://github.com/ruby/ruby.wasm/tree/main/packages/npm-packages/ruby-3.3-wasm-wasi) |
1516
| `3.2` | [`@ruby/3.2-wasm-wasi`](https://github.com/ruby/ruby.wasm/tree/main/packages/npm-packages/ruby-3.2-wasm-wasi) |
1617

0 commit comments

Comments
 (0)