Wiring and installation
This guide takes an empty Rust crate to a compiling plain-Rust and protobuf round trip, explains how
to install and verify prebuilt binaries, and covers the --lock, --released, and released
configuration options.
Install and verify
Section titled “Install and verify”Choose the channel that matches your team’s toolchain; every channel runs the same single native
witforge Rust binary with zero runtime dependencies added to generated plain types:
| Channel | Best for | Section |
|---|---|---|
crates.io (cargo install / cargo binstall) |
Rust crates and custom platforms | From crates.io |
PyPI (uvx, pipx, pip) |
Python 3.11+ repositories | From PyPI |
npm (npx, npm, pnpm) |
TypeScript / Node.js repositories | From npm |
Homebrew, aqua, and mise |
macOS, Linux, and Go //go:generate teams |
From Homebrew, aqua, and mise |
NuGet (Witforge.Tools) and Maven (witforge-native) |
.NET 8+ MSBuild and Java 21+ Gradle / Maven builds | From NuGet and Maven |
| Prebuilt GitHub Release archives | Air-gapped CI and manual SLSA verification | Prebuilt archives |
From crates.io
Section titled “From crates.io”cargo install witforge-cli --version 0.12.0 --lockedwitforge --versionFrom PyPI (uvx, pipx, pip)
Section titled “From PyPI (uvx, pipx, pip)”Python teams can run or pin the native witforge CLI wheel without installing Rust or Cargo
(packaged and smoked on every release tag via release.yml, and published on PyPI once PyPI
Trusted Publishing is enabled; Linux wheels bundle the static musl binary for both
manylinux_2_17 and musllinux_1_1, alongside native macOS Intel/Apple silicon and Windows x86_64
wheels):
VERSION=0.12.0
# Ephemeral pinned invocation with uvx:uvx "witforge==${VERSION}" --versionuvx "witforge==${VERSION}" generate --config witforge.toml --only proto,py,py-glue --check
# Persistent CLI install with uv or pipx:uv tool install "witforge==${VERSION}"pipx install "witforge==${VERSION}"
# Project virtualenv pin with pip:pip install "witforge==${VERSION}"The PyPI wheel contains zero Python runtime dependencies and executes no postinstall network
downloads. Plain Python code generated by witforge py also has zero runtime dependencies.
From npm (npx, npm, pnpm)
Section titled “From npm (npx, npm, pnpm)”TypeScript and Node.js teams can run or pin @witforge/cli without installing Rust or Cargo
(packaged and smoked on every release tag via release.yml, and published on npm once npm Trusted
Publishing is enabled; uses exact-pinned per-platform optionalDependencies with static Linux
musl binaries, zero postinstall scripts, and WITFORGE_BINARY_PATH offline override):
VERSION=0.12.0
# Ephemeral pinned invocation with npx:npx --yes "@witforge/cli@${VERSION}" --versionnpx --yes "@witforge/cli@${VERSION}" generate --config witforge.toml --only proto,ts,ts-glue --check
# Pinned devDependency in package.json:npm install --save-dev --save-exact "@witforge/cli@${VERSION}"npm exec witforge -- generate --config witforge.toml --only proto,ts,ts-glue --check@witforge/cli works cleanly under npm ci --ignore-scripts, pnpm, and behind corporate
proxies. Plain TypeScript code generated by witforge ts has zero runtime dependencies.
From Homebrew, aqua, and mise
Section titled “From Homebrew, aqua, and mise”macOS, Linux, and Go teams can install the verified static GitHub Release archives through
Homebrew (using the deterministic Formula/witforge.rb rendered by ci/render-homebrew-formula.sh
for zeropier/homebrew-tap) or through aqua and mise (packaging/aqua/registry.yaml,
verifying both .sha256 checksums and GitHub SLSA build provenance attestations):
VERSION=0.12.0
# Homebrew tap (once zeropier/homebrew-tap is populated from a release's Formula/witforge.rb):brew install zeropier/tap/witforgewitforge --version
# mise (using the aqua registry backend once merged upstream, or a local aqua registry):mise use "aqua:zeropier/witforge@${VERSION}"On Linux, both the Homebrew formula and packaging/aqua/registry.yaml select the static musl
archive (x86_64-unknown-linux-musl / aarch64-unknown-linux-musl), so Ubuntu LTS, Debian, RHEL,
and Alpine containers work without a glibc 2.39 floor (for mise on Linux distributions with
glibc < 2.39, set libc = "musl" or MISE_LIBC=musl so mise does not swap to the sibling
Ubuntu 24.04 -gnu archive). See
Go //go:generate with mise and aqua for a pinned Go
code-generation setup.
From NuGet (Witforge.Tools) and Maven (witforge-native)
Section titled “From NuGet (Witforge.Tools) and Maven (witforge-native)”.NET 8+ and Java 21+ repositories can integrate witforge directly into dotnet build, Gradle, or
Maven using thin build-tool wrappers staged in each tag release’s dotnet-jvm-packages workflow
artifact (ready for local or private enterprise NuGet/Maven feeds, with zero runtime dependencies):
- .NET / MSBuild (
packaging/dotnet/):Witforge.Toolsis adevelopmentDependencyNuGet package (PrivateAssets="all", zerolib/assemblies, zerobuildTransitive/targets) bundling the five native release binaries undertools/<rid>/(staticmuslon Linux). Its MSBuild targets run withBeforeTargets="Protobuf_BeforeCompile;Protobuf_Compile;BeforeCompile"sowitforgeexecutes strictly ahead ofGrpc.Toolsand C# compilation. See MSBuild integration for .NET. - JVM / Gradle and Maven (
packaging/jvm/): classifier-addressedorg.witforge:witforge-native:<version>:<classifier>@exeartifacts follow the standardosdetector/os-maven-pluginscheme (linux-x86_64,linux-aarch_64,osx-x86_64,osx-aarch_64,windows-x86_64) with SHA-256 verification before execution and explicit ordering ahead ofprotocand Java compilation. See Gradle and Maven integration for JVM.
Prebuilt archives
Section titled “Prebuilt archives”Prebuilt archives are published on GitHub Releases
for native targets (each archive contains the executable beside LICENSE-APACHE,
LICENSE-MIT, and README.md, plus a sibling .sha256 file and, from 0.7.0, a SLSA build
provenance attestation):
| Platform | Target | Notes |
|---|---|---|
| Linux x86_64 (static) | x86_64-unknown-linux-musl |
Portable across glibc/Alpine (from 0.8.0) |
| Linux x86_64 (gnu) | x86_64-unknown-linux-gnu |
glibc >= 2.39 (Ubuntu 24.04 runner) |
| Linux arm64 (static) | aarch64-unknown-linux-musl |
Portable across glibc/Alpine (from 0.8.0) |
| Linux arm64 (gnu) | aarch64-unknown-linux-gnu |
glibc >= 2.39, published from 0.7.0 |
| macOS Intel | x86_64-apple-darwin |
Native binary |
| macOS Apple silicon | aarch64-apple-darwin |
Native binary |
| Windows x86_64 | x86_64-pc-windows-msvc |
Native binary |
Windows arm64 builds are not provided; install from crates.io with cargo install witforge-cli --locked on that target. cargo binstall witforge-cli is also configured via
[package.metadata.binstall].
Download and verify a prebuilt archive before extracting it:
VERSION=0.12.0TARGET=x86_64-unknown-linux-muslBASE="https://github.com/zeropier/witforge/releases/download/v${VERSION}"curl -sSfLO "${BASE}/witforge-${VERSION}-${TARGET}.tar.gz"curl -sSfLO "${BASE}/witforge-${VERSION}-${TARGET}.tar.gz.sha256"sha256sum -c "witforge-${VERSION}-${TARGET}.tar.gz.sha256"# Releases 0.12.0 and later carry a GitHub build provenance attestation under zeropier/witforge:gh attestation verify "witforge-${VERSION}-${TARGET}.tar.gz" \ --repo zeropier/witforge \ --signer-workflow zeropier/witforge/.github/workflows/release.ymltar -xzf "witforge-${VERSION}-${TARGET}.tar.gz"./witforge --versionFor pre-transfer releases 0.7.0 through 0.11.0, pass --owner asamarts --signer-workflow asamarts/witforge/.github/workflows/release.yml to gh attestation verify because GitHub keeps pre-transfer attestations indexed under the original owner. On macOS, use shasum -a 256 -c if sha256sum is unavailable.
Layout: committed output vs. build.rs
Section titled “Layout: committed output vs. build.rs”Two layouts are possible:
- Commit witforge output under
src/generated/(recommended):witforge generatewrites plain Rust,.proto, JSON Schema, and glue into committed directories, andbuild.rsonly compiles the committed.protofiles withprost-build(0.14) andprotox(0.10, so no systemprotocbinary is required). CI runswitforge generate --checkto catch drift, code review shows exact API changes in pull requests, and downstream crates build with plaincargowithout installingwitforge. - Generate during
build.rs: invokeswitforgeintoOUT_DIR. This avoids committing generated files, butwitforge --checkcannot guard committed per-version modules in CI and every contributor needs the matchingwitforgebinary duringcargo build.
The walkthrough below uses the committed layout. Generated glue targets prost / prost-build
0.14 (and optionally pbjson / pbjson-build 0.9 for proto3 JSON).
Empty crate to compiling round trip
Section titled “Empty crate to compiling round trip”Create the crate layout:
my-contract-crate/ Cargo.toml build.rs witforge.toml wit/ v0.1/ contract.wit wire.lock src/ lib.rs main.rs generated/ rust/ proto/ schema/ glue/mkdir -p my-contract-crate/wit/v0.1 my-contract-crate/srcSave my-contract-crate/Cargo.toml:
[package]name = "my-contract-crate"version = "0.1.0"edition = "2024"
[dependencies]prost = "0.14"
[build-dependencies]prost-build = "0.14"protox = "0.10"Save my-contract-crate/wit/v0.1/contract.wit:
package example:greeter@0.1.0;
interface api { record greeting { text: string, repeat: option<u32>, }
greet: func(name: string) -> greeting;}
world hello { export api;}Save my-contract-crate/witforge.toml:
version = 1
[project.greeter]root = "wit"
[project.greeter.rust]out = "src/generated/rust"
[project.greeter.proto]out = "src/generated/proto"
[project.greeter.schema]out = "src/generated/schema"
[project.greeter.glue]out = "src/generated/glue"plain-root = "crate::plain"proto-root = "crate::proto"Lock the contract, validate it, and generate all four outputs:
witforge lock my-contract-crate/wit/v0.1 --firstwitforge check my-contract-crate/witwitforge generate --config my-contract-crate/witforge.tomlwitforge generate --config my-contract-crate/witforge.toml --checkSave my-contract-crate/build.rs, which compiles the committed .proto schema using protox
(pure Rust, no external protoc) and prost-build:
use std::path::PathBuf;
fn main() -> Result<(), Box<dyn std::error::Error>> { let proto_dir = PathBuf::from("src/generated/proto"); println!("cargo:rerun-if-changed={}", proto_dir.display()); let fds = protox::compile([proto_dir.join("v0.proto")], [&proto_dir])?; prost_build::Config::new().compile_fds(fds)?; Ok(())}Save my-contract-crate/src/lib.rs, exposing plain, proto, and glue at the exact module
paths configured by plain-root = "crate::plain" and proto-root = "crate::proto":
#![deny(missing_docs)]
//! Contract crate wiring witforge's generated plain Rust, prost protobuf types, and glue.
/// Generated plain Rust contract types, traits, and worlds.#[path = "generated/rust/mod.rs"]pub mod plain;
/// Prost-generated protobuf messages compiled by `build.rs`.pub mod proto { /// Wire schema for major version 0. #[allow(clippy::all, missing_docs)] pub mod v0 { include!(concat!(env!("OUT_DIR"), "/example.greeter.v0.rs")); }}
/// Generated plain-Rust <-> prost protobuf glue.#[path = "generated/glue/mod.rs"]pub mod glue;Save my-contract-crate/src/main.rs to round-trip a plain Rust value through generated glue and
protobuf binary encoding:
use my_contract_crate::{glue, plain, proto};use prost::Message as _;
fn main() { let original = plain::v0_1::api::Greeting { text: "hello".to_string(), repeat: Some(3), }; let wire = glue::v0::api::greeting::to_proto(&original); let encoded = wire.encode_to_vec(); let decoded_wire = proto::v0::ApiGreeting::decode(encoded.as_slice()).expect("decode proto"); let roundtripped = glue::v0::api::greeting::from_proto(decoded_wire).expect("glue from_proto"); assert_eq!(roundtripped, original);}Run cargo run inside my-contract-crate/ (the repository test suite builds and runs these exact
files verbatim):
cargo run --manifest-path my-contract-crate/Cargo.tomlModule roots, dependencies, rustfmt, and lints
Section titled “Module roots, dependencies, rustfmt, and lints”- Module path forms:
--plain-root/plain-rootand--proto-root/proto-rootmust be absolute Rust module paths:crate,crate::...,::crate_name::..., or an external crate name (other::...). Relative paths (self::...,super::...) and unprefixed generated module names (v0,witforge_deps, etc.) are refused with exit2. - Contracts with
deps/: When a contract uses standarddeps/packages,witforge protoemits<namespace>.<pkg>.v<major>.protofiles alongsidev<major>.proto. Pass all.protofiles insrc/generated/proto/toprotox::compile(...), setprost_build::Config::new().include_file("prost_include.rs"), and includeconcat!(env!("OUT_DIR"), "/prost_include.rs")insidepub mod proto { ... }so prost emits the package-nested module tree (crate::proto::<namespace>::<pkg>::v<major>) that glue expects. - Formatting and lints: Generated plain Rust and glue already match default
rustfmt(Editions 2021 and 2024), pass default Clippy (-D warnings), and document every public item (-D missing_docs) without needing attributes. If your crate uses a non-defaultrustfmt.toml, add#[rustfmt::skip]on thepub mod plain;andpub mod glue;declarations. #![no_std]+alloccrates: Setno-std = trueunder[project.<name>.rust]and[project.<name>.glue](or pass--no-stdonrust,glue, orgenerate). Generated Rust,convert.rs, and glue emit::alloc::string::String,::alloc::vec::Vec,::alloc::collections::BTreeMap,::core::option::Option,::core::result::Result, and::core::error::Errorwith no::std::references. In your crate, declare#![no_std]andextern crate alloc;, and depend onprostwithdefault-features = false, features = ["derive"](andserdewithdefault-features = false, features = ["alloc", "derive"]ifserde = true). When a#![no_std]contract usesmap<K, V>, configureprost_build::Config::btree_map(["."])inbuild.rs(or viawitforge_build::Config::with_prost_config) so prost emitsBTreeMapinstead ofstd::collections::HashMap.- Additional opt-in Rust derives and adapters: Set
eq-hash = true(--eq-hash) to deriveEqandHashon float-free generated types, andtry-from = true(--try-from) to emitTryFromimplementations inconvert.rsfor converted nominal types. See Generation for the fullwitforge.tomllayout.
Simplifying build.rs with witforge-build
Section titled “Simplifying build.rs with witforge-build”Instead of wiring protox, prost-build, and manual cargo:rerun-if-changed directives by hand,
you can use the optional witforge-build helper crate (first published on crates.io starting in
0.8.0) in [build-dependencies]:
[build-dependencies]witforge-build = "0.12.0"fn main() -> Result<(), Box<dyn std::error::Error>> { witforge_build::compile_protos("src/generated/proto")?; Ok(())}Then include the generated prost_include.rs in src/lib.rs:
#[allow(clippy::all, missing_docs)]pub mod proto { include!(concat!(env!("OUT_DIR"), "/prost_include.rs"));}witforge-build discovers every .proto file in deterministic order, emits per-file
cargo:rerun-if-changed directives, compiles with pure-Rust protox (no external protoc
needed), and generates a prost_include.rs layout matching witforge glue for both standalone
contracts (crate::proto::v0::*) and contracts with deps/
(crate::proto::<namespace>::<pkg>::v<major>::*). Enable features = ["pbjson"] and call
witforge_build::Config::new().pbjson(true).compile_protos("src/generated/proto")? to also emit
and include proto3-JSON serde implementations via pbjson-build.
Released-directory options (--lock, --released, and released)
Section titled “Released-directory options (--lock, --released, and released)”--lock <PATH>(oncheckandlockfor a single version directory): overrides the lockfile path instead of the default<WIT_DIR>/wire.lock.witforge lockstill refuses any--lockpath located inside a released directory.--released <PATH>(oncheck,lock,rust,proto,schema,glue,doc,ts,ts-glue,py,py-glue,go,go-glue,java,java-glue,csharp,csharp-glue,plugin,generate,new-version,deps sync,release,retire,inspect, andfreeze): overrides the released-version manifest path. The defaults are:<WIT_DIR>/../releasedfor single-version commands (check <dir>,lock <dir>,release <dir>,retire <dir>);<WIT_ROOT>/releasedfor whole-rootcheck,new-version,deps sync,inspect(refused on single version directories), generators, andfreeze. A missing default manifest means no versions are released; an explicitly passed missing manifest exits2. Forlock, an explicit--releasedmanifest is checked in addition to the default manifests (never instead of them), so an explicit manifest cannot unlock a released directory.
released = "..."inwitforge.toml: sets the project’s released-version manifest path relative towitforge.toml(overridden by CLI--released).- Version retirement (
<name> retired): marking a contiguous oldest prefix of released versions asretiredin the manifest keeps their directories frozen on disk while removing them from generated outputs on the next run. See Contract evolution for major-version and retirement rules, and CLI and configuration reference for every flag and key.