Skip to content

Commit ec5bb2b

Browse files
committed
chore: upgrade to Ruby 3.4, fix escaping source code
1 parent f2c700e commit ec5bb2b

File tree

10 files changed

+83
-41
lines changed

10 files changed

+83
-41
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
toolchain: 1.74.0
1818
- uses: ruby/setup-ruby@v1
1919
with:
20-
ruby-version: 3.3
20+
ruby-version: 3.4
2121
bundler-cache: true
2222
- name: Setup yarn
2323
run: npm install -g yarn
@@ -43,14 +43,14 @@ jobs:
4343
- name: Build ruby.wasm
4444
if: steps.cache-ruby-wasm-module.outputs.cache-hit != 'true'
4545
run: |
46-
bundle exec rbwasm build -o src/ruby.wasm --ruby-version 3.3
46+
bin/rbwasm build -o src/ruby.wasm --ruby-version 3.4
4747
- name: Build web app
4848
run: |
4949
yarn install
5050
yarn build
5151
- name: Push to Github Pages
5252
if: github.ref == 'refs/heads/master' || github.event_name == 'workflow_dispatch'
53-
uses: actions/upload-pages-artifact@v1
53+
uses: actions/upload-pages-artifact@v3
5454
with:
5555
path: './dist'
5656

@@ -72,4 +72,4 @@ jobs:
7272
runs-on: ubuntu-latest
7373
steps:
7474
- name: Deploy to GitHub Pages
75-
uses: actions/deploy-pages@v1
75+
uses: actions/deploy-pages@v4

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
source "https://rubygems.org"
44

5-
gem "js", "~> 2.5" unless ENV["JS"] == "false"
6-
gem "ruby_wasm", "~> 2.5"
5+
gem "js", "~> 2.7.1" unless ENV["JS"] == "false"
6+
gem "ruby_wasm", "~> 2.7.1"
77
gem "ruby-next", "~> 1.1.0"

Gemfile.lock

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ GEM
33
specs:
44
ast (2.4.2)
55
diff-lcs (1.5.1)
6-
js (2.5.0)
6+
js (2.7.1)
77
paco (0.2.3)
88
parser (3.3.7.0)
99
ast (~> 2.4.1)
@@ -19,7 +19,10 @@ GEM
1919
ruby-next-core (1.1.0)
2020
ruby-next-parser (3.4.0.2)
2121
parser (>= 3.0.3.1)
22-
ruby_wasm (2.5.0)
22+
ruby_wasm (2.7.1)
23+
ruby_wasm (2.7.1-aarch64-linux)
24+
ruby_wasm (2.7.1-arm64-darwin)
25+
ruby_wasm (2.7.1-x86_64-linux)
2326
unparser (0.6.15)
2427
diff-lcs (~> 1.3)
2528
parser (>= 3.3.0)
@@ -31,9 +34,9 @@ PLATFORMS
3134
x86_64-linux
3235

3336
DEPENDENCIES
34-
js (~> 2.5)
37+
js (~> 2.7.1)
3538
ruby-next (~> 1.1.0)
36-
ruby_wasm (~> 2.5)
39+
ruby_wasm (~> 2.7.1)
3740

