Module wit_component::metadata
source · Expand description
Definition for encoding of custom sections within core wasm modules of component-model related data.
When creating a component from a source language the high-level process for
doing this is that code will be generated into the source language by
wit-bindgen
or a similar tool which will be compiled down to core wasm.
The core wasm file is then fed into wit-component
and a component is
created. This means that the componentization process is decoupled from the
binding generation process and intentionally affords for linking together
libraries into the main core wasm module that import different interfaces.
The purpose of this module is to define an intermediate format to reside in
a custom section in the core wasm output. This intermediate format is
carried through the wasm linker through a custom section whose name starts
with component-type
. This custom section is created
per-language-binding-generation and consumed by slurping up all the
sections during the component creation process.
The custom section here contains World
, the interpretation of a “world”
of a component, along with how strings are encoded for all the specified
interfaces. Currently the encoding is:
-
First, a version byte (
CURRENT_VERSION
). This is intended to detect mismatches between different versions of the binding generator andwit-component
which may or may not become a problem over time. -
Next a string encoding byte.
-
Afterwards a “types only” component encoding of a
World
package through theComponentEncoder::types_only
configuration.
Structs
Functions
wasm
binary given as input and return a
BindgenMetadata
which extracts the custom sections describing
component-level types from within the binary itself.component-type*
custom section to be decoded by decode
above.