5#ifndef WASMTIME_COMPONENT_COMPONENT_HH
6#define WASMTIME_COMPONENT_COMPONENT_HH
10#ifdef WASMTIME_FEATURE_COMPONENT_MODEL
40 std::unique_ptr<wasmtime_component_export_index_t, deleter> ptr;
78 std::unique_ptr<wasmtime_component_t, deleter> ptr;
103#ifdef WASMTIME_FEATURE_COMPILER
115 auto bytes = wasm.ok();
134 if (error !=
nullptr) {
157 if (error !=
nullptr) {
176 const std::string &path) {
180 if (error !=
nullptr) {
186#ifdef WASMTIME_FEATURE_COMPILER
196 if (error !=
nullptr) {
199 std::vector<uint8_t> ret;
215 std::string_view name) {
217 capi(), instance ? instance->
capi() :
nullptr, name.data(),
Global compilation state in Wasmtime.
Definition: engine.hh:21
const wasm_engine_t * capi() const
Returns the underlying C API pointer.
Definition: engine.hh:61
Errors coming from Wasmtime.
Definition: error.hh:25
Fallible result type used for Wasmtime.
Definition: error.hh:82
Span class used when c++20 is not available.
Definition: span.hh:47
std::size_t size() const
Returns number of data that referred by Span class.
Definition: span.hh:81
iterator end() const
Returns end iterator.
Definition: span.hh:87
T * data() const
Returns pointer to data.
Definition: span.hh:78
iterator begin() const
Returns begin iterator.
Definition: span.hh:84
Representation of a compiled WebAssembly component.
Definition: component/component.hh:71
static Result< Component > deserialize_file(Engine &engine, const std::string &path)
Deserializes a component from an on-disk file.
Definition: component/component.hh:175
Component & operator=(Component &&other)=default
Moves resources from another component into this one.
const wasmtime_component_t * capi() const
Returns the underlying C API pointer.
Definition: component/component.hh:98
Result< std::vector< uint8_t > > serialize() const
Serializes this component to a list of bytes.
Definition: component/component.hh:193
Component & operator=(const Component &other)
Copies another component into this one.
Definition: component/component.hh:87
Component(Component &&other)=default
Moves resources from another component into this one.
static Result< Component > compile(Engine &engine, std::string_view wat)
Compiles a component from the WebAssembly text format.
Definition: component/component.hh:110
static Result< Component > deserialize(Engine &engine, Span< uint8_t > wasm)
Deserializes a previous list of bytes created with serialize.
Definition: component/component.hh:153
wasmtime_component_t * capi()
Returns the underlying C API pointer.
Definition: component/component.hh:101
static Result< Component > compile(Engine &engine, Span< uint8_t > wasm)
Compiles a component from the WebAssembly binary format.
Definition: component/component.hh:130
std::optional< ExportIndex > export_index(ExportIndex *instance, std::string_view name)
Returns the export index for the export named name in this component.
Definition: component/component.hh:214
Component(const Component &other)
Copies another component into this one.
Definition: component/component.hh:84
An index to an exported item within a particular component.
Definition: component/component.hh:31
ExportIndex(ExportIndex &&other)=default
Moves resources from another component into this one.
ExportIndex(wasmtime_component_export_index_t *raw)
Constructs an ExportIndex from the underlying C API struct.
Definition: component/component.hh:44
const wasmtime_component_export_index_t * capi() const
Returns the underlying C API pointer.
Definition: component/component.hh:62
ExportIndex & operator=(const ExportIndex &other)
Copies another index into this one.
Definition: component/component.hh:50
ExportIndex(const ExportIndex &other)
Copies another index into this one.
Definition: component/component.hh:47
ExportIndex & operator=(ExportIndex &&other)=default
Moves resources from another component into this one.
wasmtime_component_export_index_t * capi()
Returns the underlying C API pointer.
Definition: component/component.hh:65
wasmtime_error_t * wasmtime_component_deserialize(const wasm_engine_t *engine, const uint8_t *buf, size_t len, wasmtime_component_t **component_out)
Build a component from serialized data.
wasmtime_component_t * wasmtime_component_clone(const wasmtime_component_t *component)
Creates a shallow clone of the specified component, increasing the internal reference count.
struct wasmtime_component_export_index_t wasmtime_component_export_index_t
A value which represents a known export of a component.
Definition: component/component.h:113
wasmtime_component_export_index_t * wasmtime_component_export_index_clone(const wasmtime_component_export_index_t *index)
Creates a new separately-owned copy of the specified index.
struct wasmtime_component_t wasmtime_component_t
Representation of a component in the component model.
Definition: component/component.h:17
wasmtime_component_export_index_t * wasmtime_component_get_export_index(const wasmtime_component_t *component, const wasmtime_component_export_index_t *instance_export_index, const char *name, size_t name_len)
Looks up a specific export of this component by name optionally nested within the instance provided.
wasmtime_error_t * wasmtime_component_new(const wasm_engine_t *engine, const uint8_t *buf, size_t len, wasmtime_component_t **component_out)
Compiles a WebAssembly binary into a wasmtime_component_t.
wasmtime_error_t * wasmtime_component_serialize(const wasmtime_component_t *component, wasm_byte_vec_t *ret)
This function serializes compiled component artifacts as blob data.
void wasmtime_component_delete(wasmtime_component_t *component)
Deletes a wasmtime_component_t created by wasmtime_component_new.
void wasmtime_component_export_index_delete(wasmtime_component_export_index_t *export_index)
Deletes a wasmtime_component_export_index_t.
wasmtime_error_t * wasmtime_component_deserialize_file(const wasm_engine_t *engine, const char *path, wasmtime_component_t **component_out)
Deserialize a component from an on-disk file.
Build-time defines for how the C API was built.
A list of bytes.
Definition: wasm.h:102
size_t size
Length of this vector.
Definition: wasm.h:102
wasm_byte_t * data
Pointer to the base of this vector.
Definition: wasm.h:102
void wasm_byte_vec_delete(wasm_byte_vec_t *)
Deletes a byte vector.
Result< std::vector< uint8_t > > wat2wasm(std::string_view wat)
Converts the WebAssembly text format into the WebAssembly binary format.
Definition: wat.hh:30