Skip to content

Commit

Permalink
Apply larger fiber stack size workaround only to Ruby 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
kateinoigakukun committed Nov 13, 2023
1 parent b4590e4 commit 57ccc24
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 9 additions & 1 deletion packages/npm-packages/ruby-3_2-wasm-wasi/src/browser.script.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { main } from "@ruby/wasm-wasi/dist/browser.script"
import * as pkg from "../package.json"

main(pkg)
main(pkg, {
env: {
// WORKAROUND(katei): setjmp consumes a LOT of stack in Ruby 3.2,
// so we extend default Fiber stack size as well as main stack
// size allocated by wasm-ld's --stack-size. 8MB is enough for
// most cases. See https://github.com/ruby/ruby.wasm/issues/273
"RUBY_FIBER_MACHINE_STACK_SIZE": "8388608"
}
})
7 changes: 5 additions & 2 deletions packages/npm-packages/ruby-wasm-wasi/src/browser.script.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { DefaultRubyVM } from "./browser";

export const main = async (pkg: { name: string; version: string }) => {
export const main = async (
pkg: { name: string; version: string },
options?: Parameters<typeof DefaultRubyVM>[1],
) => {
const response = fetch(
`https://cdn.jsdelivr.net/npm/${pkg.name}@${pkg.version}/dist/ruby+stdlib.wasm`,
);
const module = await compileWebAssemblyModule(response);
const { vm } = await DefaultRubyVM(module);
const { vm } = await DefaultRubyVM(module, options);

vm.printVersion();

Expand Down

0 comments on commit 57ccc24

Please sign in to comment.