I have a wit
file which I use in several different components... when I generate the bindings, even through the same tooling (e.g. cargo-component or wit-bindgen), I get conflicts that the type in component_a::Foo
is different than component_b::Foo
- even though they're both importing the same wit
and using the same world
is this a known issue? any tips for working around this other than writing macros to convert the types?
One option that I've seen some projects do is factor out the bindings into a separate crate. That is, put a wit bindgen generate!()
in src/lib.rs in its own crate that your other crates can depend on.
that would definitely work... but I'm building the components with cargo component build
and it wants to know the world
, generate its own bindings, etc.. with this approach, I guess I'd need to bypass cargo component
and do things more manually? will check into it, thanks!
in almost every single component model I've ever seen over the past 30 years, data types are always their own "component"/"package"/"shareable thing". I'll be STUNNED if the wasm component model can pull this off or any language chain.
but, as you might imagine, I'd looooooooooove* to be surprised here.
:-)
fwiw, I went down a few rabbit holes... the most promising for a general solution was probably something like:
it worked, but kinda ugly...
turns out for my use-case I don't need the macros - just have a shared lib with the bindings, and use variant
s to handle more usecases where I would have maybe wanted different world
s before.
I do think tooling to handle the problem of "I have a .wit
that's used in a bunch of places, but bindings are incompatible" would be nice - especially where it's multiple worlds generated as distinct bindings but from the same exact interface imports
Everyone wants it, of course. My guess is that if you have your data types in a separate wit, witbindgen should be able to export both guest and host parts properly.
Last updated: Jan 24 2025 at 00:11 UTC