Skip to content

Proposal: Allowing WIT bindgen written in languages they are generating for #640

@Mossaka

Description

@Mossaka

@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:

  1. 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.
  2. wit-bindgen uses fully-resolved WIT packages in wit_parser::Resolved to generate bindings. Roughly speaking, a new language bindgen needs to implement these Rust traits:
    1. wit_bindgen_core::Bindgen - lower and lift signatures from Wasm types to WIT types
    2. wit_bindgen_core::WorldGenerator - generate source code to files for WIT worlds
    3. wit_bindgen_core::InterfaceGenerator - generate source code to files for WIT interfaces

Ideas

  1. Complete rewrite of wit-parser and wit-bindgen in each language. For example, wit-parser-go and wit-bindgen-go for WIT binding Go generator. See an example for wit-parser in Go by @jordan-rash
  2. 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.
  3. @lann suggested to turn language generators to Wasm components by defining generator interfaces as WIT packages.

Metadata

Metadata

Assignees

No one assigned

    Labels

    open questionBig topics that have no clear answer at this time

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions