Configuring generation
Commands
Section titled “Commands”witforge rust wit --out generated/rustwitforge proto wit --out generated/protowitforge schema wit --out generated/schemawitforge glue wit --out generated/glue \ --plain-root crate::plain \ --proto-root crate::protowitforge 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.
Configuration
Section titled “Configuration”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 = trueThen run every configured built-in emitter at once, narrow to a subset with --only, or opt in to
configured plugins with --allow-plugins:
witforge generate --config witforge.tomlwitforge generate --config witforge.toml --only rust,proto --checkwitforge generate --config witforge.toml --allow-plugins --checkwitforge generate --config witforge.toml --checkInside 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.
Output ownership
Section titled “Output ownership”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
2before anything is written. - A
witforge.tomlconfiguration whoseoutpaths coincide or nest (including across projects or through symlinks) is refused as a usage error (exit2). - 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 exits2if a foreign generator’s or contract’s file is present).
Inspect the result
Section titled “Inspect the result”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.
Third-party emitter plugins
Section titled “Third-party emitter plugins”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).
Invoking a plugin
Section titled “Invoking a plugin”Invoke a plugin explicitly by name (matching ^[a-z0-9][a-z0-9-]*$, up to 64 ASCII characters):
witforge plugin kotlin wit --out generated/kotlin --option package=com.acme.apiwitforge plugin kotlin wit --out generated/kotlin --option package=com.acme.api --checkwitforge 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:
witforge plugin kotlin wit --out generated/kotlin --plugin-bin ./bin/witforge-gen-kotlinPlugin 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"Authoring a plugin
Section titled “Authoring a plugin”- Read a single UTF-8 JSON request object from
stdincontainingprotocol_version(1),ir_version(1),plugin,contract_id,package,ownership(withgenerator_id"plugin:<name>"and pre-formatted line-1 ownership headers forline_comment,go_generated,hash_comment,json_comment, andhtml_comment), normalizedoptions, and the validated rootirfromwitforge inspect --json. Host-specific filesystem paths such as--outandWIT_ROOTare never sent to the plugin so output remains machine-independent. - Emit a single UTF-8 JSON response object on
stdoutwithprotocol_version: 1, optionalheader_style(default"line_comment"), an orderedfileslist ({ "path", "content", "marker?" }), and optionaldiagnostics({ "severity", "message", "path?", "code?" }), then exit0. - Begin every non-marker file on line 1 with
request.ownership.headers[header_style]. Use"marker": trueonly for small allowlisted marker files (up to 4 KiB, such as an emptypy.typed).
Security boundaries and limits
Section titled “Security boundaries and limits”- Explicit opt-in only:
witforge generatevalidates plugin config keys, output-root guards, and output-root distinctness, and never executes configured plugins unless--allow-pluginsis passed explicitly on the CLI (passing--only pluginswithout--allow-pluginsexits2withWF9001; plugin-only projects without--allow-pluginsexit2with instructions to pass--allow-pluginsor invokewitforge 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 asplugin-bin,bin,command, orpathwith exit2(WF9003). Only the CLI flag--plugin-binmay specify an explicit executable path. - Pre-flight contract and path safety:
witforgevalidates the WIT contract, lockfiles, and output-root guards before spawning the plugin. Before writing any file,witforgeenforces 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, andstderrare piped concurrently with hard caps (default timeout30sup to3600s,64 MiBstdout,1 MiBstderr,4096files,16 MiBper file,64 MiBtotal emitted content,1024diagnostics); runaway or timed-out processes are terminated and reported with exit2(WF9004). Pluginseverity: "error"diagnostics prevent any writes and exit1.