Quickstart
witforge turns one hand-written WIT package into the artifacts the two sides of a contract need:
- plain Rust types and interface traits (with opt-in Serde,
no_std,Eq/Hash, andTryFrom); - zero-dependency plain types, interfaces, and version adapters for TypeScript, Python, Go, Java 21, and C# 12;
- a protobuf schema with append-only field numbers and opt-in Go/Java/C# file options;
- JSON Schema definitions (Draft 7 default, opt-in Draft 2020-12);
- checked protobuf conversion glue across Rust, TypeScript, Python, Go, Java, and C#;
- deterministic Markdown contract reference documentation (
witforge doc), conformance fixtures (witforge conformance), and opt-in third-party plugins (witforge plugin).
It is not a runtime, transport, or WASM guest-binding generator. Consumers in Rust, TypeScript,
Python, Go, Java, and C# can use the generated plain types, adapters, and checked protobuf glue
directly, while other languages use the emitted .proto with their normal protobuf toolchain.
Install
Section titled “Install”Install the current release:
cargo install witforge-cli --version 0.12.0 --lockedwitforge --versionNon-Rust teams do not need a Rust toolchain to run witforge:
| Ecosystem | Invocation / Package | Details |
|---|---|---|
Python (uvx, pipx, pip) |
uvx witforge==<version> generate --config witforge.toml --only proto,py,py-glue --check (workflow-packaged; published once PyPI OIDC is enabled) |
PyPI install |
TypeScript / Node (npx, npm) |
npx --yes @witforge/cli@<version> generate --config witforge.toml --only proto,ts,ts-glue --check (workflow-packaged; published once npm OIDC is enabled) |
npm install |
macOS / Linux / Go (brew, mise) |
brew install zeropier/tap/witforge or mise use aqua:zeropier/witforge@<version> (workflow-staged tap / local aqua registry) |
Homebrew, aqua, and mise |
| .NET 8+ / JVM 21+ | Witforge.Tools (PrivateAssets="all") and witforge-native @exe (workflow artifact / local feed) |
.NET and JVM wrappers |
| GitHub Actions | uses: zeropier/witforge@v0.12.0 |
CI guide |
Prebuilt archives (with .sha256 checksums, LICENSE-APACHE, LICENSE-MIT, README.md, and
from 0.7.0 SLSA build provenance attestations) are published on GitHub Releases for Linux x86_64
and Linux arm64 (static musl from 0.8.0 alongside gnu), macOS Intel and Apple silicon, and
Windows x86_64; cargo binstall witforge-cli is also configured. Windows arm64 builds are not
provided; use cargo install witforge-cli --locked on that platform (or see the
wiring and installation guide for manual download and verification commands).
From this repository, before or after publication:
cargo run -p witforge-cli -- --versionThe examples below use witforge; replace it with cargo run -p witforge-cli -- when working
from a checkout. Every command on this page runs from one working directory, the one that
contains my-contract/, and the test suite runs them in this order.
One version
Section titled “One version”To scaffold a starter project (wit/v0.1/contract.wit, initial wire.lock, and witforge.toml)
in one step without overwriting existing files, run witforge init my-contract --package example:hello
(add --serde to enable Serde derives). The manual steps below walk through each file explicitly.
Create a root with a version directory:
my-contract/ wit/ v0.1/ contract.witmkdir -p my-contract/wit/v0.1Save a small contract as my-contract/wit/v0.1/contract.wit. The package version must match the
directory name, and an interface and a world cannot share a name:
package example:hello@0.1.0;
interface greeter { record greeting { text: string, }
greet: func(name: string) -> greeting;}
world hello { export greeter;}At this point, contract.wit is the only file in v0.1. Do not create wire.lock by hand.
Create the lockfile, assign wire numbers, and validate the contract:
witforge lock my-contract/wit/v0.1 --firstwitforge check my-contract/wit/v0.1witforge lock --first creates my-contract/wit/v0.1/wire.lock. Commit contract.wit and the
generated wire.lock together. The lockfile is append-only: generated protobuf field numbers and
method ids must never change.
Generate each projection:
witforge rust my-contract/wit --out my-contract/generated/rustwitforge proto my-contract/wit --out my-contract/generated/protowitforge schema my-contract/wit --out my-contract/generated/schemawitforge glue my-contract/wit --out my-contract/generated/glue \ --plain-root crate::generated::rust --proto-root crate::generated::proto--plain-root and --proto-root are Rust module paths, not output directories. The glue emitter
uses them to reference the plain types and the prost types generated from the .proto schema.
Every generator supports --check, which writes nothing and fails if committed output differs:
witforge rust my-contract/wit --out my-contract/generated/rust --checkwitforge proto my-contract/wit --out my-contract/generated/proto --checkwitforge schema my-contract/wit --out my-contract/generated/schema --checkwitforge glue my-contract/wit --out my-contract/generated/glue \ --plain-root crate::generated::rust --proto-root crate::generated::proto --checkUse witforge.toml
Section titled “Use witforge.toml”Put the repeated paths in a project file, my-contract/witforge.toml:
version = 1
[project.hello]root = "wit"
[project.hello.rust]out = "generated/rust"# serde = true # opt in to Serialize/Deserialize derives
[project.hello.proto]out = "generated/proto"
[project.hello.schema]out = "generated/schema"
[project.hello.glue]out = "generated/glue"plain-root = "crate::generated::rust"proto-root = "crate::generated::proto"Then run every configured generator in one command (or invoke rust, proto, schema, and glue individually):
witforge generate --config my-contract/witforge.tomlwitforge generate --config my-contract/witforge.toml --checkInside my-contract/ (or any subdirectory below it within the repository), witforge.toml is discovered automatically without passing --config (pass --no-config to disable discovery). If the file has more than one project, generate runs all of them unless --project NAME selects one. Paths inside the file are relative to the file itself. Explicit CLI paths override configured paths, and the command-line-only form continues to work. --serde or --no-serde overrides the Rust section’s serde setting; the generated code then requires the consumer’s serde crate with derive.
Evolve a contract
Section titled “Evolve a contract”A contract change is a new version directory, never an edit to a released one. Keep every released version in the tree:
my-contract/wit/ released # lists v0.1 v0.1/ contract.wit wire.lock v0.2/ contract.wit wire.lockWhen v0.1 ships, validate and record it as released in my-contract/wit/released:
witforge release my-contract/wit/v0.1Start the next minor from the latest version. new-version copies every .wit file, deps/, and
wire.lock, and updates the package version header to 0.2.0 (add --major for a new major
with no copied lockfile; the manual equivalent is mkdir, cp of the .wit files and wire.lock,
and bumping the package header yourself):
witforge new-version my-contract/witEdit my-contract/wit/v0.2/contract.wit to add the new members (using defaultable types when
possible so generated adapters can convert old values):
package example:hello@0.2.0;
interface greeter { record greeting { text: string, language: option<string>, // old values become None tags: list<string>, // old values become an empty list }
greet: func(name: string) -> greeting;}
world hello { export greeter;}Assign numbers to the new members, then validate the whole WIT root (which checks released directories in default mode and every draft against its predecessor):
witforge lock my-contract/wit/v0.2 --against my-contract/wit/v0.1/wire.lockwitforge check my-contract/witRegenerate everything. With two versions in the root, rust also writes convert.rs:
witforge generate --config my-contract/witforge.tomlwitforge generate --config my-contract/witforge.toml --checkconvert.rs holds old-to-new and new-to-old adapters. Old-to-new conversion fills an added
option with None, an added list with an empty list, and an added map with an empty
BTreeMap. New-to-old conversion drops members
the older version does not have. Missing required older members are reported as
ConversionError::MissingMember; added or removed cases are reported as
ConversionError::UnknownCase. A required, non-defaultable addition is refused by conversion
generation.
Do not edit a released version’s WIT, lockfile, or generated per-version modules. witforge lock refuses
a released directory, check and the generators fail when a released WIT file no longer matches
its lockfile, and witforge freeze verifies in Git history (with fetch-depth: 0) that no
released directory was modified or dropped from wit/released.
Review a change
Section titled “Review a change”Compare a draft with the previous version before merging it:
witforge diff my-contract/wit/v0.1 my-contract/wit/v0.2witforge diff my-contract/wit/v0.1 my-contract/wit/v0.2 --jsonwitforge diff my-contract/wit/v0.1 my-contract/wit/v0.2 --check # exits 1: see below--check fails on wire-, source-, or generated-API-breaking changes (or the view set configured in
[project.<name>.policy].diff-check). It exits 1 for the change
above: the two added fields keep every wire number and convert from old values, but Rust code
that constructs a Greeting has to be updated, so diff reports them as source- and
API-breaking. To compare your working tree directly against a Git commit or branch without
checking out a second tree, pass --git-base <rev>. --json is the complete diff report, and
witforge inspect --json exports the versioned JSON contract IR for tooling. diff also reports a
note when a shared record type’s generated new-to-old converter
is guaranteed to fail because the older version requires a member the newer version removed; the
notes do not change the change counts or --check result. To make any command’s diagnostics
machine-readable, add --format json or --format sarif; the catalogue is in the
diagnostic codes guide.
For Markdown contract reference pages (index.md and one v<major>_<minor>.md per live version),
run witforge doc (or configure [project.<name>.doc]). For CI,
zeropier/witforge publishes an Action that
installs the matching release and can run the same checks; see the CI guide and
the Action specification.
Non-Rust consumers
Section titled “Non-Rust consumers”witforge includes built-in plain-type, cross-version adapter, and checked protobuf glue emitters for five non-Rust ecosystems:
- TypeScript (
witforge tsandwitforge ts-gluefor@bufbuild/protobuf); - Python 3.11+ (
witforge pyandwitforge py-glueforgoogle.protobuf); - Go 1.22+ (
witforge goandwitforge go-glueforgoogle.golang.org/protobuf); - Java 21+ (
witforge javaandwitforge java-glueforcom.google.protobuf); - C# 12+ / .NET 8+ (
witforge csharpandwitforge csharp-glueforGoogle.Protobuf).
Built-in *-glue emitters enforce every WIT decode and encode rule automatically, and
witforge conformance exports deterministic test vectors (vectors.json, proto/, wit/) that
prove cross-language parity. Other ecosystems (such as C++, Kotlin, or Swift) can use the emitted
.proto files with their standard protobuf generator alongside the documented decode profile, or
generate custom projections with witforge plugin <name>. The
Non-Rust implementation guide specifies the complete profile and lists every
built-in emitter.
witforge intentionally does not duplicate wit-bindgen’s runtime WIT bindings or own transport
framing. The generated types, glue, stable protobuf numbers, and JSON Schema are cross-language
contract artifacts, not a complete application protocol.
Supported WIT subset
Section titled “Supported WIT subset”The current subset is deliberately pure and synchronous:
- package versions are
<major>.<minor>.0; - types and functions live in named interfaces;
- records, variants, enums, flags, aliases,
usealiases,char, lists, fixed-length lists (list<T, N>,1 <= N <= 65536), maps (map<K, V>withbool, integer,char, orstringkeys), options, and results are supported; - resources, async, futures, streams, tuples, unsupported map key types, out-of-range fixed-length lists, multi-package workspaces, and world-defined types are currently refused.
- named types and interfaces from packages under a version directory’s standard
deps/layout are supported as package-qualified references; worlds may import and export dependency interfaces, and glue covers dependency types and functions. See the dependency specification.
Run witforge check for the exact diagnostic. The
design overview has the
full contract model and the reasons for each refusal.
Dependencies and Serde
Section titled “Dependencies and Serde”A version directory may use standard deps/ packages. Put the dependency under
wit/v0.1/deps/, declare its package, and import its types or interfaces normally:
package example:app@0.1.0;
interface api { use example:shared/types@0.1.0.{item}; get: func() -> item;}
world plugin { import example:shared/types@0.1.0;}witforge rust, proto, schema, glue, and all ten built-in polyglot emitters generate
dependency bindings alongside the local output (witforge doc lists the pinned dependencies on
each version page), and witforge deps sync keeps vendored deps/ trees synchronized across
unreleased versions within a major. See the
dependency specification
for the generated files and dependency glue layout.
Serde and other Rust profile options (no-std, eq-hash, try-from) are opt-in per project:
[project.demo.rust]out = "generated/rust"serde = trueThe default generated output has no external crate dependencies; enabling Serde requires the
consumer’s serde crate with the derive feature. CLI flags (--serde/--no-serde,
--no-std/--std, --eq-hash/--no-eq-hash, --try-from/--no-try-from) override the
configuration.
JSON projections
Section titled “JSON projections”Plain Rust Serde, JSON Schema (Draft 7 default, opt-in Draft 2020-12), and proto3-JSON project the same WIT values differently:
- generated Rust Serde uses Rust identifiers, so
start-bytebecomesstart_byte; - JSON Schema preserves the WIT name
start-byte, requires every record property, and permitsnullforoption<T>; - proto3-JSON uses lowerCamelCase (
startByte), decimal strings for 64-bit integers, and normally omits an absent optional value; - none of the projections supplies application defaults such as “missing severity means warning.”
Choose one authoritative JSON profile. Keep an explicit application adapter when an existing protocol differs, and do not validate one projection with another projection’s schema. See JSON projections for the full comparison.
Examples
Section titled “Examples”examples/single: one version, Rust, protobuf, JSON Schema, and glue generators, config-driven.examples/evolved: released v0.1 plus draft v0.2, lock continuity, and generated conversions.examples/polyglot: released v0.1 plus draft v0.2 with Go/Java/C# protobuf options and all ten TypeScript, Python, Go, Java 21, and C# 12 plain, adapter, and checked-glue outputs.examples/plugin-starters: zero-dependencyprotocol_version = 1emitter plugin starter kits in Rust, TypeScript, and Python.
Troubleshooting
Section titled “Troubleshooting”wire.lockmissing: for the first version usewitforge lock <dir> --first; for a new minor copy the previous lockfile and use--against.- stale lockfile: run
witforge lock, review the printedadded,reserved,updated, anddroppedentries, and commit the result. - released version changed: restore the released WIT and lockfile; create a new version directory for the change.
- glue root path errors: for Rust
witforge glue, pass absolute Rust module roots (crate::...), not filesystem paths; for polyglot glue emitters, pass the language-specific import, module, package, or namespace roots documented in the CLI and configuration reference. - generated output drift: run the generator without
--check, review the diff, and commit the result.