Stream: wit-bindgen

Topic: Dependencies using Rust guest imports


view this post on Zulip Alex Helfet (Jan 27 2023 at 15:59):

I have a Rust guest lib compiling to wasm32-unknown-unknown and have written a wit world with its dependencies. I export the world in my lib with export_foo!(Foo) at the top level using bindings generated by wit-bindgen guest rust.

One of the interfaces that I import needs to be used by a third-party dependency fairly deep in my dependency tree, so I'd prefer not to patch every crate along the chain to pass that dependency through function calls. I want to patch just the dependency that needs the import, but looking at the generated bindings some of the items seem like they will conflict at link time if I reference the bindings module both in the top-level in my lib and in this deep dependency. In particular this item:

#[link_section = "component-type:foo"]
pub static __WIT_BINDGEN_COMPONENT_TYPE = _;

So what I'd like is a way to generate just the imports of the bindings, which looks like it's fine to reference in multiple places in my dependency tree. It looks like this isn't possible in wit-bindgen at the moment, but should it be? Or is another workaround possible?

view this post on Zulip Alex Helfet (Jan 28 2023 at 19:15):

I ended up generating a different world for the third-party dependency and patching it to use an imported component without exporting anything. Here's the code if anyone is interested: https://github.com/fluffysquirrels/pass-rs .

A password manager like `pass` implemented in Rust - GitHub - fluffysquirrels/pass-rs: A password manager like `pass` implemented in Rust

Last updated: Nov 22 2024 at 16:03 UTC