faas
The reperfect BaaS guest SDK. A guest is a WASI 0.3 component that exports
wasi:http/handler@0.3.0; the baas host runs it. This crate hides the wit-bindgen
plumbing behind a small surface:
#[faas::function]asyncfn handle(req: faas::Request)-> Result<faas::Response,faas::Error>{Ok(faas::Response::text("hi"))}crates/faas runs wit_bindgen::generate! once over vendored WIT and exposes the
generated Guest trait plus Request/Response wrappers that hide the body-stream
dance. crates/faas-macro is the #[faas::function] attribute that implements the
trait and calls export!.
Depending on it
In-repo sibling crate (this workspace, or a checkout next to it):
faas = { path = "../../crates/faas", features = ["postgres", "config"] }
External consumer (a separate app repo, e.g. reperfect/idp):
faas = { git = "https://codeberg.org/reperfect/faas", features = ["postgres", "config"] }
Every guest is crate-type = ["cdylib"] and only builds for wasm32-wasip3.
Features (each gates one optional capability import; off = not imported)
postgres—faas::pgoverwasmcloud:postgres@0.2.0.config—faas::configoverwasi:config/store.logging—faas::logoverwasi:logging.http-out—faas::http::fetchoverwasi:http/client@0.3.0.
Toolchain (the fragile part)
wasm32-wasip3 is tier-3: rustc knows it but ships no prebuilt std or libc.
scripts/setup-wasip3.sh prebuilds std once into the sysroot and copies wasi-libc
from the wasip2 sysroot, so daily builds are plain cargo build --target wasm32-wasip3 with no -Zbuild-std. Re-run the script after any toolchain reinstall
(sysroot artifacts get wiped). rust-toolchain.toml pins the nightly and rust-src.
wit-bindgen 0.59, not std's 0.57
Prebuilt std bundles wit-bindgen 0.57.1 and exports cabi_realloc_wit_bindgen_0_57_1.
A guest that also pulls 0.57.1 hits a duplicate-symbol link error, so guests generate
their own bindings with 0.59 (version skew avoids the clash). Do not use the
wasip3 crate in a guest — it pins 0.57.1 and collides.
WIT must match the host's wasi:http version
The vendored wasi:http WIT is package @0.3.0 (from wasmtime-wasi-http/src/p3/wit,
not the wasip3 crate's @0.3.0-rc-*). A mismatch is a runtime "resource has the wrong
type" at instantiate. World: export wasi:http/handler@0.3.0.
Example
examples/hello is a #[faas::function] guest that keeps the repo self-verifying:
scripts/setup-wasip3.sh # once
cargo build --target wasm32-wasip3 -p hello --release