Wasmtime
component/component.h File Reference
#include <wasm.h>
#include <wasmtime/conf.h>
#include <wasmtime/error.h>

Go to the source code of this file.

Typedefs

typedef struct wasmtime_component_t wasmtime_component_t
 Representation of a component in the component model.
 
typedef struct wasmtime_component_export_index_t wasmtime_component_export_index_t
 A value which represents a known export of a component.
 

Functions

wasmtime_error_twasmtime_component_new (const wasm_engine_t *engine, const uint8_t *buf, size_t len, wasmtime_component_t **component_out)
 Compiles a WebAssembly binary into a wasmtime_component_t. More...
 
wasmtime_error_twasmtime_component_serialize (const wasmtime_component_t *component, wasm_byte_vec_t *ret)
 This function serializes compiled component artifacts as blob data. More...
 
wasmtime_error_twasmtime_component_deserialize (const wasm_engine_t *engine, const uint8_t *buf, size_t len, wasmtime_component_t **component_out)
 Build a component from serialized data. More...
 
wasmtime_error_twasmtime_component_deserialize_file (const wasm_engine_t *engine, const char *path, wasmtime_component_t **component_out)
 Deserialize a component from an on-disk file. More...
 
wasmtime_component_twasmtime_component_clone (const wasmtime_component_t *component)
 Creates a shallow clone of the specified component, increasing the internal reference count.
 
void wasmtime_component_delete (wasmtime_component_t *component)
 Deletes a wasmtime_component_t created by wasmtime_component_new. More...
 
wasmtime_component_export_index_twasmtime_component_get_export_index (const wasmtime_component_t *component, const wasmtime_component_export_index_t *instance_export_index, const char *name, size_t name_len)
 Looks up a specific export of this component by name optionally nested within the instance provided. More...
 
void wasmtime_component_export_index_delete (wasmtime_component_export_index_t *export_index)
 Deletes a wasmtime_component_export_index_t. More...
 

Function Documentation

◆ wasmtime_component_delete()

void wasmtime_component_delete ( wasmtime_component_t component)

Deletes a wasmtime_component_t created by wasmtime_component_new.

Parameters
componentthe component to delete

◆ wasmtime_component_deserialize()

wasmtime_error_t * wasmtime_component_deserialize ( const wasm_engine_t engine,
const uint8_t *  buf,
size_t  len,
wasmtime_component_t **  component_out 
)

Build a component from serialized data.

This function does not take ownership of any of its arguments, but the returned error and component are owned by the caller.

This function is not safe to receive arbitrary user input. See the Rust documentation for more information on what inputs are safe to pass in here (e.g. only that of wasmtime_component_serialize)

◆ wasmtime_component_deserialize_file()

wasmtime_error_t * wasmtime_component_deserialize_file ( const wasm_engine_t engine,
const char *  path,
wasmtime_component_t **  component_out 
)

Deserialize a component from an on-disk file.

This function is the same as wasmtime_component_deserialize except that it reads the data for the serialized component from the path on disk. This can be faster than the alternative which may require copying the data around.

This function does not take ownership of any of its arguments, but the returned error and component are owned by the caller.

This function is not safe to receive arbitrary user input. See the Rust documentation for more information on what inputs are safe to pass in here (e.g. only that of wasmtime_component_serialize)

◆ wasmtime_component_export_index_delete()

void wasmtime_component_export_index_delete ( wasmtime_component_export_index_t export_index)

Deletes a wasmtime_component_export_index_t.

Parameters
export_indexthe export index to delete

◆ wasmtime_component_get_export_index()

wasmtime_component_export_index_t * wasmtime_component_get_export_index ( const wasmtime_component_t component,
const wasmtime_component_export_index_t instance_export_index,
const char *  name,
size_t  name_len 
)

Looks up a specific export of this component by name optionally nested within the instance provided.

Parameters
componentthe component to look up name in
instance_export_indexoptional (i.e. nullable) instance to look up in
namethe name of the export
name_lenlength of name in bytes
Returns
export index if found, else NULL

◆ wasmtime_component_new()

wasmtime_error_t * wasmtime_component_new ( const wasm_engine_t engine,
const uint8_t *  buf,
size_t  len,
wasmtime_component_t **  component_out 
)

Compiles a WebAssembly binary into a wasmtime_component_t.

This function will compile a WebAssembly binary into an owned wasmtime_component_t.

It requires a component binary, such as what is produced by Rust cargo component tooling.

This function does not take ownership of any of its arguments, but the returned error and component are owned by the caller.

Parameters
enginethe wasm_engine_t that will create the component
bufthe address of the buffer containing the WebAssembly binary
lenthe length of the buffer containing the WebAssembly binary
component_outon success, contains the address of the created component
Returns
NULL on success, else a wasmtime_error_t describing the error

◆ wasmtime_component_serialize()

wasmtime_error_t * wasmtime_component_serialize ( const wasmtime_component_t component,
wasm_byte_vec_t ret 
)

This function serializes compiled component artifacts as blob data.

Parameters
componentthe component
retif the conversion is successful, this byte vector is filled in with the serialized compiled component.
Returns
a non-null error if parsing fails, or returns NULL. If parsing fails then ret isn't touched.

This function does not take ownership of component, and the caller is expected to deallocate the returned wasmtime_error_t and wasm_byte_vec_t.