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);
37 ptr.get(), name.data(), name.size(), module.capi());
38 if (error !=
nullptr) {
41 return std::monostate();
54 ptr.get(), name.data(), name.size(), &ret);
55 if (error !=
nullptr) {
72 F *func =
reinterpret_cast<F *
>(env);
76 (*func)(
Store::Context(store), *FuncType::from_capi(&ty), args_span,
80 return result.
err().capi_release();
85 template <
typename F>
static void raw_finalize(
void *env) {
86 std::unique_ptr<F> ptr(
reinterpret_cast<F *
>(env));
98 ptr.get(), name.data(), name.length(),
99 raw_callback<std::remove_reference_t<F>>,
100 std::make_unique<std::remove_reference_t<F>>(std::forward<F>(f))
102 raw_finalize<std::remove_reference_t<F>>);
104 if (error !=
nullptr) {
108 return std::monostate();
112 template <
typename F>
116 F *func =
reinterpret_cast<F *
>(env);
119 return result.
err().capi_release();
127 template <
typename F,
128 std::enable_if_t<std::is_invocable_r_v<Result<std::monostate>, F,
129 Store::Context, uint32_t>,
134 ptr.get(), name.data(), name.length(), ty.capi(),
135 raw_resource_destructor_callback<std::remove_reference_t<F>>,
136 std::make_unique<std::remove_reference_t<F>>(std::forward<F>(f))
138 raw_finalize<std::remove_reference_t<F>>);
140 if (error !=
nullptr) {
144 return std::monostate();
152 WASMTIME_OWN_WRAPPER(
Linker, wasmtime_component_linker);
176 define_unknown_imports_as_traps(
const Component &component) {
178 ptr.get(), component.capi());
181 return std::monostate();
187 void allow_shadowing(
bool allow) {
195 ptr.get(), cx.
capi(), component.capi(), &ret);
196 if (error !=
nullptr) {
202#ifdef WASMTIME_FEATURE_WASI
213 if (error !=
nullptr) {
216 return std::monostate();
220#ifdef WASMTIME_FEATURE_WASI_HTTP
230 if (error !=
nullptr) {
233 return std::monostate();
237#ifdef WASMTIME_FEATURE_COMPONENT_MODEL_ASYNC
238#ifdef WASMTIME_FEATURE_WASI
249 if (error !=
nullptr) {
252 return std::monostate();
256#ifdef WASMTIME_FEATURE_WASI_HTTP
267 if (error !=
nullptr) {
270 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_class.hh:65
const wasmtime_context_t * capi() const
Returns the underlying C API pointer.
Definition: _store_class.hh:183
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:131
Result< std::monostate > add_func(std::string_view name, F &&f)
Defines a function within this linker instance.
Definition: component/linker.hh:96
Class used to instantiate a Component into an instance.
Definition: component/linker.hh:151
Definition: component/types/val.hh:151
Class representing an instantiated WebAssembly component.
Definition: component/val.hh:528
static const Val * from_capi(const Raw *capi)
Definition: component/val.hh:533
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:26
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_async(wasmtime_component_linker_t *linker)
Add all WASI interfaces into the linker provided using async bindings.
WASM_API_EXTERN wasmtime_error_t * wasmtime_component_linker_add_wasi_http_async(wasmtime_component_linker_t *linker)
Add WASI HTTP interfaces into the linker provided using async bindings.
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_add_wasi_http(wasmtime_component_linker_t *linker)
Add WASI HTTP interfaces into the linker provided.
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:383
An interior pointer into a wasmtime_store_t which is used as "context" for many functions.
Errors generated by Wasmtime.