Non-Rust implementations
witforge compiles one hand-written WIT contract into idiomatic, zero-dependency plain types,
interface definitions, cross-version adapters, and checked protobuf glue for five non-Rust
ecosystems alongside Rust: TypeScript, Python, Go, Java, and C#. For any other
language (such as C++, Kotlin, or Swift), consumers can use the emitted .proto schema with that
language’s protobuf generator and enforce the decode profile below, or target the language with a
third-party emitter plugin. witforge does not generate RPC services or own transport framing.
Built-in polyglot emitters
Section titled “Built-in polyglot emitters”Each built-in polyglot language ships as a plain-types emitter (zero third-party runtime dependencies, plus bidirectional cross-version adapters whenever a contract has adjacent versions) paired with a checked protobuf glue emitter that enforces every decode and encode rule in the profile below:
| Language | Target baseline | Plain emitter (witforge <cmd>) |
Version adapters | Checked glue (witforge <cmd>) |
Protobuf runtime |
|---|---|---|---|---|---|
| TypeScript | Strict ESM (NodeNext) |
ts (readonly interfaces, unions, worlds.ts) |
convert.ts |
ts-glue |
@bufbuild/protobuf |
| Python | Python 3.11+ stdlib | py (frozen dataclasses, StrEnum, Protocol, py.typed) |
convert.py |
py-glue |
google.protobuf (protoc --python_out) |
| Go | Go 1.22+ stdlib | go (typed structs, sealed interfaces, worlds/) |
convert/ |
go-glue |
google.golang.org/protobuf (protoc-gen-go) |
| Java | Java 21+ stdlib | java (records, sealed interfaces, Optional, Worlds.java) |
Convert.java |
java-glue |
com.google.protobuf (protoc --java_out) |
| C# | C# 12+ / .NET 8+ stdlib | csharp (#nullable enable records, Worlds.cs) |
Convert.cs |
csharp-glue |
Google.Protobuf (protoc --csharp_out) |
Configure any subset of these emitters in witforge.toml and run them together with
witforge generate (or narrow a run with --only):
witforge generate --config examples/polyglot/witforge.tomlwitforge generate --config examples/polyglot/witforge.toml --only proto,ts,ts-glue --checkSee examples/polyglot/witforge.toml
for a complete working configuration covering all five languages, and the
generated-output guide for verified excerpts from the
committed outputs. All flags and configuration keys are listed in the
CLI and configuration reference.
Protobuf file options
Section titled “Protobuf file options”By default, emitted .proto files carry no language-specific file options so output remains
neutral across every target language. If you want generated .proto files to embed idiomatic
Go, Java, or C# placement options directly, opt in via [project.<name>.proto] in witforge.toml
or the matching flags on witforge proto:
[project.example.proto]out = "generated/proto"go-package = "github.com/acme/contracts/gen/go"java-package = "com.acme.contracts"java-multiple-files = truecsharp-namespace = "Acme.Contracts"
# Optional exact overrides keyed by emitted proto package name (including# disambiguated dependency packages such as `shared.types.v0_m1`):[project.example.proto.packages."example.plugin.v0"]java-outer-classname = "PluginV0Proto"Or on the command line:
witforge proto wit --out generated/proto \ --go-package github.com/acme/contracts/gen/go \ --java-package com.acme.contracts \ --java-multiple-files \ --csharp-namespace Acme.ContractsHow each option is derived across multiple majors (v0, v1) and deps/ dependency files:
go-package: a base import path prefix without;derives<prefix>/<ns>/<name>/<ver>;<ns>_<name>_<ver>for every emitted file (for examplegithub.com/acme/contracts/gen/go/example/plugin/v0;example_plugin_v0). An explicit<import/path>;<alias>value (which must include/) is accepted verbatim when at most one emitted file inherits it and refused when multiple emitted files would share it.java-package: derives<prefix>.<proto_package>, escaping Java reserved keywords with a trailing underscore (for exampledefaultbecomesdefault_). Two emitted files in the same effective Java package cannot emit colliding top-level Java class names (includingEmpty.javaunderjava-multiple-files = trueor implicit default outer classnames).java-multiple-files: emitsoption java_multiple_files = true;(orfalse;in config). Pass--no-java-multiple-fileson the CLI to omit the option when overriding config.java-outer-classname: validated as a Java type identifier (rejecting keywords and restricted type identifiers such asrecordandvar) and refused if it collides with any generated message, enum, wrapper,<Message>OrBuilder, enclosedBuilder/*Caseclass, or another emitted file’s Java class in the same effective Java package.csharp-namespace: derives<prefix>.<PascalCaseSegments>(for exampleexample.my_pkg.v0becomesAcme.Contracts.Example.MyPkg.V0, and a disambiguated dependencyshared.types.v0_m1becomesAcme.Contracts.Shared.Types.V0M1). Two emitted files resolving to the same C# namespace are refused because every generated.protofile definesmessage Empty.
File options are strictly non-wire metadata: they never alter wire.lock, protobuf binary wire
encoding, witforge diff --check=wire,decode, Rust module paths generated by witforge-build /
prost-build, or witforge glue.
If you prefer to keep zero language options in checked-in .proto files, both protoc
(--go_opt=Mv0.proto=github.com/acme/contracts/gen/go/v0) and buf managed mode
(buf.gen.yaml managed.override) can inject Go, Java, and C# placement outside the schema.
Note that buf breaking with its default FILE rules flags changed file options once if you
enable file options on an already-published contract; either opt in before your first release or
temporarily exclude FILE_SAME_* option checks for that transition commit.
Decode profile
Section titled “Decode profile”The generated protobuf type alone is not the complete WIT value contract. Some WIT rules cannot
be expressed by proto3 syntax and are enforced by witforge’s built-in checked glue emitters
(glue, ts-glue, py-glue, go-glue, java-glue, and csharp-glue). If you consume the
.proto files directly in another language without generated glue, your adapter must enforce the
same rules explicitly.
| WIT value | Protobuf projection | Required implementation behavior |
|---|---|---|
u8, u16 |
uint32 |
Reject values above the WIT type’s maximum. |
s8, s16 |
sint32 |
Reject values outside the WIT type’s signed range. |
char |
uint32 |
Reject code points that are not valid Unicode scalar values (surrogates 0xD800..=0xDFFF and values > 0x10FFFF). |
required scalar, string, enum, list<u8>, or list<u8, N> |
proto3 optional scalar/string/enum/bytes |
Reject absence. A scalar’s protobuf default is not a substitute for presence. |
option<T> |
the same optional or wrapper shape used for T |
Permit absence as None; validate a present payload normally. |
| required record, variant, flags, result, parameter, or message result | message field | Reject absence. |
list<T> |
repeated T, or a wrapper when nested |
Empty is valid. Validate every element recursively. |
list<T, N> |
optional bytes (when T is u8) or repeated singular(T) (or list wrapper when nested) |
Require exact length N (1 <= N <= 65536), rejecting shorter or longer payloads (InvalidLength). Validate every element recursively. |
map<K, V> |
map<K', singular(V)>, or a WitforgeMapOf... wrapper when nested |
Empty is valid. Validate narrow integer keys (u8/u16/s8/s16), char keys, and every value recursively. |
| enum | protobuf enum with UNSPECIFIED = 0 |
Reject zero and unknown numeric values; WIT enums are closed. |
| variant or result | message with a oneof |
Require one known case. Reject an unset or unknown case. |
| flags | message with one bool per flag |
Treat missing/default false as an unset flag. |
| nested option/list/result wrapper | synthesized message | Require the wrapper’s oneof (none/some or ok/err) to be set; reject an unset or unknown wrapper state. |
These rules apply to record fields, function parameters, and function results. They also apply
after protobuf binary or proto3-JSON parsing. Language protobuf libraries commonly preserve an
unknown enum number or expose a uint32 without the narrower WIT range; successful protobuf
parsing therefore does not establish a valid WIT value.
Built-in checked glue returns a structured error (GlueError in Rust, WitforgeGlueError in
TypeScript and Python, *glueerr.GlueError in Go, WitforgeGlueException in Java and C#) covering
these cases plus encode-side narrow/unsigned integer, UTF-8/scalar-value, and fixed-length checks.
Custom implementations in other languages should expose idiomatic errors while preserving the exact
same accept/reject boundary.
Conformance fixture bundle
Section titled “Conformance fixture bundle”Use witforge conformance to export witforge’s built-in, deterministic cross-language conformance
bundle (conformance_version = 1) and verify built-in or custom protobuf glue against the exact
same decode and encode rules proved across Rust, TypeScript, Python, Go, Java, and C# in CI:
witforge conformance --out conformance-bundle --polyglot-proto-optionswitforge conformance --out conformance-bundle --polyglot-proto-options --checkThe command writes two directories and a top-level manifest under --out:
wit/v0.1/: the canonical WIT conformance contract (contract.wit,deps/conformance-dep/dep.wit, andwire.lock) exercising all 13 decode-profile rows, foreigndeps/types, and interface functions.proto/: the emitted.protofiles (v0.protoandwitforge.conformance_dep.v0.proto). Files are neutral by default; pass--polyglot-proto-options(or explicit--go-package,--java-package,--java-multiple-files,--java-outer-classname,--csharp-namespace) to embed Go, Java, and C# placement options.vectors.json: deterministic test vectors carrying RFC 4648 base64 binary protobuf payloads, canonical proto3-JSON payloads, expectedaccept/rejectoutcomes, canonical error kinds (IntegerOutOfRange,MissingField,UnknownEnumValue,UnknownCase,InvalidState,InvalidChar,InvalidLength), andencode-direction boundary rejection vectors for languages without native narrow/unsigned/scalar-char/fixed-array types.
The built-in vectors cover:
- every narrow integer’s minimum, maximum, and out-of-range values plus 64-bit integers beyond
2^53 - 1(u64::MAX,i64::MIN,i64::MAX,9007199254740993,-9007199254740993); charboundary scalars (U+0000,U+D7FF,U+E000,U+1F680,U+10FFFF), multi-byte UTF-8 strings with embedded NUL, UTF-16 surrogates (0xD800..=0xDFFF), and values above0x10FFFF;f32/f64finite boundaries,-0.0,NaN,Infinity, and-Infinity;- required optional/message fields present (including explicit zero/empty defaults) and absent;
option<T>absent and present, includingoption<option<T>>,option<list<T>>, andoption<map<K, V>>;- closed enums (
0, known cases, and unknown numbers) in both root anddeps/packages; - every variant case, all four
resultforms (result<T, E>,result<T>,result<_, E>,result), unset variant/result oneofs (UnknownCase), and unsetWitforgeOptionOf*wrappers (InvalidState); - empty and populated lists, fixed-length
list<u8, N>andlist<T, N>with exact lengthN,N - 1, andN + 1, and nested list/option/result wrappers; map<K, V>across string, narrow integer,char,bool, and 64-bit keys plus nested maps;- interface function request and response wrappers (including foreign
deps/parameters and no-result functions), in both protobuf binary and proto3-JSON forms; - encode-side (
toProto) boundary rejection vectors for TypeScript, Python, Go, Java, and C#.
Run the vectors through your target language’s protobuf implementation and keep --check in CI to
detect drift. Generated-file --check proves schema reproducibility; running vectors.json proves
runtime wire-contract parity across every language.
Extending to other languages with plugins
Section titled “Extending to other languages with plugins”If you need generated plain types, glue, or framework-specific code for an ecosystem outside the
built-in emitters (such as Kotlin, Swift, C++, or a custom runtime), implement the versioned
JSON-over-stdio plugin protocol (protocol_version = 1) and run it with witforge plugin <name>
or opt in via witforge generate --allow-plugins. See
Third-party emitter plugins, the normative
plugin specification, and
the zero-dependency starter kits in Rust, TypeScript (Node 20+), and Python 3.11+ under
examples/plugin-starters/:
# Try the TypeScript (or Rust / Python) starter kit against examples/polyglot/wit:witforge plugin starter examples/polyglot/wit \ --plugin-bin examples/plugin-starters/typescript/witforge-gen-starter.mjs \ --out ./starter-outwitforge plugin starter examples/polyglot/wit \ --plugin-bin examples/plugin-starters/typescript/witforge-gen-starter.mjs \ --out ./starter-out \ --checkGo //go:generate workflow
Section titled “Go //go:generate workflow”Go repositories can pin witforge (alongside protoc and protoc-gen-go) via mise.toml or
aqua.yaml using packaging/aqua/registry.yaml,
which downloads the attested static musl Linux (or native macOS/Windows) archive and verifies
both its .sha256 checksum and GitHub SLSA build provenance (until zeropier/witforge is merged
into upstream aquaproj/aqua-registry, configure packaging/aqua/registry.yaml as a local aqua
registry as shown in
packaging/aqua/README.md).
Setting libc = "musl" in mise.toml ensures mise selects the static musl archive on Linux
distributions with glibc < 2.39 rather than swapping to the sibling Ubuntu 24.04 -gnu archive:
# mise.toml (once zeropier/witforge is merged into upstream aquaproj/aqua-registry)[tools]"aqua:zeropier/witforge" = { version = "0.12.0", libc = "musl" }Then drive deterministic generation directly from go generate ./...:
//go:generate witforge generate --config witforge.toml --only proto,go,go-glue//go:generate protoc -I generated/proto --go_out=generated/pb --go_opt=paths=source_relative generated/proto/v0.protopackage contractsIn CI, run witforge generate --config witforge.toml --only proto,go,go-glue --check to verify
committed Go outputs without introducing any compiler dependency into go.mod. Generated Go plain
types remain zero-dependency Go 1.22+ stdlib packages.
MSBuild integration for .NET
Section titled “MSBuild integration for .NET”.NET 8+ projects can integrate witforge into dotnet build with the thin Witforge.Tools
developmentDependency NuGet package (packaging/dotnet/,
staged in each tag release’s dotnet-jvm-packages workflow artifact for local or private NuGet
feeds), modeled on Grpc.Tools:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> <Nullable>enable</Nullable> <WitforgeConfig>witforge.toml</WitforgeConfig> <WitforgeGenerators>proto,csharp,csharp-glue</WitforgeGenerators> <!-- Default is check (verifies committed outputs in CI); override with -p:WitforgeMode=generate --> <WitforgeMode>check</WitforgeMode> <WitforgeGeneratedCSharpDir>generated/csharp</WitforgeGeneratedCSharpDir> </PropertyGroup> <ItemGroup> <PackageReference Include="Witforge.Tools" Version="0.12.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference> </ItemGroup></Project>Witforge.Tools carries zero runtime assemblies under lib/ and zero buildTransitive/ targets,
so downstream projects referencing a compiled contract assembly never inherit codegen targets or
bundle native binaries in bin/. WitforgeRun executes with
BeforeTargets="Protobuf_BeforeCompile;Protobuf_Compile;BeforeCompile", restores user execute
permission (u+x) on the bundled NuGet tool on Unix if NuGet extraction cleared it before
verifying execute permission, supports offline binary overrides via <WitforgeBinaryPath> or
WITFORGE_BINARY_PATH, and in generate mode dynamically appends newly emitted .cs and .proto
files to @(Compile) and @(Protobuf) (deduplicated by %(FullPath)).
Gradle and Maven integration for JVM
Section titled “Gradle and Maven integration for JVM”Java 21+ projects can invoke witforge ahead of protoc and Java compilation using the
classifier-addressed org.witforge:witforge-native:<version>:<classifier>@exe artifacts
(staged in each tag release’s dotnet-jvm-packages workflow artifact for local or private Maven
repositories) and thin wrappers under packaging/jvm/,
matching the standard osdetector / os-maven-plugin convention (linux-x86_64,
linux-aarch_64, osx-x86_64, osx-aarch_64, windows-x86_64, with static musl binaries on
Linux):
- Gradle (
packaging/jvm/witforge.gradle.kts): registerswitforgeGenerate(ordered strictly ahead ofextractProto,extractIncludeProto,generateProto,generateTestProto,compileJava, andcompileTestJava, withwit/,witforge.toml, version, generators, and manifest inputs declared for Gradle build-cache correctness, plus opt-in-PwitforgeAutoGenerate=true) andwitforgeCheck(wired intocheckwithmustRunAfter(witforgeGenerate)). Verifies the resolved@exeartifact against a committed SHA-256 manifest, ensures owner execute permissions (u+x) on Unix when needed, and honors-PwitforgeBinary=...andWITFORGE_BINARY_PATH. - Maven (
packaging/jvm/pom-example.xml+packaging/jvm/WitforgeWrapper.java): resolveswitforge-nativeviaos-maven-plugin(${os.detected.classifier}) +maven-dependency-plugin, runs the forked Java 21exec:execlauncher (witforge-generate) ingenerate-sourcesstrictly ahead ofprotobuf-maven-plugininside<build><plugins>so Maven runswitforgebeforeprotoc, bindswitforge-checktoverify, verifies SHA-256 digests before execution, and honors-Dwitforge.binary=...andWITFORGE_BINARY_PATH.
Plain Java 21 outputs emitted by witforge java remain zero-dependency java.base code.
JSON is a separate choice
Section titled “JSON is a separate choice”Proto3-JSON follows protobuf naming and presence rules. It is not the JSON shape described by witforge’s JSON Schema (Draft 7 default, opt-in Draft 2020-12) and it is not necessarily the shape produced by Serde on generated plain Rust types. See JSON projections before choosing a JSON boundary.
Protovalidate annotations are not emitted today; they would expand the generated .proto schema
and consumer runtime/tooling requirements and remain deferred behind an explicit future option if
an adopter demonstrates a need beyond checked glue and conformance fixtures.