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 and wit-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

The result of decoding binding information from a WebAssembly binary.
Module-level metadata that’s specific to one core WebAssembly module. This is extracted with a Bindgen.

Functions

This function will parse the wasm binary given as input and return a Bindgen which extracts the custom sections describing component-level types from within the binary itself.
Creates a component-type* custom section to be decoded by decode above.