Skip to content

Commit

Permalink
Merge pull request #568 from ruby/katei/3.4
Browse files Browse the repository at this point in the history
Add Ruby 3.4 support
  • Loading branch information
kateinoigakukun authored Jan 23, 2025
2 parents c57392a + 3c33a99 commit 4f9aef8
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 14 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Create and save `index.html` page with the following contents:

```html
<html>
<script src="https://cdn.jsdelivr.net/npm/@ruby/3.3[email protected]/dist/browser.script.iife.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@ruby/3.4[email protected]/dist/browser.script.iife.js"></script>
<script type="text/ruby">
require "js"
Expand All @@ -40,18 +40,18 @@ Dependencies: [wasmtime](https://github.com/bytecodealliance/wasmtime)
```console
$ gem install ruby_wasm
# Download a prebuilt Ruby release
$ curl -LO https://github.com/ruby/ruby.wasm/releases/latest/download/ruby-3.3-wasm32-unknown-wasip1-full.tar.gz
$ tar xfz ruby-3.3-wasm32-unknown-wasip1-full.tar.gz
$ curl -LO https://github.com/ruby/ruby.wasm/releases/latest/download/ruby-3.4-wasm32-unknown-wasip1-full.tar.gz
$ tar xfz ruby-3.4-wasm32-unknown-wasip1-full.tar.gz

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

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

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

# Run the packed scripts
$ wasmtime my-ruby-app.wasm /src/my_app.rb
Expand All @@ -71,6 +71,11 @@ See the `README.md` of each package for more detail and its usage.
</tr>
</thead>
<tbody>
<tr>
<td><a href="/packages/npm-packages/ruby-3.4-wasm-wasi">@ruby/3.4-wasm-wasi</a></td>
<td>CRuby 3.4 built on WASI with JS interop support</td>
<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>
</tr>
<tr>
<td><a href="/packages/npm-packages/ruby-3.3-wasm-wasi">@ruby/3.3-wasm-wasi</a></td>
<td>CRuby 3.3 built on WASI with JS interop support</td>
Expand Down
8 changes: 7 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require "ruby_wasm/rake_task"
require "ruby_wasm/packager"
require "ruby_wasm/cli"

BUILD_SOURCES = %w[3.3 3.2 head]
BUILD_SOURCES = %w[3.4 3.3 3.2 head]
BUILD_PROFILES = %w[full minimal]

