Skip to content

Runnable examples

The repository contains three runnable examples with committed generated output.

examples/single exercises:

  • one contract version;
  • witforge.toml;
  • Rust, protobuf, JSON Schema, and glue generation;
  • committed output checked by every generator’s --check mode.
Terminal window
git clone https://github.com/zeropier/witforge.git
cd witforge/examples/single
witforge check wit/v0.1
witforge rust --config witforge.toml
witforge proto --config witforge.toml
witforge schema --config witforge.toml
witforge glue --config witforge.toml

The exact generated files are under examples/single/generated. The generated-output guide walks through representative sections.

examples/evolved contains released v0.1 and draft v0.2. It demonstrates lock continuity, diff, release freezing, and generated version adapters.

Terminal window
cd witforge/examples/evolved
witforge check wit/v0.2 --against wit/v0.1/wire.lock
witforge diff wit/v0.1 wit/v0.2
witforge rust --config witforge.toml

The example adds defaultable fields. Version-adapter generation accepts them, but diff --check still reports a source/generated-API break. Use plain diff to review the example; add --check when project policy forbids those changes.

examples/polyglot contains released v0.1 and draft v0.2 (adding priority: option<u8> on item), configuring protobuf file options alongside all five built-in non-Rust ecosystems in one witforge.toml:

  • protobuf with Go, Java, and C# placement options (generated/proto);
  • TypeScript strict ESM plain types, convert.ts, and @bufbuild/protobuf glue (generated/ts, generated/ts-glue);
  • Python 3.11+ stdlib plain types, convert.py, and google.protobuf glue (generated/py, generated/py_glue);
  • Go 1.22+ stdlib plain packages, convert/, and google.golang.org/protobuf glue (generated/go, generated/go-glue);
  • Java 21+ records and sealed interfaces, Convert.java, and com.google.protobuf glue (generated/java, generated/java-glue);
  • C# 12+ / .NET 8+ records, Convert.cs, and Google.Protobuf glue (generated/csharp, generated/csharp-glue).
Terminal window
cd witforge/examples/polyglot
witforge check wit
witforge generate --config witforge.toml --check
witforge generate --config witforge.toml --only proto,ts,ts-glue --check

The committed outputs live under examples/polyglot/generated, and the generated-output guide shows line-verified excerpts for every language.

examples/plugin-starters contains zero-dependency protocol_version = 1 emitter plugin starter kits in Rust, TypeScript (Node.js 20+), and Python 3.11+ that read Contract IR v1 from stdin and agree byte-for-byte on output and diagnostics under witforge plugin starter.

Generated output is committed for review and checked for drift in CI (or run witforge generate --config witforge.toml --check to verify every configured emitter in one step). You can also run witforge inspect wit --json to inspect any example’s versioned contract IR, or witforge doc wit --out preview-doc to preview generated Markdown contract reference pages. Run any generator without --check to update committed files, review the diff, then run the same command with --check.