mirror of
https://github.com/extism/extism.git
synced 2026-01-10 22:37:58 -05:00
Updates the requirements on [criterion](https://github.com/bheisler/criterion.rs) to permit the latest version. <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/bheisler/criterion.rs/blob/master/CHANGELOG.md">criterion's changelog</a>.</em></p> <blockquote> <h2>[0.6.0] - 2025-05-17</h2> <h3>Changed</h3> <ul> <li>MSRV bumped to 1.80</li> <li>The <code>real_blackbox</code> feature no longer has any impact. Criterion always uses <code>std::hint::black_box()</code> now. Users of <code>criterion::black_box()</code> should switch to <code>std::hint::black_box()</code>.</li> <li><code>clap</code> dependency unpinned.</li> </ul> <h3>Fixed</h3> <ul> <li>gnuplot version is now correctly detected when using certain Windows binaries/configurations that used to fail</li> </ul> <h3>Added</h3> <ul> <li>Async benchmarking with Tokio may be done via a <code>tokio::runtime::Handle</code>, not only a <code>tokio::runtime::Runtime</code></li> </ul> <h2>[0.5.1] - 2023-05-26</h2> <h3>Fixed</h3> <ul> <li>Quick mode (--quick) no longer crashes with measured times over 5 seconds when --noplot is not active</li> </ul> <h2>[0.5.0] - 2023-05-23</h2> <h3>Changed</h3> <ul> <li>Replaced lazy_static dependency with once_cell</li> <li>Improved documentation of the <code>html_reports</code> feature</li> <li>Replaced atty dependency with is-terminal</li> <li>MSRV bumped to 1.64</li> <li>Upgraded clap dependency to v4</li> <li>Upgraded tempfile dependency to v3.5.0</li> </ul> <h3>Fixed</h3> <ul> <li>Quick mode (<code>--quick</code>) no longer outputs 1ms for measured times over 5 seconds</li> <li>Documentation updates</li> </ul> <h2>[0.4.0] - 2022-09-10</h2> <h3>Removed</h3> <ul> <li>The <code>Criterion::can_plot</code> function has been removed.</li> <li>The <code>Criterion::bench_function_over_inputs</code> function has been removed.</li> <li>The <code>Criterion::bench_functions</code> function has been removed.</li> <li>The <code>Criterion::bench</code> function has been removed.</li> </ul> <h3>Changed</h3> <ul> <li>HTML report hidden behind non-default feature flag: 'html_reports'</li> <li>Standalone support (ie without cargo-criterion) feature flag: 'cargo_bench_support'</li> <li>MSRV bumped to 1.57</li> <li><code>rayon</code> and <code>plotters</code> are optional (and default) dependencies.</li> <li>Status messages ('warming up', 'analyzing', etc) are printed to stderr, benchmark results are printed to stdout.</li> <li>Accept subsecond durations for <code>--warm-up-time</code>, <code>--measurement-time</code> and <code>--profile-time</code>.</li> </ul> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Commits</summary> <ul> <li><a href="43bf90a64b"><code>43bf90a</code></a> release version 0.6.0 (<a href="https://redirect.github.com/bheisler/criterion.rs/issues/860">#860</a>)</li> <li><a href="92696e45c5"><code>92696e4</code></a> deps: unpin clap (<a href="https://redirect.github.com/bheisler/criterion.rs/issues/858">#858</a>)</li> <li><a href="5756a5d526"><code>5756a5d</code></a> chore: bump MSRV to 1.80 (<a href="https://redirect.github.com/bheisler/criterion.rs/issues/859">#859</a>)</li> <li><a href="9d887c0145"><code>9d887c0</code></a> Fixed typo in faq.md (<a href="https://redirect.github.com/bheisler/criterion.rs/issues/852">#852</a>)</li> <li><a href="59b791a587"><code>59b791a</code></a> ci: test against MSRV and 1.87 (<a href="https://redirect.github.com/bheisler/criterion.rs/issues/857">#857</a>)</li> <li><a href="ace1cc93ef"><code>ace1cc9</code></a> Fix warnings from clippy (rust 1.87.0) (<a href="https://redirect.github.com/bheisler/criterion.rs/issues/856">#856</a>)</li> <li><a href="7afab6ef7c"><code>7afab6e</code></a> Commit Cargo.lock to make CI and local debugging more stable (<a href="https://redirect.github.com/bheisler/criterion.rs/issues/855">#855</a>)</li> <li><a href="260e2f1c78"><code>260e2f1</code></a> Update Cargo features' comments (<a href="https://redirect.github.com/bheisler/criterion.rs/issues/825">#825</a>)</li> <li><a href="58130ff859"><code>58130ff</code></a> Update to async-std v1.13 (<a href="https://redirect.github.com/bheisler/criterion.rs/issues/812">#812</a>)</li> <li><a href="d2e705b855"><code>d2e705b</code></a> Add rust-version 1.70 (<a href="https://redirect.github.com/bheisler/criterion.rs/issues/813">#813</a>)</li> <li>Additional commits viewable in <a href="https://github.com/bheisler/criterion.rs/compare/0.5.1...0.6.0">compare view</a></li> </ul> </details> <br /> Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: zach <zach@dylibso.com>
345 lines
10 KiB
C
345 lines
10 KiB
C
#pragma once
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
#define EXTISM_FUNCTION(N) extern void N(ExtismCurrentPlugin*, const ExtismVal*, ExtismSize, ExtismVal*, ExtismSize, void*)
|
|
#define EXTISM_GO_FUNCTION(N) extern void N(void*, ExtismVal*, ExtismSize, ExtismVal*, ExtismSize, uintptr_t)
|
|
|
|
/** The return code from extism_plugin_call used to signal a successful call with no errors */
|
|
#define EXTISM_SUCCESS 0
|
|
|
|
/** An alias for I64 to signify an Extism pointer */
|
|
#define EXTISM_PTR ExtismValType_I64
|
|
|
|
|
|
/**
|
|
* An enumeration of all possible value types in WebAssembly.
|
|
*/
|
|
typedef enum {
|
|
/**
|
|
* Signed 32 bit integer.
|
|
*/
|
|
ExtismValType_I32,
|
|
/**
|
|
* Signed 64 bit integer.
|
|
*/
|
|
ExtismValType_I64,
|
|
/**
|
|
* Floating point 32 bit integer.
|
|
*/
|
|
ExtismValType_F32,
|
|
/**
|
|
* Floating point 64 bit integer.
|
|
*/
|
|
ExtismValType_F64,
|
|
/**
|
|
* A 128 bit number.
|
|
*/
|
|
ExtismValType_V128,
|
|
/**
|
|
* A reference to a Wasm function.
|
|
*/
|
|
ExtismValType_FuncRef,
|
|
/**
|
|
* A reference to opaque data in the Wasm instance.
|
|
*/
|
|
ExtismValType_ExternRef,
|
|
} ExtismValType;
|
|
|
|
/**
|
|
* A `CancelHandle` can be used to cancel a running plugin from another thread
|
|
*/
|
|
typedef struct ExtismCancelHandle ExtismCancelHandle;
|
|
|
|
typedef struct ExtismCompiledPlugin ExtismCompiledPlugin;
|
|
|
|
/**
|
|
* CurrentPlugin stores data that is available to the caller in PDK functions, this should
|
|
* only be accessed from inside a host function
|
|
*/
|
|
typedef struct ExtismCurrentPlugin ExtismCurrentPlugin;
|
|
|
|
typedef struct ExtismFunction ExtismFunction;
|
|
|
|
/**
|
|
* Plugin contains everything needed to execute a WASM function
|
|
*/
|
|
typedef struct ExtismPlugin ExtismPlugin;
|
|
|
|
typedef uint64_t ExtismMemoryHandle;
|
|
|
|
typedef uint64_t ExtismSize;
|
|
|
|
/**
|
|
* A union type for host function argument/return values
|
|
*/
|
|
typedef union {
|
|
int32_t i32;
|
|
int64_t i64;
|
|
float f32;
|
|
double f64;
|
|
} ExtismValUnion;
|
|
|
|
/**
|
|
* `ExtismVal` holds the type and value of a function argument/return
|
|
*/
|
|
typedef struct {
|
|
ExtismValType t;
|
|
ExtismValUnion v;
|
|
} ExtismVal;
|
|
|
|
/**
|
|
* Host function signature
|
|
*/
|
|
typedef void (*ExtismFunctionType)(ExtismCurrentPlugin *plugin,
|
|
const ExtismVal *inputs,
|
|
ExtismSize n_inputs,
|
|
ExtismVal *outputs,
|
|
ExtismSize n_outputs,
|
|
void *data);
|
|
|
|
/**
|
|
* Log drain callback
|
|
*/
|
|
typedef void (*ExtismLogDrainFunctionType)(const char *data, ExtismSize size);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif // __cplusplus
|
|
|
|
/**
|
|
* Get a plugin's ID, the returned bytes are a 16 byte buffer that represent a UUIDv4
|
|
*/
|
|
const uint8_t *extism_plugin_id(ExtismPlugin *plugin);
|
|
|
|
/**
|
|
* Get the current plugin's associated host context data. Returns null if call was made without
|
|
* host context.
|
|
*/
|
|
void *extism_current_plugin_host_context(ExtismCurrentPlugin *plugin);
|
|
|
|
/**
|
|
* Returns a pointer to the memory of the currently running plugin
|
|
* NOTE: this should only be called from host functions.
|
|
*/
|
|
uint8_t *extism_current_plugin_memory(ExtismCurrentPlugin *plugin);
|
|
|
|
/**
|
|
* Allocate a memory block in the currently running plugin
|
|
* NOTE: this should only be called from host functions.
|
|
*/
|
|
ExtismMemoryHandle extism_current_plugin_memory_alloc(ExtismCurrentPlugin *plugin, ExtismSize n);
|
|
|
|
/**
|
|
* Get the length of an allocated block
|
|
* NOTE: this should only be called from host functions.
|
|
*/
|
|
ExtismSize extism_current_plugin_memory_length(ExtismCurrentPlugin *plugin, ExtismMemoryHandle n);
|
|
|
|
/**
|
|
* Free an allocated memory block
|
|
* NOTE: this should only be called from host functions.
|
|
*/
|
|
void extism_current_plugin_memory_free(ExtismCurrentPlugin *plugin, ExtismMemoryHandle ptr);
|
|
|
|
/**
|
|
* Create a new host function
|
|
*
|
|
* Arguments
|
|
* - `name`: function name, this should be valid UTF-8
|
|
* - `inputs`: argument types
|
|
* - `n_inputs`: number of argument types
|
|
* - `outputs`: return types
|
|
* - `n_outputs`: number of return types
|
|
* - `func`: the function to call
|
|
* - `user_data`: a pointer that will be passed to the function when it's called
|
|
* this value should live as long as the function exists
|
|
* - `free_user_data`: a callback to release the `user_data` value when the resulting
|
|
* `ExtismFunction` is freed.
|
|
*
|
|
* Returns a new `ExtismFunction` or `null` if the `name` argument is invalid.
|
|
*/
|
|
ExtismFunction *extism_function_new(const char *name,
|
|
const ExtismValType *inputs,
|
|
ExtismSize n_inputs,
|
|
const ExtismValType *outputs,
|
|
ExtismSize n_outputs,
|
|
ExtismFunctionType func,
|
|
void *user_data,
|
|
void (*free_user_data)(void *_));
|
|
|
|
/**
|
|
* Free `ExtismFunction`
|
|
*/
|
|
void extism_function_free(ExtismFunction *f);
|
|
|
|
/**
|
|
* Set the namespace of an `ExtismFunction`
|
|
*/
|
|
void extism_function_set_namespace(ExtismFunction *ptr, const char *namespace_);
|
|
|
|
/**
|
|
* Pre-compile an Extism plugin
|
|
*/
|
|
ExtismCompiledPlugin *extism_compiled_plugin_new(const uint8_t *wasm,
|
|
ExtismSize wasm_size,
|
|
const ExtismFunction **functions,
|
|
ExtismSize n_functions,
|
|
bool with_wasi,
|
|
char **errmsg);
|
|
|
|
/**
|
|
* Free `ExtismCompiledPlugin`
|
|
*/
|
|
void extism_compiled_plugin_free(ExtismCompiledPlugin *plugin);
|
|
|
|
/**
|
|
* Create a new plugin with host functions, the functions passed to this function no longer need to be manually freed using
|
|
*
|
|
* `wasm`: is a WASM module (wat or wasm) or a JSON encoded manifest
|
|
* `wasm_size`: the length of the `wasm` parameter
|
|
* `functions`: an array of `ExtismFunction*`
|
|
* `n_functions`: the number of functions provided
|
|
* `with_wasi`: enables/disables WASI
|
|
*/
|
|
ExtismPlugin *extism_plugin_new(const uint8_t *wasm,
|
|
ExtismSize wasm_size,
|
|
const ExtismFunction **functions,
|
|
ExtismSize n_functions,
|
|
bool with_wasi,
|
|
char **errmsg);
|
|
|
|
/**
|
|
* Create a new plugin from an `ExtismCompiledPlugin`
|
|
*/
|
|
ExtismPlugin *extism_plugin_new_from_compiled(const ExtismCompiledPlugin *compiled, char **errmsg);
|
|
|
|
/**
|
|
* Create a new plugin and set the number of instructions a plugin is allowed to execute
|
|
*/
|
|
ExtismPlugin *extism_plugin_new_with_fuel_limit(const uint8_t *wasm,
|
|
ExtismSize wasm_size,
|
|
const ExtismFunction **functions,
|
|
ExtismSize n_functions,
|
|
bool with_wasi,
|
|
uint64_t fuel_limit,
|
|
char **errmsg);
|
|
|
|
/**
|
|
* Enable HTTP response headers in plugins using `extism:host/env::http_request`
|
|
*/
|
|
void extism_plugin_allow_http_response_headers(ExtismPlugin *plugin);
|
|
|
|
/**
|
|
* Free the error returned by `extism_plugin_new`, errors returned from `extism_plugin_error` don't need to be freed
|
|
*/
|
|
void extism_plugin_new_error_free(char *err);
|
|
|
|
/**
|
|
* Free `ExtismPlugin`
|
|
*/
|
|
void extism_plugin_free(ExtismPlugin *plugin);
|
|
|
|
/**
|
|
* Get handle for plugin cancellation
|
|
*/
|
|
const ExtismCancelHandle *extism_plugin_cancel_handle(const ExtismPlugin *plugin);
|
|
|
|
/**
|
|
* Cancel a running plugin
|
|
*/
|
|
bool extism_plugin_cancel(const ExtismCancelHandle *handle);
|
|
|
|
/**
|
|
* Update plugin config values.
|
|
*/
|
|
bool extism_plugin_config(ExtismPlugin *plugin, const uint8_t *json, ExtismSize json_size);
|
|
|
|
/**
|
|
* Returns true if `func_name` exists
|
|
*/
|
|
bool extism_plugin_function_exists(ExtismPlugin *plugin, const char *func_name);
|
|
|
|
/**
|
|
* Call a function
|
|
*
|
|
* `func_name`: is the function to call
|
|
* `data`: is the input data
|
|
* `data_len`: is the length of `data`
|
|
*/
|
|
int32_t extism_plugin_call(ExtismPlugin *plugin,
|
|
const char *func_name,
|
|
const uint8_t *data,
|
|
ExtismSize data_len);
|
|
|
|
/**
|
|
* Call a function with host context.
|
|
*
|
|
* `func_name`: is the function to call
|
|
* `data`: is the input data
|
|
* `data_len`: is the length of `data`
|
|
* `host_context`: a pointer to context data that will be available in host functions
|
|
*/
|
|
int32_t extism_plugin_call_with_host_context(ExtismPlugin *plugin,
|
|
const char *func_name,
|
|
const uint8_t *data,
|
|
ExtismSize data_len,
|
|
void *host_context);
|
|
|
|
/**
|
|
* Get the error associated with a `Plugin`
|
|
*/
|
|
const char *extism_error(ExtismPlugin *plugin);
|
|
|
|
/**
|
|
* Get the error associated with a `Plugin`
|
|
*/
|
|
const char *extism_plugin_error(ExtismPlugin *plugin);
|
|
|
|
/**
|
|
* Get the length of a plugin's output data
|
|
*/
|
|
ExtismSize extism_plugin_output_length(ExtismPlugin *plugin);
|
|
|
|
/**
|
|
* Get a pointer to the output data
|
|
*/
|
|
const uint8_t *extism_plugin_output_data(ExtismPlugin *plugin);
|
|
|
|
/**
|
|
* Set log file and level.
|
|
* The log level can be either one of: info, error, trace, debug, warn or a more
|
|
* complex filter like `extism=trace,cranelift=debug`
|
|
* The file will be created if it doesn't exist.
|
|
*/
|
|
bool extism_log_file(const char *filename, const char *log_level);
|
|
|
|
/**
|
|
* Enable a custom log handler, this will buffer logs until `extism_log_drain` is called
|
|
* Log level should be one of: info, error, trace, debug, warn
|
|
*/
|
|
bool extism_log_custom(const char *log_level);
|
|
|
|
/**
|
|
* Calls the provided callback function for each buffered log line.
|
|
* This is only needed when `extism_log_custom` is used.
|
|
*/
|
|
void extism_log_drain(ExtismLogDrainFunctionType handler);
|
|
|
|
/**
|
|
* Reset the Extism runtime, this will invalidate all allocated memory
|
|
*/
|
|
bool extism_plugin_reset(ExtismPlugin *plugin);
|
|
|
|
/**
|
|
* Get the Extism version string
|
|
*/
|
|
const char *extism_version(void);
|
|
|
|
#ifdef __cplusplus
|
|
} // extern "C"
|
|
#endif // __cplusplus
|