witforge
A WIT-first contract compiler. Write a contract once, as a WIT package, and generate the bindings the other sides of the contract need:
- plain Rust types and traits (no wasmtime or component-runtime dependency), for native implementations and for hosts;
- a protobuf schema with stable field numbers, for out-of-process implementations in any language;
- Draft 7 JSON Schema definitions for value validation;
- generated old-to-new and new-to-old adapters between contract versions.
WIT is the strictest of these type systems (the component model treats a published record, variant, enum, or flags type as frozen), so projecting it onto Rust and protobuf loses nothing, while the reverse directions are lossy. witforge exists because no tool performs that projection: the ecosystem's converters go from protobuf to WIT, and the WIT bindings generators tie their output to a runtime.
Status: 0.4.1. The loading, subset-checker, internal-model, v2 append-only lockfile, Rust, protobuf, JSON Schema, glue, and version-conversion emitters are implemented, alongside
witforge diff, structured--format json|sarifdiagnostics,witforge.tomlprojects, and the GitHub Action/prebuilt release archives. CI runs on Linux, macOS, and Windows and gates generated-output drift, release freezes, dependency and security policy, and the aplan contract. witforge's first consumer is the alint plugin contract.
Install
This installs the witforge command; the witforge crate is the library behind it. Both need
Rust 1.88 or later.
Starting with 0.3.0, each release also attaches prebuilt archives for Linux x86_64, macOS
Intel and Apple silicon, and Windows x86_64, each with a .sha256 checksum. See
docs/design/action.md for the archive names and
verification commands.
GitHub Action
The action installs the release matching its tag by default, then runs check, diff, and
configured generators with --check:
- uses: asamarts/witforge@v0.4.1 # pinned: installs witforge 0.4.1
with:
check: wit/v0.2
diff-old: wit/v0.1
diff-new: wit/v0.2
config: witforge.toml
generators: rust,proto
@main is a floating ref: it installs the latest published release. Pass version to override
either default, and github-token: ${{ github.token }} when querying latest to avoid anonymous
API rate limits. The full input and checksum behavior is in
docs/design/action.md.
Security
Report suspected vulnerabilities privately through
GitHub private vulnerability reporting,
not a public issue. See SECURITY.md for the supported-version and dependency
policy.
Plan
Task-level planning, dependencies, and closure evidence live in aplan/
and are validated with aplan check and aplan verify; CI runs those gates with the pinned
published aplan 0.5.2 release. ROADMAP.md is the narrative sequence; the plan is the
task-level source of truth.
How it works
See docs/quickstart.md for an install-to-generated-code walkthrough and examples/ for runnable single-version and evolved contracts.
wit/ hand-written contracts (the source of truth)
released released version directories
v0.1/
*.wit
wire.lock append-only protobuf numbers, committed
v0.2/
*.wit
wire.lock
$ witforge lock wit/v0.1 --first number the first version
$ cp wit/v0.1/wire.lock wit/v0.2/wire.lock start a new minor from the last lock
$ witforge lock wit/v0.2 --against wit/v0.1/wire.lock number its new members
$ witforge check wit/v0.2 --against wit/v0.1/wire.lock subset + continuity (CI)
$ witforge diff wit/v0.1 wit/v0.2 --check review breaking changes (CI)
$ witforge rust wit --out src/plain plain modules + metadata
$ witforge proto wit --out proto protobuf schema
$ witforge schema wit --out schema Draft 7 JSON Schema
$ witforge glue wit --out src/glue --plain-root crate::plain --proto-root crate::pb
--format json|sarif turns diagnostics from the commands into stable machine-readable output;
diff --json is the full diff report. The formats and code catalogue are in
docs/design/diagnostics.md.
A witforge.toml project can replace the repeated roots and output paths:
= 1
[]
= "wit"
[]
= "src/plain"
[]
= "proto"
Use witforge rust --config witforge.toml; --project NAME selects a project when the file has
more than one. CLI paths override the configuration, and the command-line-only form above remains
valid.
rust also writes worlds.rs when a contract has worlds, exposing each world's imported and
exported interface names, and convert.rs when the WIT root has more than one version: one
module per adjacent version pair in each direction. Old-to-new conversions default defaultable additions;
new-to-old conversions report a removed required member as ConversionError::MissingMember;
added or removed variant and enum cases report UnknownCase; retyped or kind-changed types are
refused rather than converted silently.
--proto-root names the Rust module that holds the prost types generated from the emitted
schema (for example by prost-build in a build script), not the directory the schema is
written to. Every generated file starts with witforge's header, and --check on any generator
fails instead of writing when its output would change. Give each generator its own output
root: generation replaces and removes only files that carry the header, and refuses to replace a
symlink, a directory, or a file without the header at an expected path.
The generators also refuse a minor whose wire.lock does not keep every entry of the previous
minor's, so a lockfile started fresh instead of copied cannot renumber the shared per-major
schema. For a version not yet released, check accepts the lockfile only as lock writes it
(CRLF line endings read as LF); pin wire.lock and *.wit to LF in .gitattributes
(wire.lock text eol=lf, *.wit text eol=lf). No command follows a version directory that is
a symlink, so a released version cannot change through a link's target.
Every command exits 1 for a contract, lockfile, or output violation: a subset violation, a
version directory holding another package version, a stale or discontinuous lockfile, a
generated-name collision, or --check drift, which includes an expected path that generation
would refuse; check also exits 1 for an unreleased version's lockfile that is not in the
form lock writes. It exits 2 for a usage, I/O, or parse error, a released or symlinked
version directory, an output root inside the WIT root, a generation run refused by an expected
path, or an internal error.
- The subset. Contracts stay inside a pure, synchronous, self-contained subset of WIT: no
resources or handles, no
future,stream, orerror-context, nomap, no fixed-length lists, nochar, no tuples, noasyncfunctions orget/setaccessors, nothing from another package, and package versions are<major>.<minor>.0. Types and functions live in the package's named interfaces, which worlds import and export. Anything unrecognised is refused, never passed through. - The lockfile. WIT members carry no field numbers, so
wire.lockmaps every record field, variant case, enum case, flag, function method id, and function parameter to a number that never changes. New members get the next free number in their parent; removed members stay, markedreserved, and their names cannot come back; nothing is renumbered or deleted, and the package version is not part of the key, so version bumps never renumber anything. Entries also record their kind and canonical type, so a type or kind change is caught even when protobuf would not see it. An additive order section fingerprints each type's and function's live declaration order;--againstcatches reorders of common members without treating additions or removals as reorders.
The design is in docs/design/overview.md; the 1.0 API policy is in docs/design/public-api.md and the release criteria and deprecation runways are in docs/design/release-1.0.md.
License
Licensed under either of Apache License, Version 2.0 or MIT license, at your option.