Stream: wasmtime

Topic: Trouble using bindgen! to generate import trait for resource


view this post on Zulip Chris Hamons (Dec 26 2024 at 11:40):

Apologies if this is not the correct place to ask for help, please redirect as needed.

I am playing around with using wasmtime and the component model to do a form of hot reloading for gamedev. I was able to get something working with returning simple records, but I wanted to extend it to use a resource to describe the screen.

You can see the full WIT here but in short:

interface host-api {
  resource game-screen  {  }
}

interface game-api {
  resource game-instance {
    constructor();
    run-frame: func(mouse: mouse-info, key: keyboard-info, screen: borrow<game-screen>);
  }
}

world hotreload-example {
  import host-api;
  export game-api;
}

The problem I'm running into is that despite import host-api, I am not getting a generated Guest trait for host-api (nor anything in that namespace at all)?

I thought declaring an interface as import would require hosted types for those resources, and that is handled via the guest trait.

Can someone help me figure out what I'm missing?

An example project which uses web assembly to power hotreload of a trivial game - chamons/game-hotreload-example

view this post on Zulip Chris Hamons (Dec 26 2024 at 11:41):

The relevant code is here

An example project which uses web assembly to power hotreload of a trivial game - GitHub - chamons/game-hotreload-example at component

view this post on Zulip Alex Crichton (Dec 26 2024 at 16:41):

I'm not at a computer so I can't dive in too deep but in the meantime you might find https://docs.rs/wasmtime/latest/wasmtime/component/bindgen_examples/index.html useful

view this post on Zulip Chris Hamons (Dec 26 2024 at 18:03):

Yeah I saw those samples, I don’t understand why my wit isn’t generating the host trait for my screen resource

view this post on Zulip Chris Hamons (Dec 26 2024 at 22:49):

Alright, I think maybe I figured out what I was missing.

This is the path to most of the types: exports::example::host::game_api
This is the path to the host: example::host::host_api::Host

I didn't check the other module when I was looking at the generated code.

I'm going to check the module paths more closely and see if I can get it working.


Last updated: Jan 24 2025 at 00:11 UTC