Stream: wit-bindgen

Topic: ✔ import has the wrong type


view this post on Zulip DougAnderson444 | PeerPiper.io (Jun 08 2023 at 18:57):

I am trying to get a basic example up and running here: https://github.com/DougAnderson444/wit-wasm

It compiles fine, and runs fine until I try to use a host function thunk in the guest Component fn think at runtime I get this import error:

Error: import `mypackage:smoke/imports` has the wrong type

Caused by:
    0: instance export `thunk` has the wrong type
    1: expected func found nothing

Wit file:

package mypackage:smoke

interface imports {
  thunk: func()
}

world smoke {
  import imports

  export think: func()
}

Component:

wit_bindgen::generate!("smoke" in "wit");
struct Exports;

impl Smoke for Exports {
    fn think() {
        mypackage::smoke::imports::thunk();
    }
}

export_smoke!(Exports);

Thunk:

#[async_trait::async_trait]
impl mypackage::smoke::imports::Host for MyImports {
    async fn thunk(&mut self) -> Result<()> {
        self.hit = true;
        println!("in the host");
        Ok(())
    }
}

I am using this as a guide, but maybe it's overkill? https://github.com/bytecodealliance/wasmtime/blob/afd9aced3b91ae4eab7c72e0ed4cc241ef93dc89/crates/test-programs/tests/reactor.rs

I feel like it's close! Just missing something that I'm not seeing?

Contribute to DougAnderson444/wit-wasm development by creating an account on GitHub.
A fast and secure runtime for WebAssembly. Contribute to bytecodealliance/wasmtime development by creating an account on GitHub.

view this post on Zulip Brian (Jun 08 2023 at 20:40):

@DougAnderson444 looks like you are missing adding Smoke to the linker; i.e. Smoke::add_to_linker(&mut linker, |x| x)?; here https://github.com/DougAnderson444/wit-wasm/blob/master/examples/smoke.rs#LL80C1-L80C1

Contribute to DougAnderson444/wit-wasm development by creating an account on GitHub.

view this post on Zulip DougAnderson444 | PeerPiper.io (Jun 08 2023 at 21:25):

THANK YOU @Brian You just made my day!

view this post on Zulip Notification Bot (Jun 08 2023 at 21:25):

DougAnderson444 has marked this topic as resolved.


Last updated: Dec 23 2024 at 12:05 UTC