Skip to content

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.

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
Terminal window
cargo install witforge-cli --version 0.12.0 --locked
witforge --version

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):

Terminal window
VERSION=0.12.0
# Ephemeral pinned invocation with uvx:
uvx "witforge==${VERSION}" --version
uvx "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.

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):

Terminal window
VERSION=0.12.0
# Ephemeral pinned invocation with npx:
npx --yes "@witforge/cli@${VERSION}" --version
npx --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.

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):

Terminal window
VERSION=0.12.0
# Homebrew tap (once zeropier/homebrew-tap is populated from a release's Formula/witforge.rb):
brew install zeropier/tap/witforge
witforge --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.Tools is a developmentDependency NuGet package (PrivateAssets="all", zero lib/ assemblies, zero buildTransitive/ targets) bundling the five native release binaries under tools/<rid>/ (static musl on Linux). Its MSBuild targets run with BeforeTargets="Protobuf_BeforeCompile;Protobuf_Compile;BeforeCompile" so witforge executes strictly ahead of Grpc.Tools and C# compilation. See MSBuild integration for .NET.
  • JVM / Gradle and Maven (packaging/jvm/): classifier-addressed org.witforge:witforge-native:<version>:<classifier>@exe artifacts follow the standard osdetector / os-maven-plugin scheme (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 of protoc and Java compilation. See Gradle and Maven integration for JVM.

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:

Terminal window
VERSION=0.12.0
TARGET=x86_64-unknown-linux-musl
BASE="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.yml
tar -xzf "witforge-${VERSION}-${TARGET}.tar.gz"
./witforge --version

For 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.

Two layouts are possible:

  1. Commit witforge output under src/generated/ (recommended): witforge generate writes plain Rust, .proto, JSON Schema, and glue into committed directories, and build.rs only compiles the committed .proto files with prost-build (0.14) and protox (0.10, so no system protoc binary is required). CI runs witforge generate --check to catch drift, code review shows exact API changes in pull requests, and downstream crates build with plain cargo without installing witforge.
  2. Generate during build.rs: invokes witforge into OUT_DIR. This avoids committing generated files, but witforge --check cannot guard committed per-version modules in CI and every contributor needs the matching witforge binary during cargo 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).

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/
Terminal window
mkdir -p my-contract-crate/wit/v0.1 my-contract-crate/src

Save 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:

Terminal window
witforge lock my-contract-crate/wit/v0.1 --first
witforge check my-contract-crate/wit
witforge generate --config my-contract-crate/witforge.toml
witforge generate --config my-contract-crate/witforge.toml --check

Save 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):

Terminal window
cargo run --manifest-path my-contract-crate/Cargo.toml

Module roots, dependencies, rustfmt, and lints

Section titled “Module roots, dependencies, rustfmt, and lints”
  • Module path forms: --plain-root / plain-root and --proto-root / proto-root must 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 exit 2.
  • Contracts with deps/: When a contract uses standard deps/ packages, witforge proto emits <namespace>.<pkg>.v<major>.proto files alongside v<major>.proto. Pass all .proto files in src/generated/proto/ to protox::compile(...), set prost_build::Config::new().include_file("prost_include.rs"), and include concat!(env!("OUT_DIR"), "/prost_include.rs") inside pub 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-default rustfmt.toml, add #[rustfmt::skip] on the pub mod plain; and pub mod glue; declarations.
  • #![no_std] + alloc crates: Set no-std = true under [project.<name>.rust] and [project.<name>.glue] (or pass --no-std on rust, glue, or generate). 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::Error with no ::std:: references. In your crate, declare #![no_std] and extern crate alloc;, and depend on prost with default-features = false, features = ["derive"] (and serde with default-features = false, features = ["alloc", "derive"] if serde = true). When a #![no_std] contract uses map<K, V>, configure prost_build::Config::btree_map(["."]) in build.rs (or via witforge_build::Config::with_prost_config) so prost emits BTreeMap instead of std::collections::HashMap.
  • Additional opt-in Rust derives and adapters: Set eq-hash = true (--eq-hash) to derive Eq and Hash on float-free generated types, and try-from = true (--try-from) to emit TryFrom implementations in convert.rs for converted nominal types. See Generation for the full witforge.toml layout.

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"
build.rs
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> (on check and lock for a single version directory): overrides the lockfile path instead of the default <WIT_DIR>/wire.lock. witforge lock still refuses any --lock path located inside a released directory.
  • --released <PATH> (on check, 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, and freeze): overrides the released-version manifest path. The defaults are:
    • <WIT_DIR>/../released for single-version commands (check <dir>, lock <dir>, release <dir>, retire <dir>);
    • <WIT_ROOT>/released for whole-root check, new-version, deps sync, inspect (refused on single version directories), generators, and freeze. A missing default manifest means no versions are released; an explicitly passed missing manifest exits 2. For lock, an explicit --released manifest is checked in addition to the default manifests (never instead of them), so an explicit manifest cannot unlock a released directory.
  • released = "..." in witforge.toml: sets the project’s released-version manifest path relative to witforge.toml (overridden by CLI --released).
  • Version retirement (<name> retired): marking a contiguous oldest prefix of released versions as retired in 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.