sagemathinc / cowasm

CoWasm: Collaborative WebAssembly for Servers and Browsers. Built using Zig. Supports Python with extension modules, including numpy.
https://cowasm.org
BSD 3-Clause "New" or "Revised" License
482 stars 23 forks source link

wasi-js getImportObject #68

Open walmartwarlord opened 10 months ago

walmartwarlord commented 10 months ago

Hi! Thanks for this. I'm looking at the wasi-js example, and wondering where can get the value of wasmOpts here?

import { WASI } from "wasi-js";
import fs from "fs";
import nodeBindings from "wasi-js/dist/bindings/node";

const wasi = new WASI({
  args: [],
  env: {},
  bindings: {...nodeBindings, fs},
});

const source = await readFile(pathToWasm);
const typedArray = new Uint8Array(source);
const result = await WebAssembly.instantiate(typedArray, wasmOpts); // where can we wasmOpts
wasi.start(result.instance);

I tried looking at the WASI implementation of node 20 and tried to do it as well - but it is undefined:

const result = await WebAssembly.instantiate(typedArray, wasi.getImportObject()); // getImportObject is undefined

Any tips? Thank you!

williamstein commented 10 months ago

I don't have time at the moment to look into this, but I would start by looking first at

https://github.com/sagemathinc/cowasm/blob/28cf78ae7d96373a49f026ffd02813dcf0c9dd17/core/wasi-js/src/runtime.ts#L77