3#ifndef WASMTIME_COMPONENT_LINKER_HH
4#define WASMTIME_COMPONENT_LINKER_HH
8#ifdef WASMTIME_FEATURE_COMPONENT_MODEL
29 WASMTIME_OWN_WRAPPER(
LinkerInstance, wasmtime_component_linker_instance);
36 ptr.get(), name.data(), name.size(), module.capi());
37 if (error !=
nullptr) {
40 return std::monostate();
53 ptr.get(), name.data(), name.size(), &ret);
54 if (error !=
nullptr) {
71 F *func =
reinterpret_cast<F *
>(env);
75 (*func)(
Store::Context(store), *FuncType::from_capi(&ty), args_span,
79 return result.
err().capi_release();
84 template <
typename F>
static void raw_finalize(
void *env) {
85 std::unique_ptr<F> ptr(
reinterpret_cast<F *
>(env));
97 ptr.get(), name.data(), name.length(),
98 raw_callback<std::remove_reference_t<F>>,
99 std::make_unique<std::remove_reference_t<F>>(std::forward<F>(f))
101 raw_finalize<std::remove_reference_t<F>>);
103 if (error !=
nullptr) {
107 return std::monostate();
111 template <
typename F>
115 F *func =
reinterpret_cast<F *
>(env);
118 return result.
err().capi_release();
126 template <
typename F,
127 std::enable_if_t<std::is_invocable_r_v<Result<std::monostate>, F,
128 Store::Context, uint32_t>,
133 ptr.get(), name.data(), name.length(), ty.capi(),
134 raw_resource_destructor_callback<std::remove_reference_t<F>>,
135 std::make_unique<std::remove_reference_t<F>>(std::forward<F>(f))
137 raw_finalize<std::remove_reference_t<F>>);
139 if (error !=
nullptr) {
143 return std::monostate();
151 WASMTIME_OWN_WRAPPER(
Linker, wasmtime_component_linker);
175 define_unknown_imports_as_traps(
const Component &component) {
177 ptr.get(), component.capi());
180 return std::monostate();
186 void allow_shadowing(
bool allow) {
194 ptr.get(), cx.
capi(), component.capi(), &ret);
195 if (error !=
nullptr) {
201#ifdef WASMTIME_FEATURE_WASI
212 if (error !=
nullptr) {
215 return std::monostate();
Global compilation state in Wasmtime.
Definition: engine.hh:22
Errors coming from Wasmtime.
Definition: error.hh:26
Representation of a compiled WebAssembly module.
Definition: module.hh:28
Fallible result type used for Wasmtime.
Definition: error.hh:70
E && err()
Returns the error, if present, aborts if this is not an error.
Definition: error.hh:84
Span class used when c++20 is not available.
Definition: span.hh:47
An interior pointer into a Store.
Definition: store.hh:66
const wasmtime_context_t * capi() const
Returns the underlying C API pointer.
Definition: store.hh:160
Representation of a compiled WebAssembly component.
Definition: component/component.hh:39
Type information about a component function.
Definition: component/types/func.hh:21
Class representing an instantiated WebAssembly component.
Definition: component/instance.hh:22
Helper class for linking modules together with name-based resolution.
Definition: component/linker.hh:28
Result< std::monostate > add_resource(std::string_view name, const ResourceType &ty, F &&f)
Defines a new resource in this linker with the provided destructor.
Definition: component/linker.hh:130
Result< std::monostate > add_func(std::string_view name, F &&f)
Defines a function within this linker instance.
Definition: component/linker.hh:95
Class used to instantiate a Component into an instance.
Definition: component/linker.hh:150
Definition: component/types/val.hh:151
Class representing an instantiated WebAssembly component.
Definition: component/val.hh:471
static const Val * from_capi(const Raw *capi)
Definition: component/val.hh:476
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(*finalizer)(void *))
Define a function within this instance.
struct wasmtime_component_linker_instance_t wasmtime_component_linker_instance_t
Structure representing an "instance" being defined within a linker.
Definition: component/linker.h:25
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.
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.
WASM_API_EXTERN wasmtime_error_t * wasmtime_component_linker_add_wasip2(wasmtime_component_linker_t *linker)
Add all WASI interfaces into the linker provided.
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(*finalizer)(void *))
Defines a new resource type within this 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.
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.
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.
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.
WASM_API_EXTERN wasmtime_error_t * wasmtime_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.
struct wasmtime_component_func_type_t wasmtime_component_func_type_t
Opaque type representing a component function type.
Definition: component/types/func.h:18
Build-time defines for how the C API was built.
Representation of a instance in Wasmtime.
Definition: component/instance.h:24
Represents possible runtime values which a component function can either consume or produce.
Definition: component/val.h:376
An interior pointer into a wasmtime_store_t which is used as "context" for many functions.
Errors generated by Wasmtime.