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_func_type_t *, wasmtime_component_val_t *, size_t, wasmtime_component_val_t *, size_t)
 Type of the callback used in wasmtime_component_linker_instance_add_func.
 
typedef wasmtime_error_t *(* wasmtime_component_resource_destructor_t) (void *, wasmtime_context_t *, uint32_t)
 

Functions

WASM_API_EXTERN wasmtime_component_linker_twasmtime_component_linker_new (const wasm_engine_t *engine)
 Creates a new wasmtime_component_linker_t for the specified engine. More...
 
WASM_API_EXTERN void wasmtime_component_linker_allow_shadowing (wasmtime_component_linker_t *linker, bool allow)
 Configures whether this linker allows later definitions to shadow previous definitions. More...
 
WASM_API_EXTERN 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...
 
WASM_API_EXTERN 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...
 
WASM_API_EXTERN wasmtime_error_twasmtime_component_linker_define_unknown_imports_as_traps (wasmtime_component_linker_t *linker, const wasmtime_component_t *component)
 Defines all unknown imports of component as trapping functions.
 
WASM_API_EXTERN void wasmtime_component_linker_delete (wasmtime_component_linker_t *linker)
 Deletes a wasmtime_component_linker_t created by wasmtime_component_linker_new. More...
 
WASM_API_EXTERN 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...
 
WASM_API_EXTERN 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...
 
WASM_API_EXTERN 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)(void *))
 Define a function within this instance. More...
 
WASM_API_EXTERN wasmtime_error_twasmtime_component_linker_add_wasip2 (wasmtime_component_linker_t *linker)
 Add all WASI interfaces into the linker provided.
 
WASM_API_EXTERN wasmtime_error_twasmtime_component_linker_instance_add_resource (wasmtime_component_linker_instance_t *linker_instance, const char *name, size_t name_len, const wasmtime_component_resource_type_t *resource, wasmtime_component_resource_destructor_t destructor, void *data, void(*finalizer)(void *))
 Defines a new resource type within this instance. More...
 
WASM_API_EXTERN void wasmtime_component_linker_instance_delete (wasmtime_component_linker_instance_t *linker_instance)
 Deletes a wasmtime_component_linker_instance_t. More...
 

Typedef Documentation

◆ wasmtime_component_resource_destructor_t

typedef wasmtime_error_t *(* wasmtime_component_resource_destructor_t) (void *, wasmtime_context_t *, uint32_t)

Function Documentation

◆ wasmtime_component_linker_allow_shadowing()

WASM_API_EXTERN void wasmtime_component_linker_allow_shadowing ( wasmtime_component_linker_t linker,
bool  allow 
)

Configures whether this linker allows later definitions to shadow previous definitions.

By default this setting is false.

◆ wasmtime_component_linker_delete()

WASM_API_EXTERN 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()

WASM_API_EXTERN 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(*)(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()

WASM_API_EXTERN 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()

WASM_API_EXTERN 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_add_resource()

WASM_API_EXTERN wasmtime_error_t * wasmtime_component_linker_instance_add_resource ( wasmtime_component_linker_instance_t linker_instance,
const char *  name,
size_t  name_len,
const wasmtime_component_resource_type_t resource,
wasmtime_component_resource_destructor_t  destructor,
void *  data,
void(*)(void *)  finalizer 
)

Defines a new resource type within this instance.

This can be used to define a new resource type that the guest will be able to import. Here the resource is a type, often a host-defined type, which can be used to distinguish and definie different types of resources. A destruction callback is also specified via destructor which has private data data along with an optional finalizer for the data too.

Returns
on success NULL, otherwise an error

◆ wasmtime_component_linker_instance_delete()

WASM_API_EXTERN 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()

WASM_API_EXTERN 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()

WASM_API_EXTERN 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()

WASM_API_EXTERN 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.