Wasmex. Components. Component
(wasmex v0.18.1)
Copy Markdown
A WebAssembly Component that can be instantiated.
Components are compiled WebAssembly modules that follow the Component Model specification. They define imports and exports using WIT (WebAssembly Interface Types).
Summary
Functions
Compiles a new WebAssembly component from bytes.
Serializes a compiled WebAssembly component into an artifact for
unsafe_deserialize/2 or unsafe_deserialize_file/2.
Loads a component artifact produced by serialize/1 or
Wasmex.Engine.precompile_component/2.
Loads a precompiled component by memory-mapping its artifact file.
Types
Functions
Compiles a new WebAssembly component from bytes.
Parameters
store- The store to compile the component forbytes- Raw WebAssembly component bytes
Returns
{:ok, component}on success{:error, reason}on failure
Serializes a compiled WebAssembly component into an artifact for
unsafe_deserialize/2 or unsafe_deserialize_file/2.
@spec unsafe_deserialize(binary(), Wasmex.Engine.t()) :: {:ok, t()} | {:error, binary()}
Loads a component artifact produced by serialize/1 or
Wasmex.Engine.precompile_component/2.
The artifact must match the Wasmtime version, target, and compatible configuration of the supplied Engine. Create the component Store with this same Engine before instantiating the component.
Safety
Only pass unmodified artifacts from a trusted Wasmtime compiler. The artifact contains native executable code. Wasmtime's compatibility checks cannot establish that the code is safe to run. Keep this API away from untrusted input.
@spec unsafe_deserialize_file(String.t(), Wasmex.Engine.t()) :: {:ok, t()} | {:error, binary()}
Loads a precompiled component by memory-mapping its artifact file.
The file must contain the output of serialize/1 or
Wasmex.Engine.precompile_component/2 and match the supplied Engine's
Wasmtime version, target, and configuration. Use the same Engine to create
the component Store before instantiating the component.
Safety
Only load unmodified artifacts from a trusted Wasmtime compiler. They contain native executable code, and the mapped file must stay unchanged for the lifetime of the component and all instances created from it. Use a versioned artifact path when deploying updated files.