Expand description
Rust bindings for the Kube32 WebAssembly pod ABI.
A request-handling pod is a few functions and one macro invocation:
ⓘ
#![no_std]
use kube32_sdk::{kube32_app, Request, Response};
fn handle(req: &Request) -> i32 {
let mut resp = Response::json(200);
resp.write_str("{\"path\":").write_json_str(req.path).write_str("}");
resp.end()
}
kube32_app! { handle: handle, }The macro exports k32_alloc and k32_handle (plus k32_init,
k32_tick, k32_event when given); the host looks them up by name
(include/runtime/k32_app_abi.h). Build with
cargo build --release --target wasm32-unknown-unknown and the link flags
in sdk/rust/.cargo/config.toml, or with tools/kube32-cli build.
The crate is no_std; the only allocation is the static request buffer
the macro reserves for k32_alloc.
Features:
panic-handler(default): a#[panic_handler]that logs throughk32_logand traps.hardware:hardwarewrapsk32_display_*,k32_key_read,k32_toneand the infrared importsesp32_rmt_sendandesp32_rmt_receive.fs:fswraps thek32_fs_*imports (pod storage on the microSD card).linalg:linalgwraps the native products for quantized neural networks (k32_matvec_*,k32_matmul_*,k32_vecmat_f32_i8,k32_softmax_f32) and their element-wise steps (k32_rmsnorm_f32,k32_quantize_i8,k32_rope_f32,k32_swiglu_f32,k32_add_f32,k32_argmax_f32).
An import is only linked into the module when the app calls it, so the
module’s import list tells which manifest resources it needs;
tools/kube32-cli check prints that list.
Re-exports§
pub use buf::Buf;pub use channel::Channel;pub use host::delay_ms;pub use host::emit;pub use host::env;pub use host::env_len;pub use host::env_u32;pub use host::log;pub use host::mem_stats;pub use host::random;pub use host::time_ms;pub use request::parse_u32;pub use request::percent_decode;pub use request::Request;pub use response::Response;
Modules§
- abi
- Raw host imports, one per declaration in
include/runtime/k32_app_abi.h. - buf
- A fixed-capacity text buffer for event payloads and log lines, without
core::fmt(which costs several KB of wasm) and without an allocator. - channel
- Cluster virtual channels (
kube32_channel_*): ESP-NOW frames on hardware, UDP between simulator processes. Needs theCHANNEL_IPCcapability. - fs
- Pod storage on the node’s microSD card (
k32_fs_*, featurefs). - hardware
- On-board peripherals behind the capability firewall. Every call needs the
matching resource in the pod manifest, otherwise the host returns
Error::Permissionand logs a violation: - host
- Node services: log, time, random, environment, memory statistics, events.
- linalg
- Native products for quantized neural networks (
k32_matvec_i8,k32_matvec_i4,k32_matmul_i8,k32_matmul_i4,k32_matvec_f32_i8,k32_vecmat_f32_i8,k32_softmax_f32) and their element-wise steps (k32_rmsnorm_f32,k32_quantize_i8,k32_rope_f32,k32_swiglu_f32,k32_add_f32,k32_argmax_f32), featurelinalg. - request
- The request block the host hands to
k32_handle. - response
- Streaming responses through
k32_resp_begin/k32_resp_header/k32_resp_write/k32_resp_end.
Macros§
- kube32_
app - Exports the request-pod entry points. Keys are optional but must appear
in this order:
alloc(buffer size in bytes),init,handle,tick,event. - kube32_
main - Exports
app_mainfor a pod that runs its own loop (display, keyboard, channels) instead of handling requests. The host runs it on the pod’s own thread; returning ends the container (the pod log saysentrypoint returned, container completed). The return value is not used.
Enums§
Constants§
- DEFAULT_
ALLOC_ BYTES - Default size of the buffer
k32_allochands to the host: one maximal request block (16 KiB) plus room for an event topic and payload. - ERR_
AGAIN - ERR_
BADF - ERR_
EXIST - ERR_
FAULT - ERR_
INVAL - ERR_IO
- ERR_
ISDIR - ERR_
MFILE - ERR_
NAMETOOLONG - ERR_
NODEV - ERR_
NOENT - ERR_
NOMEM - ERR_
NOSPC - ERR_
PERM - Host error codes: negative errno values (
k32_app_abi.h,hal_types.hpp). - ERR_
TIMEDOUT kube32_channel_recvwhen nothing arrived in time.- ERR_
TOOBIG - HANDLE_
ERR_ BAD_ REQUEST - HANDLE_
ERR_ NO_ RESPONSE k32_handlereturn value when the request block could not be parsed.- MAX_
EVENT_ BYTES - MAX_
HEADER_ BYTES - MAX_
REQUEST_ BYTES - Limits enforced by the host (
k32_app_abi.h).