Skip to content

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

@jsoneaday

Description

@jsoneaday

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(())
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions