Skip to content

createWasmBin

Implementation signature for createWasmBin (overloads above are public).

Returns a closure-captured BinFunction that lazy-loads WASM bytes + glue factory on first call, memoizes them for subsequent calls, and resolves dynamic preloadPaths per invocation (callers can compute the preload list from proc.env or other context).

The guest-side branch asserts the glue module’s default export is callable — a non-function default means the .mjs file was packaged wrong and the program would crash inside Emscripten’s internals otherwise.

createWasmBin(metaUrl, wasmFile, glueFile, opts?): BinFunction

Defined in: packages/runtime/src/wasm/create-wasm-bin.ts:112

Build a BinFunction that runs an Emscripten WASM program.

Overloads:

  • Host-side — pass import.meta.url and paths relative to it. Resolved via node:fs / dynamic import on Node, and fetch / dynamic import in the browser.
  • Guest-side (registry) — pass an AssetResolver, which reads the bundled assets shipped alongside the package.

The bin caches the compiled WASM bytes and the glue factory on first call, so subsequent invocations skip asset loading.

string

string

string

CreateWasmBinOptions

BinFunction

// Host-side
export const vimBin = createWasmBin(
import.meta.url, 'vim.wasm', 'vim.mjs',
{ ttyMode: 'raw', preloadPaths: ['/etc/vimrc'] },
)
// Guest-side (registry catalog entry)
export default (resolver: AssetResolver) => ({
bins: { vim: createWasmBin(resolver, 'vim.wasm', 'vim.mjs', { ttyMode: 'raw' }) },
})

createWasmBin(resolver, wasmFile, glueFile, opts?): BinFunction

Defined in: packages/runtime/src/wasm/create-wasm-bin.ts:119

Guest-side overload — resolve WASM + glue via an AssetResolver.

AssetResolver

string

string

CreateWasmBinOptions

BinFunction