Stream: git-wasmtime

Topic: wasmtime / issue #5626 Unable to have multiple host imports


view this post on Zulip Wasmtime GitHub notifications bot (Jan 24 2023 at 16:57):

RinLovesYou opened issue #5626:

Hi there! I'm just starting to explore using wasm to create a plugin framework.

I was starting to play with host import functions, and noticed i was unable to have more than one.

Host

let log_str = Func::wrap(&mut store, exports::log_str);
let instance = Instance::new(&mut store, &module, &[ log_str.into() ])?;

Wasm

extern "C" {
    fn log_str(ptr: i32, len: i32);
}

Output

[17:50:14.104] Hello from wasm!

If i now add a second function:

Host

let get_assembly_count = Func::wrap(&mut store, exports::get_assembly_count);
let log_str = Func::wrap(&mut store, exports::log_str);

let instance = Instance::new(&mut store, &module, &[get_assembly_count.into(), log_str.into() ])?;

Wasm

extern "C" {
    fn get_assembly_count() -> i32;
    fn log_str(ptr: i32, len: i32);
}

Output

[17:56:14.791] [ERROR] Failed to load mod: incompatible import type for `env::log_str`

I've looked through the documentation/examples/issues and i've never seen this mentioned, so i'm a bit lost

view this post on Zulip Wasmtime GitHub notifications bot (Jan 24 2023 at 17:03):

RinLovesYou commented on issue #5626:

Even more perplexing behavior, if i switch

let instance = Instance::new(&mut store, &module, &[get_assembly_count.into(), log_str.into() ])?;

to

let instance = Instance::new(&mut store, &module, &[ log_str.into(), get_assembly_count.into() ])?;

it now works...

[18:02:18.073] Hello from wasm!
[18:02:18.073] There are 97 assemblies


Last updated: Dec 23 2024 at 12:05 UTC