There are cases where it would be helpful to have access to the component type associated with bindgen!ed code, like allowing component type checking without separate WIT bookkeeping or the creation of an engine/component/linker/store to test instantiation.
Guest wit-bindgen embeds this information in the component-type custom section for use by wasm-component-ld; I'd like to do something similar for wasmtime bindgen, roughly:
let encoded = wit_component::metadata::encode(
resolve,
world_id,
wit_component::StringEncoding::UTF8,
None,
)?;
uwriteln!(self.src, "pub const COMPONENT_TYPE: &[u8] = &{encoded:?};");
which would allow the host to reconstruct the component type:
let wit_component::metadata::Bindgen {
resolve,
world,
..
} = wit_component::metadata::decode(generated::bindings::COMPONENT_TYPE)?;
If there is a compelling reason for it this could be gated by a bindgen opt but the const will disappear if it doesn't get used so I'm not sure if that is necessary.
There are cases where it would be helpful to have access to the component type associated with
bindgen!ed code, like allowing component type checking without separate WIT bookkeeping or the creation of an engine/component/linker/store to test instantiation.Guest
wit-bindgenembeds this information in thecomponent-typecustom section for use bywasm-component-ld; I'd like to do something similar for wasmtime bindgen, roughly:which would allow the host to reconstruct the component type:
If there is a compelling reason for it this could be gated by a bindgen opt but the
constwill disappear if it doesn't get used so I'm not sure if that is necessary.