How can I consume a (rust) `.wasm` lib in wasmedge_quickjs?

19 Views Asked by At

I'd like to make an isomorphic wasm library that can be consumed both in the browser and wasmedge-quickjs.

To do this, I have a simple demo lib:

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn add(left: usize, right: usize) -> usize {
    left + right
}

For the browser, this is pretty straight forward: I run wasm-pack build --target web to generate my output and consume as such:

import init, { add } from "/rs_lib.js";

init().then(() => console.log(add(1, 2));

This works just fine.

Where I'm struggling is for wasmedge. Unfortunately it doesn't implement the WebAssembly global which you'd use in Node, and it has no way of directly consuming the .wasm as you might see in a bundler. How am I meant to be consuming this?

// ReferenceError: could not load module filename 'rs-lib/pkg-bundler/rs_lib_bg.wasm'
import * as tmp from '../rs-lib/pkg-node/rs_lib.js';
// ReferenceError: 'WebAssembly' is not defined
//    at <anonymous> (rs-lib/pkg-node/rs_lib.js:20)
import * as tmp from '../rs-lib/pkg-node/rs_lib.js';
0

There are 0 best solutions below