bytecodealliance / jco

JavaScript toolchain for working with WebAssembly Components
https://bytecodealliance.github.io/jco/
Apache License 2.0
640 stars 63 forks source link

DRAFT: Adding JSPI and Asyncify #518

Open calvinrp opened 3 weeks ago

calvinrp commented 3 weeks ago

Adds options to jco transpile and jco types:

.addOption(new Option('--async-mode [mode]', 'use async imports and exports').choices(['sync', 'jspi', 'asyncify']).preset('sync'))
.option('--default-async-imports', 'default async component imports from WASI interfaces')
.option('--default-async-exports', 'default async component exports from WASI interfaces')
.option('--async-imports <imports...>', 'async component imports (examples: "wasi:io/poll@0.2.0#poll", "wasi:io/poll#[method]pollable.block")')
.option('--async-exports <exports...>', 'async component exports (examples: "wasi:cli/run@#run", "handle")')

Which treats the specified imports and exports as async using either JSPI or Asyncify.

JSPI is behind a feature flag in Chrome, Deno and NodeJS. Can run via:

DENO_V8_FLAGS="--experimental-wasm-jspi" deno
node --experimental-wasm-jspi

From my understanding, Asyncify does not support reentrancy (so it throws an error) but JSPI does.