3#ifndef WASMTIME_COMPONENT_LINKER_HH
4#define WASMTIME_COMPONENT_LINKER_HH
8#ifdef WASMTIME_FEATURE_COMPONENT_MODEL
35 std::unique_ptr<wasmtime_component_linker_instance_t, deleter> ptr;
53 ptr.get(), name.data(), name.size(), module.
capi());
54 if (error !=
nullptr) {
57 return std::monostate();
70 ptr.get(), name.data(), name.size(), &ret);
71 if (error !=
nullptr) {
85 F *func =
reinterpret_cast<F *
>(env);
91 return result.
err().release();
96 template <
typename F>
static void raw_finalize(
void *env) {
97 std::unique_ptr<F> ptr(
reinterpret_cast<F *
>(env));
102 template <
typename F,
104 std::is_invocable_r_v<Result<std::monostate>, F, Store::Context,
105 Span<const Val>, Span<Val>>,
109 ptr.get(), name.data(), name.length(),
110 raw_callback<std::remove_reference_t<F>>,
111 std::make_unique<std::remove_reference_t<F>>(std::forward<F>(f))
113 raw_finalize<std::remove_reference_t<F>>);
115 if (error !=
nullptr) {
119 return std::monostate();
123 template <
typename F>
127 F *func =
reinterpret_cast<F *
>(env);
130 return result.
err().release();
138 template <
typename F,
139 std::enable_if_t<std::is_invocable_r_v<Result<std::monostate>, F,
140 Store::Context, uint32_t>,
145 ptr.get(), name.data(), name.length(), ty.
capi(),
146 raw_resource_destructor_callback<std::remove_reference_t<F>>,
147 std::make_unique<std::remove_reference_t<F>>(std::forward<F>(f))
149 raw_finalize<std::remove_reference_t<F>>);
151 if (error !=
nullptr) {
155 return std::monostate();
169 std::unique_ptr<wasmtime_component_linker_t, deleter> ptr;
201 ptr.get(), cx.
capi(), component.
capi(), &ret);
202 if (error !=
nullptr) {
208#ifdef WASMTIME_FEATURE_WASI
219 if (error !=
nullptr) {
222 return std::monostate();
Global compilation state in Wasmtime.
Definition: engine.hh:21
Errors coming from Wasmtime.
Definition: error.hh:25
Representation of a compiled WebAssembly module.
Definition: module.hh:27
const wasmtime_module_t * capi() const
Returns the underlying C API pointer.
Definition: module.hh:188
Fallible result type used for Wasmtime.
Definition: error.hh:82
E && err()
Returns the error, if present, aborts if this is not an error.
Definition: error.hh:96
Span class used when c++20 is not available.
Definition: span.hh:47
An interior pointer into a Store.
Definition: store.hh:60
const wasmtime_context_t * capi() const
Returns the underlying C API pointer.
Definition: store.hh:154
Representation of a compiled WebAssembly component.
Definition: component/component.hh:71
const wasmtime_component_t * capi() const
Returns the underlying C API pointer.
Definition: component/component.hh:98
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
wasmtime_component_linker_instance_t * capi()
Returns the underlying C API pointer.
Definition: component/linker.hh:46
Result< LinkerInstance > add_instance(std::string_view name)
Adds an new instance to this linker instance under the specified name.
Definition: component/linker.hh:67
Result< std::monostate > add_module(std::string_view name, Module &module)
Adds a module to this linker instance under the specified name.
Definition: component/linker.hh:51
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:142
const wasmtime_component_linker_instance_t * capi() const
Returns the underlying C API pointer.
Definition: component/linker.hh:43
Result< std::monostate > add_func(std::string_view name, F &&f)
Defines a function within this linker instance.
Definition: component/linker.hh:107
LinkerInstance(wasmtime_component_linker_instance_t *ptr)
Creates a new linker instance from the given C API pointer.
Definition: component/linker.hh:39
Class used to instantiate a Component into an instance.
Definition: component/linker.hh:162
Linker(Engine &engine)
Creates a new linker which will instantiate in the given engine.
Definition: component/linker.hh:173
void allow_shadowing(bool allow)
Definition: component/linker.hh:193
Result< std::monostate > add_wasip2()
Adds WASIp2 API definitions to this linker.
Definition: component/linker.hh:217
wasmtime_component_linker_t * capi()
Returns the underlying C API pointer.
Definition: component/linker.hh:230
Result< Instance > instantiate(Store::Context cx, Component &component)
Instantiates the given component within this linker.
Definition: component/linker.hh:198
LinkerInstance root()
Gets the "root" instance of this linker which can be used to define items into the linker under the t...
Definition: component/linker.hh:184
const wasmtime_component_linker_t * capi() const
Returns the underlying C API pointer.
Definition: component/linker.hh:227
Definition: component/val.hh:397
const wasmtime_component_resource_type_t * capi() const
Returns the underlying C API pointer.
Definition: component/val.hh:440
Class representing an instantiated WebAssembly component.
Definition: component/val.hh:593
static const Val * from_capi(const Raw *capi)
Definition: component/val.hh:598
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.
wasmtime_component_linker_t * wasmtime_component_linker_new(const wasm_engine_t *engine)
Creates a new wasmtime_component_linker_t for the specified engine.
struct wasmtime_component_linker_instance_t wasmtime_component_linker_instance_t
Structure representing an "instance" being defined within a linker.
Definition: component/linker.h:24
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.
void wasmtime_component_linker_allow_shadowing(wasmtime_component_linker_t *linker, bool allow)
Configures whether this linker allows later definitions to shadow previous definitions.
void wasmtime_component_linker_instance_delete(wasmtime_component_linker_instance_t *linker_instance)
Deletes a wasmtime_component_linker_instance_t.
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.
struct wasmtime_component_linker_t wasmtime_component_linker_t
A type used to instantiate a wasmtime_component_t.
Definition: component/linker.h:21
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.
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.
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.
wasmtime_error_t * wasmtime_component_linker_add_wasip2(wasmtime_component_linker_t *linker)
Add all WASI interfaces into the linker provided.
void wasmtime_component_linker_delete(wasmtime_component_linker_t *linker)
Deletes a wasmtime_component_linker_t created by wasmtime_component_linker_new.
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:425
An interior pointer into a wasmtime_store_t which is used as "context" for many functions.
Errors generated by Wasmtime.