Skip to main content

Crate kube32_sdk

Crate kube32_sdk 

Source
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 through k32_log and traps.
  • hardware: hardware wraps k32_display_*, k32_key_read, k32_tone and the infrared imports esp32_rmt_send and esp32_rmt_receive.
  • fs: fs wraps the k32_fs_* imports (pod storage on the microSD card).
  • linalg: linalg wraps 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 the CHANNEL_IPC capability.
fs
Pod storage on the node’s microSD card (k32_fs_*, feature fs).
hardware
On-board peripherals behind the capability firewall. Every call needs the matching resource in the pod manifest, otherwise the host returns Error::Permission and 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), feature linalg.
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_main for 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 says entrypoint returned, container completed). The return value is not used.

Enums§

Error

Constants§

DEFAULT_ALLOC_BYTES
Default size of the buffer k32_alloc hands 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_recv when nothing arrived in time.
ERR_TOOBIG
HANDLE_ERR_BAD_REQUEST
HANDLE_ERR_NO_RESPONSE
k32_handle return 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).