wasm_component_layer icon indicating copy to clipboard operation
wasm_component_layer copied to clipboard

`wit_bindgen!` macro

Open ten3roberts opened this issue 1 year ago • 13 comments

To consume wit files, we would need a bindgen procedural macro which will consume the interface, and generate all necessary inferface types and functions, as well as the relevant traits to implement for the host exports.

To do this, we could leverage the existing wasmtime wit_bindgen macro and slightly modify it to fit this crate and its exports.

For supporting custom structs and enums we would need a ComponentLift ComponentLower trait that will declare how to convert this rust side struct into a the ValueType::Record type, or directly into the guest memory.

The conversion into Value would allow utilizing existing marshalling code, but comes at the cost of the conversion and boxing of the values due to the recursive nature of the enum. If used in a hotloop, this would likely become expensive, though far from as expensive at generating recursive JsObjects with stringed key-value pairs which JCO employs.

Using a direct memory write would be more code, but it would allow an flow-inversion where the existing Value would instead implement that Lift and Lower traits. As such, this method will still ensure a consistent and predictable model without shortcuts or circumventions of existing logic.

Let me know what you think and if you have any particular requests or considerations 😊

ten3roberts avatar Dec 12 '23 10:12 ten3roberts