/zig-spin

🪀 Zig Spin SDK.

Primary LanguageCMIT LicenseMIT

🦎 🪀 zig spin

CI CD DC LC

Zig SDK for the Spin serverless application framework created by the Fermyon team.

🚀 Usage

Important

  • Make sure your executable's optimization mode is ReleaseSmall and target is wasm32-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.

  1. Add spin as a dependency in your build.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> to 12200000000000000000000000000000000000000000000000000000000000000000 and build your package to find the correct value specified in a compiler error message.

  2. Add spin as a module in your build.zig.

    build.zig example
    const spin_dep = b.dependency("spin", .{});
    const spin_mod = spin.module("spin");
    exe.root_module.addImport("spin", spin_mod);

🔋 Progress

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

⬇️ Dependencies