Skip to content
项目

关于

A fast, spec-compliant WebAssembly runtime written in Zig

编程语言与运行时

这些数字如何统计

实测星标增长

24小时
0
7天
+1
15天
+5
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

zwasm

A spec-compliant WebAssembly runtime written in Zig.

CI Release Zig WebAssembly 3.0 License: Apache 2.0

  • Full spec coverage — WebAssembly 3.0 (all 9 proposals), spec testsuite green on macOS aarch64, Linux x86_64 and aarch64, and Windows x86_64. CI runs both engines; the JIT lane enumerates its known-wrong outcomes and gates on an exact match. WASI 0.1, 0.2 (Component Model) and 0.3 (native async), all on by default.
  • Three execution backends — interpreter, JIT (arm64 + x86_64) and AOT (.cwasm), differentially tested against each other on every change. wasmtime is the external oracle for the interpreter and JIT; the AOT lane against it runs on demand.
  • Embeddable, sandboxed by default — C (standard wasm-c-api), Zig and CLI surfaces; the Zig API gives instances finite fuel, memory and table budgets by default, and every surface can set them explicitly.

Status: feature-complete and green on the 3-OS CI matrix. v2.0.0 is the first stable release (SemVer starts there); the current line is on Releases. v2 is a ground-up redesign — v1 is frozen at v1.11.1 (MIT), and the v2 line is Apache-2.0 with no v1 ABI compatibility.

Install

Homebrew (macOS arm64 / Linux):

brew install zwasm/tap/zwasm

The zwasm binary is not code-signed. Homebrew installs it without a Gatekeeper prompt on most setups; if macOS still blocks it as coming from an unidentified developer, clear the quarantine flag once:

xattr -d com.apple.quarantine "$(which zwasm)"

Or grab a prebuilt binary straight from the Releases page (macOS arm64, Linux x86_64/aarch64, Windows x86_64). Building from source is below.

Then run a module:

zwasm run hello.wasm                     # WASI _start / main
zwasm run --invoke 'add=2,40' lib.wasm   # call a named export (prints 42)
zwasm compile app.wasm -o app.cwasm      # AOT-compile, then run the artifact
zwasm run app.cwasm

Full walkthrough (run, preopen dirs, embed from Zig and C): docs/tutorial.md.

Supported platforms

zwasm is built and tested on these host targets:

Platform Arch Notes
macOS aarch64 primary development target
Linux x86_64 native, spec + full test gate
Linux aarch64 native, spec + core test gate
Windows x86_64 native, MSVC ABI

Each release is verified on native macOS-aarch64, Linux-x86_64, Linux-aarch64 and Windows-x86_64 hosts. Windows ARM64 and other targets are out of scope for now (demand-driven).

Coverage

Wasm versions

