diff --git a/.gitignore b/.gitignore index 9ad8354b2b..dc85eaa010 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ compile_commands.json html build_manifest.json +ci_matrix.json vendor/bundle /pkg diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b33b65eecd..d4a4ab5727 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -24,9 +24,9 @@ $ rake build:download_prebuilt $ rake build:head-wasm32-unknown-wasip1-full # Build npm package -$ rake npm:ruby-head-wasm-wasi +$ rake npm:ruby-head-wasm-wasip2:build # Test npm package -$ rake npm:ruby-head-wasm-wasi:check +$ rake npm:ruby-head-wasm-wasip2:check ``` If you need to re-build Ruby, please clean `./rubies` directory, and run `rake npm:ruby-head-wasm-wasi` again. diff --git a/Rakefile b/Rakefile index 05ff059282..4a0784e8bb 100644 --- a/Rakefile +++ b/Rakefile @@ -30,6 +30,12 @@ NPM_PACKAGES = [ ruby_version: "head", gemfile: "packages/npm-packages/ruby-head-wasm-wasi/Gemfile", target: "wasm32-unknown-wasip1", + }, + { + name: "ruby-head-wasm-wasip2", + ruby_version: "head", + gemfile: "packages/npm-packages/ruby-head-wasm-wasip2/Gemfile", + target: "wasm32-unknown-wasip2", enable_component_model: true, }, { diff --git a/builders/wasm32-unknown-wasip1 b/builders/wasm32-unknown-wasip1 new file mode 120000 index 0000000000..27021ac96c --- /dev/null +++ b/builders/wasm32-unknown-wasip1 @@ -0,0 +1 @@ +wasm32-unknown-wasip2 \ No newline at end of file diff --git a/builders/wasm32-unknown-wasip1/Dockerfile b/builders/wasm32-unknown-wasip2/Dockerfile similarity index 100% rename from builders/wasm32-unknown-wasip1/Dockerfile rename to builders/wasm32-unknown-wasip2/Dockerfile diff --git a/builders/wasm32-unknown-wasip1/entrypoint.sh b/builders/wasm32-unknown-wasip2/entrypoint.sh similarity index 100% rename from builders/wasm32-unknown-wasip1/entrypoint.sh rename to builders/wasm32-unknown-wasip2/entrypoint.sh diff --git a/package-lock.json b/package-lock.json index 0c747e19d4..70f3856069 100644 --- a/package-lock.json +++ b/package-lock.json @@ -75,8 +75,7 @@ "node_modules/@bytecodealliance/preview2-shim": { "version": "0.16.5", "resolved": "https://registry.npmjs.org/@bytecodealliance/preview2-shim/-/preview2-shim-0.16.5.tgz", - "integrity": "sha512-1YThPyZ/gWZBgmJ3nEsnBXLxgSV3VOW3vLfyxe/RTKk9fWkTKaUouuZHWBvP0aFN7Hnat733rUeSYAUjEUNONQ==", - "dev": true + "integrity": "sha512-1YThPyZ/gWZBgmJ3nEsnBXLxgSV3VOW3vLfyxe/RTKk9fWkTKaUouuZHWBvP0aFN7Hnat733rUeSYAUjEUNONQ==" }, "node_modules/@esbuild/linux-x64": { "version": "0.21.5", @@ -455,6 +454,10 @@ "resolved": "packages/npm-packages/ruby-head-wasm-wasi", "link": true }, + "node_modules/@ruby/head-wasm-wasip2": { + "resolved": "packages/npm-packages/ruby-head-wasm-wasip2", + "link": true + }, "node_modules/@ruby/wasm-emscripten": { "resolved": "packages/npm-packages/ruby-wasm-emscripten", "link": true @@ -2208,6 +2211,14 @@ "@ruby/wasm-wasi": "^2.0.0" } }, + "packages/npm-packages/ruby-head-wasm-wasip2": { + "version": "2.6.2", + "license": "MIT", + "dependencies": { + "@bytecodealliance/preview2-shim": "^0.16.5", + "@ruby/wasm-wasi": "^2.0.0" + } + }, "packages/npm-packages/ruby-wasm-emscripten": { "name": "@ruby/wasm-emscripten", "version": "0.1.0", diff --git a/packages/npm-packages/ruby-head-wasm-wasi/README.md b/packages/npm-packages/ruby-head-wasm-wasi/README.md index d25df14174..61d7c23167 100644 --- a/packages/npm-packages/ruby-head-wasm-wasi/README.md +++ b/packages/npm-packages/ruby-head-wasm-wasi/README.md @@ -2,6 +2,6 @@ [![npm version](https://badge.fury.io/js/@ruby%2Fhead-wasm-wasi.svg)](https://www.npmjs.com/package/@ruby/head-wasm-wasi) -This package provides WebAssembly binaries of CRuby built from the latest `HEAD` source code targeting WASI-compatible environments. +This package provides WebAssembly binaries of CRuby built from the latest `HEAD` 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. diff --git a/packages/npm-packages/ruby-head-wasm-wasi/package.json b/packages/npm-packages/ruby-head-wasm-wasi/package.json index 6df914973c..b0f5ff508a 100644 --- a/packages/npm-packages/ruby-head-wasm-wasi/package.json +++ b/packages/npm-packages/ruby-head-wasm-wasi/package.json @@ -29,7 +29,7 @@ "README.md" ], "scripts": { - "test": "RUBY_NPM_PACKAGE_ROOT=../ruby-head-wasm-wasi npm -C ../ruby-wasm-wasi run test:run:all", + "test": "RUBY_NPM_PACKAGE_ROOT=../ruby-head-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-head-wasm-wasi", diff --git a/packages/npm-packages/ruby-head-wasm-wasip2/.gitignore b/packages/npm-packages/ruby-head-wasm-wasip2/.gitignore new file mode 100644 index 0000000000..cbb80a5cd4 --- /dev/null +++ b/packages/npm-packages/ruby-head-wasm-wasip2/.gitignore @@ -0,0 +1,4 @@ +*.tgz +/tmp +/bundle +/vendor diff --git a/packages/npm-packages/ruby-head-wasm-wasip2/Gemfile b/packages/npm-packages/ruby-head-wasm-wasip2/Gemfile new file mode 100644 index 0000000000..35a14732c1 --- /dev/null +++ b/packages/npm-packages/ruby-head-wasm-wasip2/Gemfile @@ -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" diff --git a/packages/npm-packages/ruby-head-wasm-wasip2/Gemfile.lock b/packages/npm-packages/ruby-head-wasm-wasip2/Gemfile.lock new file mode 100644 index 0000000000..f5bf0d9958 --- /dev/null +++ b/packages/npm-packages/ruby-head-wasm-wasip2/Gemfile.lock @@ -0,0 +1,25 @@ +PATH + remote: ../../.. + specs: + ruby_wasm (2.6.2.dev) + +GEM + remote: https://rubygems.org/ + specs: + js (2.6.2.dev) + power_assert (2.0.3) + test-unit (3.6.2) + power_assert + +PLATFORMS + ruby + x86_64-linux + +DEPENDENCIES + js (= 2.6.2.dev) + power_assert + ruby_wasm! + test-unit + +BUNDLED WITH + 2.6.0.dev diff --git a/packages/npm-packages/ruby-head-wasm-wasip2/README.md b/packages/npm-packages/ruby-head-wasm-wasip2/README.md new file mode 100644 index 0000000000..e5b87edac6 --- /dev/null +++ b/packages/npm-packages/ruby-head-wasm-wasip2/README.md @@ -0,0 +1,7 @@ +# @ruby/head-wasm-wasip2 + +[![npm version](https://badge.fury.io/js/@ruby%2Fhead-wasm-wasip2.svg)](https://www.npmjs.com/package/@ruby/head-wasm-wasip2) + +This package provides WebAssembly binaries of CRuby built from the latest `HEAD` source code targeting environments compatible with WASI Preview2. + +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. diff --git a/packages/npm-packages/ruby-head-wasm-wasip2/package.json b/packages/npm-packages/ruby-head-wasm-wasip2/package.json new file mode 100644 index 0000000000..2f759975af --- /dev/null +++ b/packages/npm-packages/ruby-head-wasm-wasip2/package.json @@ -0,0 +1,58 @@ +{ + "name": "@ruby/head-wasm-wasip2", + "version": "2.6.2", + "description": "Ruby head built on WASI Preview 2", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "private": true, + "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": { + "__comment": "FIXME: Enable test:e2e after https://github.com/bytecodealliance/jco/pull/499 is merged", + "test": "npm run run-script -- test:unit && npm run run-script -- test:vitest -- --run", + "run-script": "RUBY_NPM_PACKAGE_ROOT=../ruby-head-wasm-wasip2 ENABLE_COMPONENT_TESTS=1 npm -C ../ruby-wasm-wasi run", + "build:deps": "cd ../ruby-wasm-wasi && npm run build", + "build:static:files": "../ruby-wasm-wasi/tools/pack-static-files.sh ./dist", + "build:static": "npm run build:static:files", + "build:rollup": "rollup -c rollup.config.mjs", + "build": "npm run build:deps && npm run build:static && npm run build:rollup" + }, + "repository": "https://github.com/ruby/ruby.wasm", + "homepage": "https://github.com/ruby/ruby.wasm/tree/main/packages/npm-packages/ruby-head-wasm-wasi", + "publishConfig": { + "access": "public" + }, + "keywords": [ + "wasm", + "webassembly", + "wasi", + "ruby" + ], + "license": "MIT", + "dependencies": { + "@ruby/wasm-wasi": "^2.0.0", + "@bytecodealliance/preview2-shim": "^0.16.5" + } +} diff --git a/packages/npm-packages/ruby-head-wasm-wasip2/rollup.config.mjs b/packages/npm-packages/ruby-head-wasm-wasip2/rollup.config.mjs new file mode 100644 index 0000000000..302c2c6720 --- /dev/null +++ b/packages/npm-packages/ruby-head-wasm-wasip2/rollup.config.mjs @@ -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() + ], + }, +]; diff --git a/packages/npm-packages/ruby-head-wasm-wasip2/src/browser.script.js b/packages/npm-packages/ruby-head-wasm-wasip2/src/browser.script.js new file mode 100644 index 0000000000..aff548be89 --- /dev/null +++ b/packages/npm-packages/ruby-head-wasm-wasip2/src/browser.script.js @@ -0,0 +1,6 @@ +import { instantiate } from "../dist/component/ruby.component" +import { componentMain } from "@ruby/wasm-wasi/dist/browser.script" +import * as wasip2 from "@bytecodealliance/preview2-shim" +import * as pkg from "../package.json" + +componentMain(pkg, { instantiate, wasip2 }) diff --git a/packages/npm-packages/ruby-wasm-wasi/.gitignore b/packages/npm-packages/ruby-wasm-wasi/.gitignore index f647196f26..62246d4097 100644 --- a/packages/npm-packages/ruby-wasm-wasi/.gitignore +++ b/packages/npm-packages/ruby-wasm-wasi/.gitignore @@ -1,4 +1,5 @@ !.gitkeep /coverage /playwright-report +/test-results *.tgz diff --git a/packages/npm-packages/ruby-wasm-wasi/package.json b/packages/npm-packages/ruby-wasm-wasi/package.json index fdd86b4413..a6c09454b0 100644 --- a/packages/npm-packages/ruby-wasm-wasi/package.json +++ b/packages/npm-packages/ruby-wasm-wasi/package.json @@ -39,7 +39,6 @@ ], "license": "MIT", "scripts": { - "test:run:all": "npm run test:run && ENABLE_COMPONENT_TESTS=1 npm run test:run", "test:run": "npm run test:unit && npm run test:vitest -- --run && npm run test:e2e", "test:vitest": "vitest ./test/", "test:unit": "./tools/run-test-unit.mjs", diff --git a/packages/npm-packages/ruby-wasm-wasi/src/browser.script.ts b/packages/npm-packages/ruby-wasm-wasi/src/browser.script.ts index 65c1b8af90..2c5b2bd32a 100644 --- a/packages/npm-packages/ruby-wasm-wasi/src/browser.script.ts +++ b/packages/npm-packages/ruby-wasm-wasi/src/browser.script.ts @@ -1,5 +1,9 @@ import { DefaultRubyVM } from "./browser.js"; +import { RubyInitComponentOptions, RubyComponentInstantiator, RubyVM } from "./vm.js"; +/** + * The main entry point of `