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.
Currently the encoding of this custom section 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.
-
Next, three strings are encoded. These are the names of the root package, document, and world that the bindings were generated for. These strings are used as lookups into the next field.
-
Finally the Wasm-encoded representation of a
Resolve
is included in its binary form. This is the encoding of a package into wasm, and the bound world for the bindings is specified from the prior strings.
Structs
Bindgen
.