Stream: general

Topic: Combining multiple crates wit-bindgen


view this post on Zulip Mendy Berger (Apr 15 2024 at 02:09):

When having multiple wit_bindgen::generate! macro calls, (e.g. in two dependencies) they each create their own types.
So if they both use a resource type, the resource type from each generate! is different, making it impossible to reuse code between them.
I.e. you can't take a wasi:http/request-options from one, and pass it to the other, even though they're really the same underlying thing.
Is there any way to work around this? Perhaps I'm missing something?

view this post on Zulip Pat Hickey (Apr 15 2024 at 02:11):

yep, this is what with clauses are for: https://github.com/bytecodealliance/wasmtime/blob/main/crates/wasi-http/src/lib.rs#L60

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

view this post on Zulip Mendy Berger (Apr 15 2024 at 02:13):

Does wit-bindgen support the same thing? I'm having this issue on the guest side, not the runtime's side.

view this post on Zulip Pat Hickey (Apr 15 2024 at 02:13):

ah, sorry. i think that feature may be missing in guest wit-bindgen

view this post on Zulip Pat Hickey (Apr 15 2024 at 02:14):

i recall this comes up pretty frequently

view this post on Zulip Pat Hickey (Apr 15 2024 at 02:14):

maybe someone did add it in the last month, ive been offline

view this post on Zulip Mendy Berger (Apr 15 2024 at 02:20):

To make it a bit more concrete, this is relevant for wasi-webgpu where we expect most rust users to use the wgpu crate instead of relying on wasi-webgpu directly.
So I'm working on a wasi-backend for wgpu, but we also expect the users to be able to connect the gpu device to a canvas/window. And now the wgpu generated types are incompatible with the types generated by the crate itself.

view this post on Zulip Mendy Berger (Apr 15 2024 at 03:04):

:face_palm: If only I'd read the docs...
It specifically addresses this case...
https://docs.rs/wit-bindgen/0.24.0/wit_bindgen/macro.generate.html#options-to-generate


Last updated: Oct 23 2024 at 20:03 UTC