Zig SDK for the Spin serverless application framework created by the Fermyon team.
Important
- Make sure your executable's optimization mode is
ReleaseSmall
and target iswasm32-wasi
. - Make sure you use
std.heap.c_allocator
when allocating/freeing memory consumed/returned by this library. - Currently, this library leaks memory to avoid some reallocations. Ideally, it would use WIT Zig bindings that relied on
std.heap.wasm_allocator
.
See the package test for a complete basic usage example.
-
Add
spin
as a dependency in yourbuild.zig.zon
.build.zig.zon
example.{ .name = "<name_of_your_package>", .version = "<version_of_your_package>", .dependencies = .{ .spin = .{ .url = "https://github.com/tensorush/zig-spin/archive/<git_tag_or_commit_hash>.tar.gz", .hash = "<package_hash>", }, }, .paths = .{ "src/", "build.zig", "README.md", "LICENSE.md", "build.zig.zon", }, }
Set
<package_hash>
to12200000000000000000000000000000000000000000000000000000000000000000
and build your package to find the correct value specified in a compiler error message. -
Add
spin
as a module in yourbuild.zig
.build.zig
exampleconst spin_dep = b.dependency("spin", .{}); const spin_mod = spin.module("spin"); exe.root_module.addImport("spin", spin_mod);
Note
Legend: 🟢 - tested, 🟡 - untested, 🔴 - unimplemented.
Component | Status | Example |
---|---|---|
HTTP (outbound) | 🟢 | Click |
HTTP (inbound) | 🟢 | Click |
Redis (outbound) | 🟡 | Click |
Redis (inbound) | 🟡 | Click |
Key-value store | 🟢 | Click |
PostgreSQL | 🟡 | Click |
MySQL | 🟡 | Click |
SQLite | 🟡 | Click |
Config | 🟢 | Click |
MQTT | 🔴 | Click |
LLM | 🔴 | Click |
-
wit-bindgen-cli
- guest language WIT bindings generator.cargo install --git https://github.com/fermyon/wit-bindgen-backport --rev b89d507 wit-bindgen-cli