Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allocate error: Instance(NotFoundFunc("allocate")) when using a wasmedge_quickjs module with rust sdk host #136

Open
jsoneaday opened this issue Mar 28, 2024 · 2 comments

Comments

@jsoneaday
Copy link

I get this error when calling a function called init from a rust host. I've tried including the js file both in the wasm file and the in the host project but continue to get this error. My entire project can be found at https://github.com/jsoneaday/ao in the servers/cu_rs folder

This is the wasm module

use wasmedge_quickjs::*;
use wasmedge_bindgen_macro::*;

#[wasmedge_bindgen]
pub fn init() {
    let mut ctx = Context::new();

    let code = r#"
        import("main.js")
            .then(res => {
                return res.init();
            })
    "#;

    let p = ctx.eval_global_str(code);
    ctx.promise_loop_poll();
    if let JsValue::Promise(ref p) = p {
        let v = p.get_result();
        println!("v: {:?}", v);
    }
}

// this is the host function calling the init function in the module

fn do_js_work() -> Result<(), Box<dyn std::error::Error>> {
    let common_options = CommonConfigOptions::default()
        .bulk_memory_operations(true)
        .multi_value(true)
        .mutable_globals(true)
        .non_trap_conversions(true)
        .reference_types(true)
        .sign_extension_operators(true)
        .simd(true);
    let host_options = HostRegistrationConfigOptions::default()
        .wasi(true);
    let config = ConfigBuilder::new(common_options)
        .with_host_registration_config(host_options)
        .build()
        .unwrap();

    let vm = VmBuilder::new().with_config(config).build()?;
    let module = Module::from_file(None, "wasm/js_lib.wasm").unwrap();
    let vm = vm.register_module(None, module).unwrap();
    let mut bg = Bindgen::new(vm);

    match bg.run_wasm("init", params!()) {
        Ok(res) => println!("init result {:?}", res),
        Err(e) => println!("error {:?}", e)
    };

    Ok(())
}
@jsoneaday
Copy link
Author

I just tried switching to this module code, but same error.

#[wasmedge_bindgen]
pub fn init() {
    let mut ctx = Context::new();

    let code = r#"
        let module = import("main.js")
        module
    "#;

    let p = ctx.eval_global_str(code);
    ctx.promise_loop_poll();
    if let JsValue::Promise(ref p) = p {
        let module = p.get_result();
        println!("v: {:?}", module);

        if let JsValue::Object(obj_mod) = module {
            let func = obj_mod.get("init");
            println!("init func: {:?}", func);

            if let JsValue::Function(func) = func {
                let result = func.call(&mut []);
                println!("result {:?}", result);
            }
        }
    }
}

The js module is a large bundled file, but the main function that I'm trying to call looks like this

import Arweave from "arweave";
export { default as Arweave } from "arweave";
export { default as WarpArBundles } from "warp-arbundles";

export function init() {
  return Arweave.init({});
}

@L-jasmine
Copy link
Collaborator

Your use case seems to be running WebAssembly in a browser and then using JavaScript within the WebAssembly. This scenario is not supported by us; our goal is to run JavaScript within WASI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants