Skip to content

Configuring generation

Terminal window
witforge rust wit --out generated/rust
witforge proto wit --out generated/proto
witforge schema wit --out generated/schema
witforge glue wit --out generated/glue \
--plain-root crate::plain \
--proto-root crate::proto
witforge doc wit --out generated/doc

--plain-root and --proto-root on witforge glue are absolute Rust module paths used by generated glue (not filesystem paths). Accepted forms are crate, crate::..., ::crate_name::..., or an external crate name (other::...). Relative paths starting with self or super are refused because glue references the roots from nested modules at multiple depths; write crate::... for modules inside your own crate, and prefix an external crate with :: if its name matches a generated module. The same rules apply to plain-root and proto-root in [project.<name>.glue].

Ten additional built-in commands target TypeScript (ts, ts-glue), Python (py, py-glue), Go (go, go-glue), Java (java, java-glue), and C# (csharp, csharp-glue), each following the same --out, --check, and --diff conventions. Use witforge conformance --out <DIR> to export the deterministic cross-language protobuf conformance bundle, and witforge plugin <name> to run a third-party emitter plugin. See Non-Rust implementations and the CLI and configuration reference for every language flag and root syntax.

version = 1
[project.example]
root = "wit"
[project.example.rust]
out = "generated/rust"
serde = true
# no-std = true # opt-in `#![no_std]` + `alloc` paths (CLI: `--no-std` / `--std`)
# eq-hash = true # opt-in `Eq, Hash` on float-free types (CLI: `--eq-hash` / `--no-eq-hash`)
# try-from = true # opt-in `TryFrom` impls in `convert.rs` (CLI: `--try-from` / `--no-try-from`)
[project.example.proto]
out = "generated/proto"
# go-package = "github.com/acme/contracts/gen/go"
# java-package = "com.acme.contracts"
# java-multiple-files = true
# java-outer-classname = "ContractProto"
# csharp-namespace = "Acme.Contracts"
#
# [project.example.proto.packages."example.plugin.v0"]
# go-package = "github.com/acme/contracts/custom/v0;customv0"
[project.example.schema]
out = "generated/schema"
# draft = "2020-12" # Draft 7 default, opt-in Draft 2020-12 (CLI: `--draft 7|2020-12`)
[project.example.glue]
out = "generated/glue"
plain-root = "crate::plain"
proto-root = "crate::proto"
# no-std = true # opt-in `#![no_std]` + `alloc` paths (CLI: `--no-std` / `--std`)
# [project.example.doc]
# out = "generated/doc"
# Polyglot emitters (any subset may be configured alongside Rust; see examples/polyglot/witforge.toml):
# [project.example.typescript]
# out = "generated/ts"
# [project.example.typescript-glue]
# out = "generated/ts-glue"
# plain-root = "../ts"
# proto-root = "../proto"
# [project.example.python]
# out = "generated/py"
# [project.example.python-glue]
# out = "generated/py_glue"
# plain-root = "..py"
# proto-root = "..proto"
# [project.example.go]
# out = "generated/go"
# go-module = "example.com/acme/contracts/gen/go"
# [project.example.go-glue]
# out = "generated/go-glue"
# go-module = "example.com/acme/contracts/gen/go-glue"
# plain-root = "example.com/acme/contracts/gen/go"
# proto-root = "example.com/acme/contracts/gen/proto"
# [project.example.java]
# out = "generated/java"
# java-package = "com.acme.contracts.plain"
# [project.example.java-glue]
# out = "generated/java-glue"
# java-package = "com.acme.contracts.glue"
# plain-root = "com.acme.contracts.plain"
# proto-root = "com.acme.contracts.proto"
# [project.example.csharp]
# out = "generated/csharp"
# csharp-namespace = "Acme.Contracts.Plain"
# [project.example.csharp-glue]
# out = "generated/csharp-glue"
# csharp-namespace = "Acme.Contracts.Glue"
# plain-root = "Acme.Contracts.Plain"
# proto-root = "Acme.Contracts.Proto"
# [project.example.policy]
# diff-check = ["wire", "decode"]
# forbid-unstable-in-release = true

Then run every configured built-in emitter at once, narrow to a subset with --only, or opt in to configured plugins with --allow-plugins:

Terminal window
witforge generate --config witforge.toml
witforge generate --config witforge.toml --only rust,proto --check
witforge generate --config witforge.toml --allow-plugins --check
witforge generate --config witforge.toml --check

Inside a project directory or any subdirectory below it within the Git repository, witforge.toml is discovered upwards automatically (witforge generate, witforge rust, etc.); pass --no-config to disable discovery. Individual commands (witforge rust, proto, schema, glue, doc, ts, ts-glue, py, py-glue, go, go-glue, java, java-glue, csharp, csharp-glue, and plugin) also continue to accept --config witforge.toml or explicit CLI flags.

Paths inside witforge.toml (root, released, and every out) are resolved relative to the configuration file (or used as given when absolute, including .. components) and are never shell-expanded: a path starting with ~ or containing $ or %VAR% is refused with exit 2. Save witforge.toml as UTF-8 without a byte-order mark (BOM); wit/released is accepted with or without a leading UTF-8 BOM.

Under a WIT root, every entry whose name starts with v or V followed by a digit must be a valid v<major>.<minor> directory (for example v0.1, v1.0). Near-miss directories or files such as v0.2.0, V0.2, v0.2-rc1, v00.2, v1, or overflowing version numbers are refused rather than silently skipped; unrelated entries such as vendor, versions.md, released, and hidden files are ignored.

Each emitter and project needs its own non-overlapping output directory. Every generated file starts with an ownership header naming both the generator and the contract (// @generated by witforge (<gen>, <ns>:<name>); do not edit., // Code generated by witforge (<gen>, <ns>:<name>); DO NOT EDIT. for Go, # @generated by witforge (<gen>, <ns>:<name>); do not edit. for Python, <!-- @generated by witforge (<gen>, <ns>:<name>); do not edit. --> for Markdown, or the matching JSON Schema $comment prefix), except allowlisted headerless marker files such as PEP 561 py.typed. A generator only overwrites or removes files that carry its own header (or the legacy pre-0.6.0 shared header, which is adopted and rewritten when you regenerate).

  • An output directory that already holds files from another generator or another contract is refused with exit 2 before anything is written.
  • A witforge.toml configuration whose out paths coincide or nest (including across projects or through symlinks) is refused as a usage error (exit 2).
  • Symlinks, directories, and unowned files at expected output paths are refused; unowned files at other paths are left untouched.
  • Every generator supports --check, which writes nothing and fails on missing, changed, or extra generated files (and exits 2 if a foreign generator’s or contract’s file is present).

The generated-output guide shows current Rust, protobuf, JSON Schema, glue, version-adapter, and polyglot (TypeScript, Python, Go, Java, and C#) output from the committed runnable examples. Run witforge doc (or configure [project.<name>.doc]) to generate deterministic Markdown contract reference pages and per-version changelogs, or run witforge inspect --json to export the versioned JSON contract IR. The full example files are checked with --check in this repository’s CI.

External tools can target additional languages or frameworks without forking witforge by implementing the versioned JSON-over-stdio plugin protocol (protocol_version = 1, specified in docs/design/plugins.md).

Invoke a plugin explicitly by name (matching ^[a-z0-9][a-z0-9-]*$, up to 64 ASCII characters):

Terminal window
witforge plugin kotlin wit --out generated/kotlin --option package=com.acme.api
witforge plugin kotlin wit --out generated/kotlin --option package=com.acme.api --check

witforge resolves witforge-gen-<name> strictly by scanning absolute directories in PATH (using PATHEXT on Windows). Empty and relative PATH entries (including .) are skipped, and the current working directory is never searched implicitly. To run a local or pinned binary during development, pass --plugin-bin <PATH> on the CLI:

Terminal window
witforge plugin kotlin wit --out generated/kotlin --plugin-bin ./bin/witforge-gen-kotlin

Plugin output directories, default key-value options, and timeout limits may also be stored in witforge.toml:

[project.example.plugins.kotlin]
out = "generated/kotlin"
timeout-secs = 30
[project.example.plugins.kotlin.options]
package = "com.acme.api"
  1. Read a single UTF-8 JSON request object from stdin containing protocol_version (1), ir_version (1), plugin, contract_id, package, ownership (with generator_id "plugin:<name>" and pre-formatted line-1 ownership headers for line_comment, go_generated, hash_comment, json_comment, and html_comment), normalized options, and the validated root ir from witforge inspect --json. Host-specific filesystem paths such as --out and WIT_ROOT are never sent to the plugin so output remains machine-independent.
  2. Emit a single UTF-8 JSON response object on stdout with protocol_version: 1, optional header_style (default "line_comment"), an ordered files list ({ "path", "content", "marker?" }), and optional diagnostics ({ "severity", "message", "path?", "code?" }), then exit 0.
  3. Begin every non-marker file on line 1 with request.ownership.headers[header_style]. Use "marker": true only for small allowlisted marker files (up to 4 KiB, such as an empty py.typed).
  • Explicit opt-in only: witforge generate validates plugin config keys, output-root guards, and output-root distinctness, and never executes configured plugins unless --allow-plugins is passed explicitly on the CLI (passing --only plugins without --allow-plugins exits 2 with WF9001; plugin-only projects without --allow-plugins exit 2 with instructions to pass --allow-plugins or invoke witforge plugin <name>, while mixed multi-project configs run their built-in generators and skip plugin-only projects).
  • No executable paths in config: [project.<name>.plugins.<plugin>] rejects unknown keys such as plugin-bin, bin, command, or path with exit 2 (WF9003). Only the CLI flag --plugin-bin may specify an explicit executable path.
  • Pre-flight contract and path safety: witforge validates the WIT contract, lockfiles, and output-root guards before spawning the plugin. Before writing any file, witforge enforces POSIX relative path rules, refuses traversal (..), absolute paths, backslashes, control characters, duplicates, case-insensitive and prefix collisions, Windows reserved device names, missing or foreign ownership headers, and symlinks, and normalizes line endings to LF.
  • Bounded execution: stdin, stdout, and stderr are piped concurrently with hard caps (default timeout 30s up to 3600s, 64 MiB stdout, 1 MiB stderr, 4096 files, 16 MiB per file, 64 MiB total emitted content, 1024 diagnostics); runaway or timed-out processes are terminated and reported with exit 2 (WF9004). Plugin severity: "error" diagnostics prevent any writes and exit 1.