wit-bindgen
wit-bindgen copied to clipboard
[Profiles] Support for linking
Would this include as a goal that WIT type definitions shared by multiple imports/exports generate shared code/types instead of separate redundant ones?
Yes, that's the goal here. We need to be able to use types from one interface in another interface. For example, given:
produce.wit:
record info {
field: u32
}
produce-info: func() -> info
consume.wit:
use { info } from produce
consume-info: func(i: info)
and main.rs
wit_bindgen_rust::import!("produce.wit");
wit_bindgen_rust::import!("consume.wit");
fn main() -> std::io::Result<()> {
let info = produce::produce_info();
consume::consume_info(info);
Ok(())
}
This currently gets an error: "expected struct consume::Info
, found struct produce::Info
".
I think the solution here is profiles. Once implemented, we'll be able to define a profile that pulls in multiple wit files, and then wit-bindgen can generate a linked bindings module for them.
I like that framing, I think profiles will be a good way to connect this all together and present it as singular input to the code generator.
I've arbitrarily chosen this as the blessed issue for "use
does not work as one might expect", especially with resources, so more information about this issue can be learned from the litany of referenced issues as well.
I'm also closing the related #191.
In the example above, why not define
messaging.wit :
record Info { field: u32 }
so that it generates Messaging.Info
and have both producer and consumer import the common struct ? It is a shared struct - why not define it in an interface library of shared types?
I believe that this is now done as of https://github.com/bytecodealliance/wit-bindgen/pull/457, so I'm going to close this.