bytecodealliance / bytecodealliance/wasmtime

How to call guest functions from within bindgen-generated host resource methods

Open
#8,915 8 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 18h
Merged PRs (30d)
126

Description

I have a resource that is implemented on the host via the `bindgen` macro. In some of its methods, it needs to call back into the guest.

When implementing the resource methods for the state struct on the host via the `Host...` trait, I'm given a mutable reference to the state struct (which holds the resource table) and the resource handle (similar to https://docs.rs/wasmtime/latest/wasmtime/component/bindgen_examples/_4_imported_resources/example/imported_resources/logging/trait.HostLogger.html). To call a method in the guest, I need access to the guest resource `Guest...`, and a mutable reference to the store (similar to https://docs.rs/wasmtime/latest/wasmtime/component/bindgen_examples/_6_exported_resources/exports/example/exported_resources/logging/struct.GuestLogger.html).

How do I get access to the store inside a host-side resource method and how could I instantiate the state struct to know about the guest resource?

Thanks for your help!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.