Spec Status Notes
Wasm 1.0 ✅ 100% spec testsuite green on the 3-OS CI matrix
Wasm 2.0 (multi-value, SIMD-128, bulk-memory, reference-types, non-trapping FP→int, sign-ext, mutable globals) ✅ 100% skip-impl == 0; bit-identical across hosts
Wasm 3.0 (GC, EH, tail-call, memory64, multi-memory, typed func refs, extended-const, relaxed-simd, custom annotations) ✅ 100% all 9 proposals, on the 3-OS CI matrix: the interpreter and JIT lanes are green (extended-const: unit-tested, no corpus lane; an imported global inside offset arithmetic is refused, #687)

WASI

Spec Status Notes
WASI 0.1 (preview1) ✅ functional, both engines args / env / preopened dirs / clock / random / fd I/O with an enforced rights model, on the interpreter, the JIT and AOT. Measured against the official WebAssembly/wasi-testsuite preview1 corpus by a lane that blocks ci-required; adapters/zwasm.py is upstream, so a clean checkout of the suite re-derives the result against a stock binary
WASI 0.2 (preview2, Component Model) ✅ functional, default-ON real wasm32-wasip2 Rust / TinyGo components run end-to-end (fs, sockets incl. TCP listeners and the wasi:http client behind --allow-network, guest-defined resources); typed embedder API (introspection + invokeTyped); the Component Model spec corpus (incl. the official assert_invalid cases) is green in test-all; gated by -Dwasi>=p2 (the default is p3), -Dwasi=p1 opts out
WASI 0.3 (preview3, native async) ✅ 0.3.0 full coverage, default-ON (-Dwasi=p2 opts out) all six WASI 0.3 proposals (0.3.0 released 2026-06-11; 0.3.1 and 0.3.2 change only the version strings, and zwasm accepts the Component Model map type and implements annotation a 0.3.1+ runtime must) — cli / clocks / random / filesystem / sockets / http — on the Component Model's native async (stream<T> / future<T>, waitable-sets; async-lifted exports in the callback form, a stackful async lift is declined). Sockets (TCP and UDP) and http (client and the exported handler) are served end-to-end; zwasm serve answers HTTP/1.1 with a wasi:http/service component, one request at a time. Official wasm32-wasip3 corpus: all 55 tests vendored, 55/55 green on all three supported OSes (@unstable interfaces excluded, as upstream gates them); the lane reconciles that count against the vendored corpus

All three execution paths do full WASI I/O — the interpreter, the JIT (--engine jit), and AOT (.cwasm). The JIT additionally executes SIMD-128 (the interpreter does not).

Execution backends

Backend Status
Interpreter (full WASI) ✅ functional
JIT — ARM64 (AAPCS64) ✅ functional
JIT — x86_64 SysV (Linux/macOS) ✅ functional
JIT — x86_64 Win64 (MSVC ABI) ✅ functional
AOT — .cwasm compile + load + run ✅ functional

The GC-on-JIT path is memory-safe: a conservative native-stack-scan collector roots live references across collections, verified by an adversarial use-after-free test on aarch64 + x86_64.

CLI

zwasm                                  # print version + build options
zwasm run [options] <file.wasm|.cwasm> [args...] # run a module (WASI _start / main)
    [--invoke <name>[=a,b,…]]          #   run a named export; =args prints typed results
    [--engine <interp|jit>]            #   default: auto (prefers JIT, interp fallback); interp|jit force one (both full WASI; jit adds SIMD, interp refuses a SIMD module at instantiate)
    [--dir <host>[:<guest>]]           #   preopen a host directory for WASI
    [--env <KEY=VAL>]                  #   set a WASI env var (repeatable)
    [--fuel <N>]                       #   trap after a deterministic budget (error.OutOfFuel)
    [--timeout <ms>]                   #   interrupt after a wall-clock deadline
    [--max-memory <bytes>]             #   refuse memory.grow past this many bytes
    [--max-table-elements <N>]         #   refuse table growth past this many elements
    [--cache[=DIR]]                    #   transparent compilation cache (content-keyed .cwasm reuse; a cache defect degrades, never fails the run)
    [--cache-clear]                    #   delete this build's cache subdirectory (clear-only; combine with --cache to repopulate)
zwasm compile <file.wasm> -o <out.cwasm>  # compile to a .cwasm AOT artifact
zwasm --version | -V                   # version + build identity (wasm/wasi/engine/mode)
zwasm --help | -h | help

The CLI is deliberately run + compile — the wasmtime/wazero-aligned shape for a runtime. Validation is programmatic (C-API wasm_module_validate / Zig Engine.compile); wat↔wasm conversion and module introspection are wasm-tools / wabt's job. Full flag table + exit codes: docs/reference/cli.md.

Runtime env vars: ZWASM_DEBUG=<categories> (dbg category filter), ZWASM_DIAG=<channels> (diagnostic trace ringbuffer drain).

Embedding

zwasm is a library first, with two host surfaces.

Zig (native facade) — add zwasm as a build.zig.zon dependency, pull its module (b.dependency("zwasm", .{}).module("zwasm")), then:

const zwasm = @import("zwasm");

var eng = try zwasm.Engine.init(alloc, .{});
defer eng.deinit();
var mod = try eng.compile(&wasm_bytes);
defer mod.deinit();
var inst = try mod.instantiate(.{});
defer inst.deinit();

const add = inst.typedFunc(fn (i32, i32) i32, "add");
const r = try add.call(.{ 2, 40 }); // 42

Surface: Engine / Module / Instance / Linker (host imports via defineFunc + Caller) / Memory / Global / Table / TypedFunc / Trap / Value. Runnable: docs/examples/zig_dep/ (external path-dep consumer) and docs/examples/zig_host/.

Sandboxing untrusted guests (both engines): mod.instantiate(.{}) is bounded by default — InstantiateOpts.fuel and .max_memory_pages carry finite defaults (a deterministic instruction budget → error.OutOfFuel, and a linear-memory cap), so a forgotten budget still yields a metered instance; set an axis to .unmetered (e.g. .{ .fuel = .unmetered }) for trusted code. Instance.interrupt() stops a runaway guest from another thread (timeout or cancellation → error.Interrupted); setFuel/setMemoryPagesLimit/setTableElementsLimit adjust the budgets on a live instance. The JIT engine carries the same triad: polls at every loop back-edge and at function entry (on x86_64 only in a function that uses the runtime) deliver interruption and fuel (units there = those crossings), and memory.grow honours the host cap. From C, use the zwasm_instance_* setters in include/zwasm.h; from the CLI, --fuel / --timeout / --max-memory (both engines).

C (wasm-c-api) — include/wasm.h is byte-identical to the upstream standard (the interface wasmtime/wasmer follow); WASI host-setup is the hand-authored include/wasi.h. See docs/examples/c_host/ and docs/reference/c_api.md.

Any FFI language — docs/examples/rust_host/ (zig build run-rust-host) declares the same wasm.h ABI from Rust and links libzwasm, demonstrating the C surface is consumable from any FFI-capable language, not just C.

Build flags

-Dwasm=v3_0|v2_0|v1_0       # default v3_0; lower levels omit later proposals
-Dwasi=none|p1|p2|p3        # default p3; ordered tier. p2 = Component Model / WASI-P2 host,
                            #   p3 = + Preview-3 async. -Dwasi=p1 = lean build (~-8%)
-Dengine=both|jit|interp    # default both
-Dstrip=true|false          # default false

Ecosystem

Repository What it is
zwasm-rust-sdk Safe Rust bindings (zwasm-sdk / zwasm-sys on crates.io)
containerd-shim-zwasm containerd shim — run Wasm workloads on containerd
homebrew-tap Homebrew formulae

The org profile at github.com/zwasm tracks the same list.

Building from source

zig build              # compile the zwasm binary
zig build test         # unit tests
zig build test-all     # all enabled test layers

# Embedding from C or Rust: libzwasm.a + the three public headers into zig-out/
zig build static-lib -Doptimize=ReleaseSafe -Dcompiler-rt=true

# Cross-compile sanity check (catches, e.g., Win64 compile errors in ~3s)
zig build -Dtarget=x86_64-windows-gnu

The link line that goes with static-lib, and what each of its flags is for, is in docs/tutorial.md §5.

You need Zig 0.17.1 and wasm-tools (pinned in .github/versions.lock; the build generates test/spec/spectest.wasm with it). Multi-OS verification is handled automatically by CI on every pull request. The full development story (test layers, optional tools, git hooks, what's maintainer-only) is in docs/development.md; the contribution flow is in .github/CONTRIBUTING.md.

Nix is optional: nix develop (or direnv) loads the pinned Zig 0.17.1 and tool surface (flake.nix: hyperfine, wasm-tools, wasmtime, yq-go, lldb, nasm).

Community & contributing

Layout

src/         Zig sources (parse/ validate/ ir/ runtime/ instruction/ feature/
             engine/ interp/ wasi/ api/ cli/ diagnostic/ support/ platform/)
include/     Public C headers (wasm.h / wasi.h / zwasm.h)
build.zig    Build script
flake.nix    Nix dev shell pinned to Zig 0.17.1
docs/        Tutorial + API reference + benchmarks
.dev/        ROADMAP + handover + ADRs + lessons + setup notes
.claude/     Claude Code settings, skills, rules (auto-loaded)
scripts/     pre-commit gate + integrity checks + bench tooling
test/        per-layer suites; unified `zig build test-all`
bench/       benchmark history (append-only)
tools/lint/  the `zig build lint` sub-build (the only thing with a dep)

Documentation

References

License

Copyright 2026 zwasm Contributors. Licensed under Apache-2.0 — see LICENSE.

探索相关项目

加载中…