Skip to content

Commit 7660c13

Browse files
Split out Component binaries into @ruby/wasm-wasip2 package
The `@ruby/wasm-wasi` package included both the Core Module and the Component binaries but it has two problems: 1. npm package size was too large and it was very close to the limit of the jsdelivr CDN. 2. The Component model build (in other words, dynamic linking build) well supports incremental build. But the Core Module build does not because it requires to re-link C-extensions every time statically. And it led to clean build every time. Splitting out the Component build makes the p2 package itself incremental buildable.
1 parent 71c25d8 commit 7660c13

File tree

14 files changed

+225
-48
lines changed

14 files changed

+225
-48
lines changed

Rakefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ NPM_PACKAGES = [
3030
ruby_version: "head",
3131
gemfile: "packages/npm-packages/ruby-head-wasm-wasi/Gemfile",
3232
target: "wasm32-unknown-wasip1",
33+
},
34+
{
35+
name: "ruby-head-wasm-wasip2",
36+
ruby_version: "head",
37+
gemfile: "packages/npm-packages/ruby-head-wasm-wasip2/Gemfile",
38+
target: "wasm32-unknown-wasip2",
3339
enable_component_model: true,
3440
},
3541
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
[![npm version](https://badge.fury.io/js/@ruby%2Fhead-wasm-wasi.svg)](https://www.npmjs.com/package/@ruby/head-wasm-wasi)
44

5-
This package provides WebAssembly binaries of CRuby built from the latest `HEAD` source code targeting WASI-compatible environments.
5+
This package provides WebAssembly binaries of CRuby built from the latest `HEAD` source code targeting environments compatible with WASI Preview1.
66

77
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.

packages/npm-packages/ruby-head-wasm-wasi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"README.md"
3030
],
3131
"scripts": {
32-
"test": "RUBY_NPM_PACKAGE_ROOT=../ruby-head-wasm-wasi npm -C ../ruby-wasm-wasi run test:run:all",
32+
"test": "RUBY_NPM_PACKAGE_ROOT=../ruby-head-wasm-wasi npm -C ../ruby-wasm-wasi run test:run",
3333
"build:deps": "cd ../ruby-wasm-wasi && npm run build",
3434
"build:static:files": "../ruby-wasm-wasi/tools/pack-static-files.sh ./dist",
3535
"build:static:compat": "../ruby-wasm-wasi/tools/pack-compat-shim.mjs --dist=./dist --pkg=ruby-head-wasm-wasi",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.tgz
2+
/tmp
3+
/bundle
4+
/vendor
Lines changed: 15 additions & 0 deletions
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"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
PATH
2+
remote: ../../..
3+
specs:
4+
ruby_wasm (2.6.2.dev)
5+
6+
GEM
7+
remote: https://rubygems.org/
8+
specs:
9+
js (2.6.2.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.6.2.dev)
20+
power_assert
21+
ruby_wasm!
22+
test-unit
23+
24+
BUNDLED WITH
25+
2.6.0.dev
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# @ruby/head-wasm-wasip2
2+
3+
[![npm version](https://badge.fury.io/js/@ruby%2Fhead-wasm-wasip2.svg)](https://www.npmjs.com/package/@ruby/head-wasm-wasip2)
4+
5+
This package provides WebAssembly binaries of CRuby built from the latest `HEAD` source code targeting environments compatible with WASI Preview2.
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.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "@ruby/head-wasm-wasip2",
3+
"version": "2.6.2",
4+
"description": "Ruby head built on WASI Preview 2",
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-head-wasm-wasi ENABLE_COMPONENT_TESTS=1 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-head-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-head-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+
"@bytecodealliance/preview2-shim": "^0.16.5"
55+
}
56+
}
Lines changed: 21 additions & 0 deletions
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+
];
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { instantiate } from "../dist/component/ruby.component"
2+
import { componentMain } from "@ruby/wasm-wasi/dist/browser.script"
3+
import * as wasip2 from "@bytecodealliance/preview2-shim"
4+
import * as pkg from "../package.json"
5+
6+
componentMain(pkg, { instantiate, wasip2 })

0 commit comments

Comments
 (0)