3841
BUNDLED WITH
3942
2.5.3

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Play with Ruby Next right in the browser (powered by [ruby.wasm](https://github.
2323
Use the following command:
2424

2525
```sh
26-
bundle exec rbwasm build -o src/ruby.wasm --ruby-version 3.3
26+
bin/rbwasm build -o src/ruby.wasm --ruby-version 3.4
2727
```
2828

2929
This would build a JS-compatible WASM module. To build JS-free WASM module, use the `JS=false` env var.

bin/rbwasm

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env ruby
2+
3+
require "bundler/setup"
4+
5+
require "ruby_wasm"
6+
require "ruby_wasm/cli"
7+
8+
# Patch ruby.wasm CLI to use the latest patch versions of Ruby
9+
RubyWasm::CLI.singleton_class.prepend(Module.new do
10+
def build_source_aliases(root)
11+
super.tap do |sources|
12+
sources["3.3"][:url] = "https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.8.tar.gz"
13+
sources["3.4"][:url] = "https://cache.ruby-lang.org/pub/ruby/3.4/ruby-3.4.3.tar.gz"
14+
end
15+
end
16+
end)
17+
18+
RubyWasm::CLI.new(stdout: $stdout, stderr: $stderr).run(ARGV)

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
"dev": "npm-run-all --parallel watch:*"
1111
},
1212
"dependencies": {
13-
"@bjorn3/browser_wasi_shim": "^0.2.19",
14-
"@ruby/wasm-wasi": "^2.4.1",
13+
"@ruby/wasm-wasi": "^2.7.1",
1514
"@shoelace-style/shoelace": "^2.13.0",
1615
"monaco-editor": "^0.45.0"
1716
},

src/app.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,13 @@ export default class App {
246246
this.vm.eval(this.configEditor.getValue());
247247

248248
const result = this.vm
249-
.eval("RubyNext.transform(%q(" + code + "), **" + rubyOptions + ")")
249+
.eval(`
250+
code = <<~'RUBY'
251+
${code}
252+
RUBY
253+
254+
RubyNext.transform(code, **${rubyOptions})
255+
`)
250256
.toString();
251257

252258
return result;

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ await Promise.all([
3131
import("./vm.js")
3232
.then(async ({ default: initVM }) => {
3333
const vm = await initVM();
34+
window.$vm = vm;
3435
loaderDone("ruby");
3536
return vm;
3637
})

src/vm.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { RubyVM } from "@ruby/wasm-wasi";
2-
import { File, WASI, OpenFile, ConsoleStdout } from "@bjorn3/browser_wasi_shim";
2+
import {
3+
File,
4+
WASI,
5+
OpenFile,
6+
ConsoleStdout,
7+
} from "@bjorn3/browser_wasi_shim";
38

49
import ruby from "./ruby.wasm";
510

@@ -26,15 +31,10 @@ export default async function initVM() {
2631
ConsoleStdout.lineBuffered(setStdout),
2732
ConsoleStdout.lineBuffered(setStderr),
2833
];
29-
const wasi = new WASI([], [], fds, { debug: false });
30-
const vm = new RubyVM();
31-
const imports = {
32-
wasi_snapshot_preview1: wasi.wasiImport,
33-
};
34-
vm.addToImports(imports);
35-
36-
const instance = await WebAssembly.instantiate(module, imports);
37-
await vm.setInstance(instance);
34+
const wasi = new WASI([], ["RUBYOPT=-EUTF-8 -W0", "NO_COLOR=1"], fds, { debug: false });
35+
const { vm, instance } = await RubyVM.instantiateModule({
36+
module, wasip1: wasi
37+
});
3838

3939
wasi.initialize(instance);
4040
vm.initialize();

yarn.lock

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
resolved "https://registry.yarnpkg.com/@alloc/quick-lru/-/quick-lru-5.2.0.tgz#7bf68b20c0a350f936915fcae06f58e32007ce30"
88
integrity sha512-UrcABB+4bUrFABwbluTIBErXwvbsU/V7TZWfmbgJfbkwiBuziS9gxdODUyuiecfdGQ85jglMW6juS3+z5TsKLw==
99

10-
"@bjorn3/browser_wasi_shim@^0.2.19":
11-
version "0.2.19"
12-
resolved "https://registry.yarnpkg.com/@bjorn3/browser_wasi_shim/-/browser_wasi_shim-0.2.19.tgz#24b6dc7417677b641da6f0a24729b6d7766e0c5b"
13-
integrity sha512-Zu5KVxRp7MBwwdOtXSmu14NUwPASNE6zK/BSwWKf0Fsc4g5NOqPYto5C0Nc6EixDb0AEXCoLFDMKP9RN7n2yPQ==
10+
"@bjorn3/browser_wasi_shim@^0.3.0":
11+
version "0.3.0"
12+
resolved "https://registry.yarnpkg.com/@bjorn3/browser_wasi_shim/-/browser_wasi_shim-0.3.0.tgz#8aa310eed2298bab435bd1f73ab100fbc3f018da"
13+
integrity sha512-FlRBYttPRLcWORzBe6g8nmYTafBkOEFeOqMYM4tAHJzFsQy4+xJA94z85a9BCs8S+Uzfh9LrkpII7DXr2iUVFg==
1414

1515
"@ctrl/tinycolor@^4.0.2":
1616
version "4.0.3"
@@ -234,12 +234,13 @@
234234
resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33"
235235
integrity sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==
236236

237-
"@ruby/wasm-wasi@^2.4.1":
238-
version "2.4.1"
239-
resolved "https://registry.yarnpkg.com/@ruby/wasm-wasi/-/wasm-wasi-2.4.1.tgz#86a0fe1dd342ecb0c37e99eaadde3920d27bd31e"
240-
integrity sha512-MNosDpMKw9N0HaTSXpyZEzPMGTRzpA9maxnUYH1dBB9p/zbLNp4Q+fxGUCxAdFHCnb0Bf7K7RqzhHrjf6crBUg==
237+
"@ruby/wasm-wasi@^2.7.1":
238+
version "2.7.1"
239+
resolved "https://registry.yarnpkg.com/@ruby/wasm-wasi/-/wasm-wasi-2.7.1.tgz#72816add3dd665e6c6bcb39b69567f76b4c28ccb"
240+
integrity sha512-2f4NqiJuFoeYiXNr60PH3TbH5c+z/xP2Hq36Av2yahp05AaLDyJxWZwr9EGmfoFsmVTmeDdEW2KjPTfpue6xeg==
241241
dependencies:
242-
tslib "^2.6.1"
242+
"@bjorn3/browser_wasi_shim" "^0.3.0"
243+
tslib "^2.8.1"
243244

244245
"@shoelace-style/animations@^1.1.0":
245246
version "1.1.0"
@@ -1444,8 +1445,16 @@ spdx-license-ids@^3.0.0:
14441445
resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-3.0.16.tgz#a14f64e0954f6e25cc6587bd4f392522db0d998f"
14451446
integrity sha512-eWN+LnM3GR6gPu35WxNgbGl8rmY1AEmoMDvL/QD6zYmPWgywxWqJWNdLGT+ke8dKNWrcYgYjPpG5gbTfghP8rw==
14461447

1447-
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0:
1448-
name string-width-cjs
1448+
"string-width-cjs@npm:string-width@^4.2.0":
1449+
version "4.2.3"
1450+
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
1451+
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
1452+
dependencies:
1453+
emoji-regex "^8.0.0"
1454+
is-fullwidth-code-point "^3.0.0"
1455+
strip-ansi "^6.0.1"
1456+
1457+
string-width@^4.1.0:
14491458
version "4.2.3"
14501459
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
14511460
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -1499,8 +1508,14 @@ string.prototype.trimstart@^1.0.7:
14991508
define-properties "^1.2.0"
15001509
es-abstract "^1.22.1"
15011510

1502-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
1503-
name strip-ansi-cjs
1511+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
1512+
version "6.0.1"
1513+
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
1514+
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
1515+
dependencies:
1516+
ansi-regex "^5.0.1"
1517+
1518+
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
15041519
version "6.0.1"
15051520
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
15061521
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -1598,10 +1613,10 @@ ts-interface-checker@^0.1.9:
15981613
resolved "https://registry.yarnpkg.com/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz#784fd3d679722bc103b1b4b8030bcddb5db2a699"
15991614
integrity sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==
16001615

1601-
tslib@^2.6.1:
1602-
version "2.6.2"
1603-
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae"
1604-
integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==
1616+
tslib@^2.8.1:
1617+
version "2.8.1"
1618+
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.1.tgz#612efe4ed235d567e8aba5f2a5fab70280ade83f"
1619+
integrity sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==
16051620

16061621
typed-array-buffer@^1.0.0:
16071622
version "1.0.0"

0 commit comments

Comments
 (0)