3
0
Fork
You've already forked faas
0
reperfect BaaS guest SDK — #[faas::function] macro + WASI 0.3 component bindings (wasm32-wasip3)
  • Rust 89.4%
  • Shell 10.6%
Vojtěch Fošnár 754cfd0421
feat: extract reperfect BaaS guest SDK (faas + faas-macro) as a standalone workspace
Vendored WIT, wasip3 toolchain bootstrap, wit-bindgen 0.59 pin, and a self-verifying
#[faas::function] example guest. Guests depend via path (in-workspace) or git dep.
2026年07月11日 14:32:35 +02:00
.cargo feat: extract reperfect BaaS guest SDK (faas + faas-macro) as a standalone workspace 2026年07月11日 14:32:35 +02:00
crates feat: extract reperfect BaaS guest SDK (faas + faas-macro) as a standalone workspace 2026年07月11日 14:32:35 +02:00
examples/hello feat: extract reperfect BaaS guest SDK (faas + faas-macro) as a standalone workspace 2026年07月11日 14:32:35 +02:00
LICENSES feat: extract reperfect BaaS guest SDK (faas + faas-macro) as a standalone workspace 2026年07月11日 14:32:35 +02:00
scripts feat: extract reperfect BaaS guest SDK (faas + faas-macro) as a standalone workspace 2026年07月11日 14:32:35 +02:00
.gitignore feat: extract reperfect BaaS guest SDK (faas + faas-macro) as a standalone workspace 2026年07月11日 14:32:35 +02:00
Cargo.lock feat: extract reperfect BaaS guest SDK (faas + faas-macro) as a standalone workspace 2026年07月11日 14:32:35 +02:00
Cargo.toml feat: extract reperfect BaaS guest SDK (faas + faas-macro) as a standalone workspace 2026年07月11日 14:32:35 +02:00
README.md feat: extract reperfect BaaS guest SDK (faas + faas-macro) as a standalone workspace 2026年07月11日 14:32:35 +02:00
REUSE.toml feat: extract reperfect BaaS guest SDK (faas + faas-macro) as a standalone workspace 2026年07月11日 14:32:35 +02:00
rust-toolchain.toml feat: extract reperfect BaaS guest SDK (faas + faas-macro) as a standalone workspace 2026年07月11日 14:32:35 +02:00

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)

  • postgresfaas::pg over wasmcloud:postgres@0.2.0.
  • configfaas::config over wasi:config/store.
  • loggingfaas::log over wasi:logging.
  • http-outfaas::http::fetch over wasi: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