-
Notifications
You must be signed in to change notification settings - Fork 250
Description
@ydnar and I originally posted this little proposal on this zulipchat post and I am raising an issue here for a bigger exposure.
Challenges
Currently, all the WIT binding generators are written in Rust to emit bindings in different languages. Given that the parsed WIT AST (in particular, Resolve struct) is represented in Rust data structures, this makes sense. However, this poses some challenges to language experts to develop and maintain WIT binding generators because they will have to know Rust well. This motivates the idea of developing bindgen in their own languages consuming resolved WIT packages. The question is how and in what format can we supply resolved WIT packages to bindgen written in different languages.
Details
wit-bindgen is a tool to generate guest language bindings for .wit files for languages that compile to Wasm components. It leverages wit-parser crate from wasm-tools to parse and interpret WIT packages. There is a clear difference between wit-bindgen and wit-parser:
- wit-parser parses the input WIT files, resolves all the imports, including foreign imports, and represent all the worlds and interfaces in a struct called
wit_parser::Resolved. - wit-bindgen uses fully-resolved WIT packages in
wit_parser::Resolvedto generate bindings. Roughly speaking, a new language bindgen needs to implement these Rust traits:wit_bindgen_core::Bindgen- lower and lift signatures from Wasm types to WIT typeswit_bindgen_core::WorldGenerator- generate source code to files for WIT worldswit_bindgen_core::InterfaceGenerator- generate source code to files for WIT interfaces
Ideas
- Complete rewrite of wit-parser and wit-bindgen in each language. For example,
wit-parser-goandwit-bindgen-gofor WIT binding Go generator. See an example for wit-parser in Go by @jordan-rash - Reuse wit-parser as much as possible by serializing its exported modules (mainly
wit_parser::Resolve) and deserialized to each binding generators in their respective languages for consuming. @alexcrichton has some insights into this. - @lann suggested to turn language generators to Wasm components by defining generator interfaces as WIT packages.