I'm not sure why I am getting errors about ComponentNamedList
.
For reference I am trying to get a TypedFunc for this: https://github.com/i509VCB/aerugo/blob/ab79099ba124da6f57a021d1f7357e00f45ffce6/wm.wit#L12-L16
And I have this so far:
struct WmFuncs {
new_toplevel: TypedFunc<Resource<Toplevel>, ()>,
closed_toplevel: TypedFunc<ToplevelId, ()>,
update_toplevel: TypedFunc<(ToplevelId, ToplevelUpdates), ()>,
ack_toplevel: TypedFunc<(ToplevelId, u32), ()>,
committed_toplevel: TypedFunc<(ToplevelId, Option<Resource<Snapshot>>), ()>,
key: TypedFunc<(u32, u32, Option<String>, KeyStatus), KeyFilter>,
key_modifiers: TypedFunc<KeyModifiers, ()>,
new_output: TypedFunc<Resource<Output>, ()>,
disconnect_output: TypedFunc<OutputId, ()>,
}
My suspicion is that I'm forgetting something here?
The compiler error:
error[E0277]: the trait bound `wasmtime::component::Resource<host::aerugo::wm::types::Toplevel>: ComponentNamedList` is not satisfied
--> crates/wm-runtime/src/lib.rs:300:36
|
300 | new_toplevel: instance.get_typed_func(store, "new-toplevel")?,
| ^^^^^^^^^^^^^^ the trait `ComponentNamedList` is not implemented for `wasmtime::component::Resource<host::aerugo::wm::types::Toplevel>`
|
are you using wasmtime::component::bindgen?
change new_toplevel: TypedFunc<Resource<Toplevel>, ()>,
to new_toplevel: TypedFunc<(Resource<Toplevel>,), ()>,
I think
or yeah use bindgen!
if you can
Pat Hickey said:
are you using wasmtime::component::bindgen?
yes
Although I get nothing from bindgen to load those typed funcs from my scan of the expanded macro?
actually alex got it, its the 1-tuple thing
is the output of bindgen!
what's failing to compile?
Alex Crichton said:
is the output of
bindgen!
what's failing to compile?
No
Given the mention of bindgen!
I'm wondering if I skipped over something that already has the types of the TypedFunc I am trying to load
ah ok, if you're looking for features in the generated code please feel free to file issues for those
bindgen will generate a WmTypes::Wm
trait that you will need to impl
to provide each of those funcs.
it depends on the structure of the WIT and also what you're doing specifically, but if you find that bindgen!
doesn't work for you then we should soup up bindgen!
on our end to be more featureful most likely
Alex Crichton said:
it depends on the structure of the WIT and also what you're doing specifically, but if you find that
bindgen!
doesn't work for you then we should soup upbindgen!
on our end to be more featureful most likely
Yeah ideally bindgen! would generate a type containing all the TypedFuncs for the resource returned from wasm like I have done
Pat Hickey said:
bindgen will generate a
WmTypes::Wm
trait that you will need toimpl
to provide each of those funcs.
And there is a Wm
type but that does not contain anything from the resource.
pub struct WmTypes {
get_info:wasmtime::component::Func,create_wm:wasmtime::component::Func,
}
It's just the two functions from the interface that that contains
why do you want it to work that way? can you instead define a struct MyWm
and impl wm_types::Wm for MyWm
?
oh I believe these are exports instead of imports
imports get traits but exports are stored as funcs
@i509VCB unfortunately given lifetimes it's not possible to store those as TypedFunc
, but within each call_*
method you'll see that the first thing it does is cast to a typed func.
there will be a wm_types::Host
trait that requires an impl of any functions in wm-types.
but we could add accessors such as bindings.func_*
which returns &TypedFunc<...>
@Pat Hickey that's only if wm-types
was an import though? Given the Func
I think these are exports?
wm_types::Host should just contain fn create_wm(...) ...
oh! of course.
sorry, i read these wrong.
There is a HostWm
trait that's generated but it's entirely empty lol
which part of this are you trying to implement on the host, and which part in a wasm component
The wasm component implements the wm
resource and I call it from the host.
ok, got it.
so there should be somestruct AerugoWm
defined by bindgen!.
is there a reason the call_*
methods won't work for you? e.g. how come you want access to the TypedFunc
?
and that will have a fn aerugo_wm_wm_types(&mut store)
which should then be a struct WmTypes
and WmTypes
should have a fn create_wm
Alex Crichton said:
is there a reason the
call_*
methods won't work for you? e.g. how come you want access to theTypedFunc
?
No call
methods exist for the functions on the resource wm
: This is what the expanded macro generates: https://gist.github.com/i509VCB/13ebc08130e7b190c9b699d7102a7184
Unless this was added recently and I need to update wasmtime again
Are you using main
or are you using 13.0.0?
13.0.0
ah ok try using main
, and I think you should see a new accessor for the resource methods
support for exported resources didn't make it into 13.0.0
Okay I'll give a look at main, this is still bleeding edge so it's not unexpected
Yeah main generates the stuff. Thank you!
i509VCB has marked this topic as resolved.
Last updated: Dec 23 2024 at 13:07 UTC