BUILDS =
Expand Down Expand Up @@ -38,6 +38,12 @@ NPM_PACKAGES = [
target: "wasm32-unknown-wasip2",
enable_component_model: true,
},
{
name: "ruby-3.4-wasm-wasi",
ruby_version: "3.4",
gemfile: "packages/npm-packages/ruby-3.3-wasm-wasi/Gemfile",
target: "wasm32-unknown-wasip1"
},
{
name: "ruby-3.3-wasm-wasi",
ruby_version: "3.3",
Expand Down
16 changes: 8 additions & 8 deletions docs/cheat_sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

## Node.js

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

```console
npm install --save @ruby/3.3-wasm-wasi @ruby/wasm-wasi
npm install --save @ruby/3.4-wasm-wasi @ruby/wasm-wasi
```

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

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

```html
<html>
<script src="https://cdn.jsdelivr.net/npm/@ruby/3.3[email protected]/dist/browser.script.iife.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@ruby/3.4[email protected]/dist/browser.script.iife.js"></script>
<script type="text/ruby">
require "js"
JS.global[:document].write "Hello, world!"
Expand All @@ -52,7 +52,7 @@ If you want to control Ruby VM from JavaScript, you can use `@ruby/wasm-wasi` pa
<html>
<script type="module">
import { DefaultRubyVM } from "https://cdn.jsdelivr.net/npm/@ruby/[email protected]/dist/browser/+esm";
const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.3[email protected]/dist/ruby+stdlib.wasm");
const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.4[email protected]/dist/ruby+stdlib.wasm");
const module = await WebAssembly.compileStreaming(response);
const { vm } = await DefaultRubyVM(module);
Expand All @@ -73,7 +73,7 @@ If you want to control Ruby VM from JavaScript, you can use `@ruby/wasm-wasi` pa
<script>
const main = async () => {
const { DefaultRubyVM } = window["ruby-wasm-wasi"];
const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.3[email protected]/dist/ruby+stdlib.wasm");
const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.4[email protected]/dist/ruby+stdlib.wasm");
const module = await WebAssembly.compileStreaming(response);
const { vm } = await DefaultRubyVM(module);
Expand Down Expand Up @@ -128,7 +128,7 @@ end

```html
<html>
<script src="https://cdn.jsdelivr.net/npm/@ruby/3.3[email protected]/dist/browser.script.iife.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@ruby/3.4[email protected]/dist/browser.script.iife.js"></script>
<script type="text/ruby" data-eval="async">
require "js"
Expand All @@ -144,7 +144,7 @@ Or using `@ruby/wasm-wasi` package API `RubyVM#evalAsync`:
<html>
<script type="module">
import { DefaultRubyVM } from "https://cdn.jsdelivr.net/npm/@ruby/[email protected]/dist/browser/+esm";
const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.3[email protected]/dist/ruby+stdlib.wasm");
const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.4[email protected]/dist/ruby+stdlib.wasm");
const module = await WebAssembly.compileStreaming(response);
const { vm } = await DefaultRubyVM(module);
Expand Down
5 changes: 5 additions & 0 deletions lib/ruby_wasm/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ def self.build_source_aliases(root)
rev: "master",
all_default_exts: RubyWasm::Packager::ALL_DEFAULT_EXTS,
},
"3.4" => {
type: "tarball",
url: "https://cache.ruby-lang.org/pub/ruby/3.4/ruby-3.4.1.tar.gz",
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",
},
"3.3" => {
type: "tarball",
url: "https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.3.tar.gz",
Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/npm-packages/ruby-3.4-wasm-wasi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.tgz
/tmp
/bundle
/vendor
15 changes: 15 additions & 0 deletions packages/npm-packages/ruby-3.4-wasm-wasi/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

source "https://rubygems.org"

# We build ./vendor/cache/js-{version}.gem just before evaluating this Gemfile
# so that Bundler builds extensions even from the local gem. (gem extensions
# from "path:" gems are not built by Bundler.)
# Thus even we specify version of "js" gem here, it should always installed
# from the ./vendor/cache/js-{version}.gem, not from rubygems.org. To achieve this,
# we always use non-exist version during development.
require_relative "../../gems/js/lib/js/version.rb"
gem "js", JS::VERSION
gem "ruby_wasm", path: "../../../", group: [:build]
gem "power_assert"
gem "test-unit"
25 changes: 25 additions & 0 deletions packages/npm-packages/ruby-3.4-wasm-wasi/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
PATH
remote: ../../..
specs:
ruby_wasm (2.7.0.dev)

GEM
remote: https://rubygems.org/
specs:
js (2.7.0.dev)
power_assert (2.0.3)
test-unit (3.6.2)
power_assert

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
js (= 2.7.0.dev)
power_assert
ruby_wasm!
test-unit

BUNDLED WITH
2.6.0.dev
7 changes: 7 additions & 0 deletions packages/npm-packages/ruby-3.4-wasm-wasi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @ruby/3.4-wasm-wasi

[![npm version](https://badge.fury.io/js/@ruby%2F3.4-wasm-wasi.svg)](https://www.npmjs.com/package/@ruby/3.4-wasm-wasi)

This package provides WebAssembly binaries of CRuby built from the latest `3.4` source code targeting environments compatible with WASI Preview1.

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.
55 changes: 55 additions & 0 deletions packages/npm-packages/ruby-3.4-wasm-wasi/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "@ruby/3.4-wasm-wasi",
"version": "2.7.0",
"description": "Ruby 3.4 built on WASI",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"exports": {
".": {
"browser": "./dist/esm/index.js",
"umd": "./dist/umd/index.js",
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
},
"./dist/*": {
"browser": "./dist/esm/*.js",
"umd": "./dist/umd/*.js",
"import": "./dist/esm/*.js",
"require": "./dist/cjs/*.js"
},
"./*.wasm": {
"browser": "./*.wasm",
"umd": "./*.wasm",
"import": "./*.wasm",
"require": "./*.wasm"
}
},
"files": [
"dist",
"README.md"
],
"scripts": {
"test": "RUBY_NPM_PACKAGE_ROOT=../ruby-3.4-wasm-wasi npm -C ../ruby-wasm-wasi run test:run",
"build:deps": "cd ../ruby-wasm-wasi && npm run build",
"build:static:files": "../ruby-wasm-wasi/tools/pack-static-files.sh ./dist",
"build:static:compat": "../ruby-wasm-wasi/tools/pack-compat-shim.mjs --dist=./dist --pkg=ruby-3.4-wasm-wasi",
"build:static": "npm run build:static:files && npm run build:static:compat",
"build:rollup": "rollup -c rollup.config.mjs",
"build": "npm run build:deps && npm run build:static && npm run build:rollup && ../ruby-wasm-wasi/tools/post-build.sh ./dist"
},
"repository": "https://github.com/ruby/ruby.wasm",
"homepage": "https://github.com/ruby/ruby.wasm/tree/main/packages/npm-packages/ruby-3.4-wasm-wasi",
"publishConfig": {
"access": "public"
},
"keywords": [
"wasm",
"webassembly",
"wasi",
"ruby"
],
"license": "MIT",
"dependencies": {
"@ruby/wasm-wasi": "^2.0.0"
}
}
21 changes: 21 additions & 0 deletions packages/npm-packages/ruby-3.4-wasm-wasi/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import json from "@rollup/plugin-json";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import fs from "fs";
import path from "path";

/** @type {import('rollup').RollupOptions[]} */
export default [
{
input: "src/browser.script.js",
output: [
{
file: "dist/browser.script.iife.js",
format: "iife",
banner: "/* " + fs.readFileSync(path.resolve("../../../NOTICE"), "utf8") + "*/",
}
],
plugins: [
json(), nodeResolve()
],
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

import { main } from "@ruby/wasm-wasi/dist/browser.script"
import * as pkg from "../package.json"

main(pkg)
1 change: 1 addition & 0 deletions packages/npm-packages/ruby-wasm-wasi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ See [Cheat Sheet](https://github.com/ruby/ruby.wasm/blob/main/docs/cheat_sheet.m
| Version | Package |
| ------- | --------------------------------------------------------------------------------------------------------------- |
| `head` | [`@ruby/head-wasm-wasi`](https://github.com/ruby/ruby.wasm/tree/main/packages/npm-packages/ruby-head-wasm-wasi) |
| `3.4` | [`@ruby/3.4-wasm-wasi`](https://github.com/ruby/ruby.wasm/tree/main/packages/npm-packages/ruby-3.4-wasm-wasi) |
| `3.3` | [`@ruby/3.3-wasm-wasi`](https://github.com/ruby/ruby.wasm/tree/main/packages/npm-packages/ruby-3.3-wasm-wasi) |
| `3.2` | [`@ruby/3.2-wasm-wasi`](https://github.com/ruby/ruby.wasm/tree/main/packages/npm-packages/ruby-3.2-wasm-wasi) |

Expand Down

0 comments on commit 4f9aef8

Please sign in to comment.