Wasmtime
component/linker.h File Reference

Go to the source code of this file.

Typedefs

typedef struct wasmtime_component_linker_t wasmtime_component_linker_t
 A type used to instantiate a wasmtime_component_t.
 
typedef struct wasmtime_component_linker_instance_t wasmtime_component_linker_instance_t
 Structure representing an "instance" being defined within a linker.
 
typedef wasmtime_error_t *(* wasmtime_component_func_callback_t) (void *, wasmtime_context_t *, const wasmtime_component_val_t *, size_t, wasmtime_component_val_t *, size_t)
 Type of the callback used in wasmtime_component_linker_instance_add_func.
 

Functions

wasmtime_component_linker_twasmtime_component_linker_new (const wasm_engine_t *engine)
 Creates a new wasmtime_component_linker_t for the specified engine. More...
 
wasmtime_component_linker_instance_twasmtime_component_linker_root (wasmtime_component_linker_t *linker)
 Returns the "root instance" of this linker, used to define names into the root namespace. More...
 
wasmtime_error_twasmtime_component_linker_instantiate (const wasmtime_component_linker_t *linker, wasmtime_context_t *context, const wasmtime_component_t *component, wasmtime_component_instance_t *instance_out)
 Instantiates a component instance in a given wasmtime_context_t. More...
 
void wasmtime_component_linker_delete (wasmtime_component_linker_t *linker)
 Deletes a wasmtime_component_linker_t created by wasmtime_component_linker_new. More...
 
wasmtime_error_twasmtime_component_linker_instance_add_instance (wasmtime_component_linker_instance_t *linker_instance, const char *name, size_t name_len, wasmtime_component_linker_instance_t **linker_instance_out)
 Defines a nested instance within this instance. More...
 
wasmtime_error_twasmtime_component_linker_instance_add_module (wasmtime_component_linker_instance_t *linker_instance, const char *name, size_t name_len, const wasmtime_module_t *module)
 Defines a wasmtime_module_t within this instance. More...
 
wasmtime_error_twasmtime_component_linker_instance_add_func (wasmtime_component_linker_instance_t *linker_instance, const char *name, size_t name_len, wasmtime_component_func_callback_t callback, void *data, void(*finalizer)())
 Define a function within this instance. More...
 
void wasmtime_component_linker_instance_delete (wasmtime_component_linker_instance_t *linker_instance)
 Deletes a wasmtime_component_linker_instance_t. More...
 

Function Documentation

◆ wasmtime_component_linker_delete()

void wasmtime_component_linker_delete ( wasmtime_component_linker_t linker)

Deletes a wasmtime_component_linker_t created by wasmtime_component_linker_new.

Parameters
linkerthe wasmtime_component_linker_t to delete

◆ wasmtime_component_linker_instance_add_func()

wasmtime_error_t * wasmtime_component_linker_instance_add_func ( wasmtime_component_linker_instance_t linker_instance,
const char *  name,
size_t  name_len,
wasmtime_component_func_callback_t  callback,
void *  data,
void(*)()  finalizer 
)

Define a function within this instance.

Parameters
linker_instancethe instance to define the function in
namethe module name
name_lenlength of name in bytes
callbackthe callback when this function gets called
datahost-specific data passed to the callback invocation, can be NULL
finalizeroptional finalizer for data, can be NULL
Returns
on success NULL, otherwise an error

◆ wasmtime_component_linker_instance_add_instance()

wasmtime_error_t * wasmtime_component_linker_instance_add_instance ( wasmtime_component_linker_instance_t linker_instance,
const char *  name,
size_t  name_len,
wasmtime_component_linker_instance_t **  linker_instance_out 
)

Defines a nested instance within this instance.

This can be used to describe arbitrarily nested levels of instances within a linker to satisfy nested instance exports of components.

Warning
This acquires exclusive access to the linker_instance. The linker_instance MUST not be accessed by anything until the returned wasmtime_component_linker_instance_t in linker_instance_out is destroyed by wasmtime_component_linker_instance_delete.
Parameters
linker_instancethe linker instance from which the new one is created
namenew instance name
name_lenlength of name in bytes
linker_instance_outon success, the new wasmtime_component_linker_instance_t
Returns
on success NULL, otherwise an error

◆ wasmtime_component_linker_instance_add_module()

wasmtime_error_t * wasmtime_component_linker_instance_add_module ( wasmtime_component_linker_instance_t linker_instance,
const char *  name,
size_t  name_len,
const wasmtime_module_t module 
)

Defines a wasmtime_module_t within this instance.

This can be used to provide a core wasm wasmtime_module_t as an import to a component. The wasmtime_module_t provided is saved within the linker for the specified name in this instance.

Parameters
linker_instancethe instance to define the module in
namethe module name
name_lenlength of name in bytes
modulethe module
Returns
on success NULL, otherwise an error

◆ wasmtime_component_linker_instance_delete()

void wasmtime_component_linker_instance_delete ( wasmtime_component_linker_instance_t linker_instance)

Deletes a wasmtime_component_linker_instance_t.

Parameters
linker_instancethe wasmtime_component_linker_instance_t to delete

◆ wasmtime_component_linker_instantiate()

wasmtime_error_t * wasmtime_component_linker_instantiate ( const wasmtime_component_linker_t linker,
wasmtime_context_t context,
const wasmtime_component_t component,
wasmtime_component_instance_t instance_out 
)

Instantiates a component instance in a given wasmtime_context_t.

Parameters
linkera wasmtime_component_linker_t that will help provide host functions
contextthe wasmtime_context_t in which the instance should be created
componentthe wasmtime_component_t to instantiate
instance_outon success, the instantiated wasmtime_component_instance_t
Returns
wasmtime_error_t* on success NULL is returned, otherwise an error is returned which describes why the build failed.

◆ wasmtime_component_linker_new()

wasmtime_component_linker_t * wasmtime_component_linker_new ( const wasm_engine_t engine)

Creates a new wasmtime_component_linker_t for the specified engine.

Parameters
enginethe compilation environment and configuration
Returns
a pointer to the newly created wasmtime_component_linker_t

◆ wasmtime_component_linker_root()

wasmtime_component_linker_instance_t * wasmtime_component_linker_root ( wasmtime_component_linker_t linker)

Returns the "root instance" of this linker, used to define names into the root namespace.

Warning
This acquires exclusive access to the linker. The linker MUST not be accessed by anything until the returned wasmtime_component_linker_instance_t in linker_instance_out is destroyed by wasmtime_component_linker_instance_delete.