uni_plugin_wasm/lib.rs
1//! WASM Component Model loader for the uni-db plugin framework.
2//!
3//! `uni-plugin-wasm` provides the host-side machinery to load WASM
4//! plugins built against the `uni:plugin` WIT worlds. The boundary uses:
5//!
6//! - **WIT-typed contracts** for each plugin kind (scalar, aggregate,
7//! procedure, locy-agg, hook, storage, …) — typed exports + capability-
8//! gated host imports.
9//! - **Arrow IPC over linear memory** for `RecordBatch` exchange — host
10//! calls plugin's `alloc(len)`, copies IPC bytes in, calls the work
11//! export, reads IPC bytes back at the returned `(ptr, len)`.
12//! - **Pre-warmed instance pools** to amortize the 10–100 ms wasmtime
13//! instantiation cost across hot-path UDF invocations.
14//!
15//! # Crate status
16//!
17//! [`WasmLoader::load`] is fully wired behind the `wasmtime-runtime`
18//! feature (default-on): it instantiates a component, negotiates
19//! capabilities against the host grants, and registers the plugin's
20//! scalar / aggregate / procedure adapters end-to-end through the
21//! respective WIT worlds.
22
23// Rust guideline compliant
24#![warn(missing_docs)]
25#![warn(rust_2018_idioms)]
26#![warn(missing_debug_implementations)]
27
28pub mod buffer;
29pub mod error;
30
31/// Arrow IPC bridge — re-exported from `uni-plugin-wasm-rt`.
32///
33/// Lifted to the shared crate in M6.shared. `WasmIpcBuffer` (the
34/// wasmtime-specific linear-memory RAII helper) stays here in
35/// [`crate::buffer`].
36pub mod ipc {
37 pub use uni_plugin_wasm_rt::ipc::{decode_batch, decode_batches, encode_batch, encode_batches};
38}
39
40/// Instance pool — re-exported from `uni-plugin-wasm-rt`.
41///
42/// Type-aliased so `WasmInstancePool<T>` keeps working unchanged
43/// downstream.
44pub mod pool {
45 pub use uni_plugin_wasm_rt::pool::{PoolConfig, PoolMetrics};
46
47 /// Type alias — generic `InstancePool` parameterized with
48 /// [`crate::WasmError`].
49 pub type WasmInstancePool<T> = uni_plugin_wasm_rt::pool::InstancePool<T, crate::WasmError>;
50
51 /// Type alias — generic `PooledInstance` parameterized with
52 /// [`crate::WasmError`].
53 pub type PooledInstance<T> = uni_plugin_wasm_rt::pool::PooledInstance<T, crate::WasmError>;
54}
55
56#[cfg(feature = "wasmtime-runtime")]
57pub mod adapter;
58#[cfg(feature = "wasmtime-runtime")]
59pub mod adapter_aggregate;
60#[cfg(feature = "wasmtime-runtime")]
61pub(crate) mod adapter_common;
62#[cfg(feature = "wasmtime-runtime")]
63pub mod adapter_procedure;
64#[cfg(feature = "wasmtime-runtime")]
65pub mod bindings;
66#[cfg(feature = "wasmtime-runtime")]
67pub mod host_state;
68#[cfg(feature = "wasmtime-runtime")]
69pub mod linker;
70#[cfg(feature = "wasmtime-runtime")]
71pub mod loader;
72#[cfg(feature = "wasmtime-runtime")]
73pub mod multi_version;
74
75#[doc(inline)]
76pub use buffer::WasmIpcBuffer;
77#[doc(inline)]
78pub use error::WasmError;
79#[doc(inline)]
80pub use pool::WasmInstancePool;
81
82#[cfg(feature = "wasmtime-runtime")]
83#[doc(inline)]
84pub use loader::WasmLoader;
85
86#[cfg(feature = "wasmtime-runtime")]
87#[doc(inline)]
88pub use multi_version::{MultiVersionLinker, SUPPORTED_MAJORS};