-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #568 from ruby/katei/3.4
Add Ruby 3.4 support
- Loading branch information
Showing
13 changed files
with
174 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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 | ||
|
@@ -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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
|
@@ -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"`); | ||
|
@@ -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!" | ||
|
@@ -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); | ||
|
@@ -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); | ||
|
@@ -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" | ||
|
@@ -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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.tgz | ||
/tmp | ||
/bundle | ||
/vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
packages/npm-packages/ruby-3.4-wasm-wasi/rollup.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
], | ||
}, | ||
]; |
5 changes: 5 additions & 0 deletions
5
packages/npm-packages/ruby-3.4-wasm-wasi/src/browser.script.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters