GoPatina is an open-source Go toolchain front end in which ordinary Go code can opt into running the way Rust code does: no garbage collector, ownership and borrowing, and Rust-grade memory safety. Without the flag it is plain Go, and every existing Go program builds exactly as before.
Mission: Go developers get Rust's performance and safety without the painful Rust learning curve.
Status: early. Phase 1 works for a defined subset of Go; real programs need features still in progress. Default mode works for all Go. For the subset, -emit-rust, -patina, -patina=check, -explain and gopatina verify are implemented and tested; everything else is rejected with a clear error. No performance figures are published yet.
Why GoPatina
The language you write in matters more to you, day to day, than what runs underneath it. Go is small, readable and quick to learn, with fast builds and excellent tooling. Rust gives deterministic memory management with no garbage collector, and catches memory errors and data races at compile time, but it is powerful and painful to learn: ownership, borrowing, lifetimes and async are a steep climb.
GoPatina keeps Go on top and puts Rust underneath. You keep writing Go; the compiler does the Rust part. GoPatina is an experiment by Pigfox to get Go developers past Rust's learning curve. Without a garbage collector a few ownership rules remain, but GoPatina states and checks them in Go terms: no Rust syntax, no lifetime annotations, no async keywords to learn.
Three modes, two flags
| Mode | Flag | Garbage collector | Works with all Go | Output | Status |
|---|---|---|---|---|---|
| Default | none | Yes (Go's) | Yes | A Go binary, built by your installed go | Works today |
| Emit Rust | -emit-rust | No | No: a defined subset | A readable Rust crate you can keep and build with cargo | Works for the phase 1 subset |
| Patina | -patina | No | No: the same subset | A native binary built by rustc from that crate | Works for the phase 1 subset |
A variant, -patina=check, runs the same checks and then builds with the Go compiler, for machines where Rust cannot be installed. It is never a silent fallback: you choose it, and the output says which compiler built the binary.
What phase 1 supports
The patina modes accept a defined subset of Go, specified in docs/patina-subset.md:
package mainin one directory, with functions, methods and named struct typesint,int64,int32(rune),byte,float64,bool,string, and slices of supported typesif,for(includingfor rangeover slices, strings and integers),switch, constants andiotaerrorresults witherrors.Newandfmt.Errorf, and pointers used as borrowsfmtprinting (Println,Printf,Sprintf,Fprintfand the rest) and a few functions fromstrings,slices,bytesandos
Not supported yet: goroutines and channels, maps, closures and function values, interfaces other than error and io.Writer, generics, defer, slicing (s[i:j]), and most of the standard library. Each is rejected with a Go-style error that names the construct; nothing is translated approximately. See the feature matrix and every known place where Go and Rust semantics differ.
How it is checked. Each of the 69 test programs in the project's golden suite is built both ways in CI, with go build and with gopatina build -patina, and both binaries must print the same output and exit with the same status. Emitted Rust is byte-identical for the same input, and gopatina verify checks that a -patina binary has the same sha256 as a plain cargo build --release --locked of the emitted crate.
How it works
What you write on top
Ordinary Go, formatted by gofmt and type-checked by Go's own libraries. Patina code is always valid Go, so the plain Go toolchain can always build it too. A package can keep a patina version beside a plain one with the //go:build patina constraint.
What happens underneath
Both patina flags translate the Go program into readable Rust. -emit-rust stops there and writes a cargo crate. -patina goes on to build that crate with rustc, so the result is a Rust program: no garbage collector and memory safe. Calling Rust crates directly is planned. rustc and LLVM do the optimising, and Rust's own borrow checker verifies every program GoPatina writes.
The GoPatina borrow checker
Before any Rust is written, GoPatina's own borrow checker runs on the Go code. It decides who owns each value and which values are moved, copied or borrowed, and applies fixes that keep the program's meaning. Phase 1 implements moves, copies of strings and small structs, and inferred shared and exclusive borrows; shared ownership and mutexes for values shared across goroutines come with goroutines. Every decision is reported with -explain; gopatina fix, which will write fixes back into the Go source, is planned. When no safe fix exists, the error is in Go terms. This is real output for the project's ownership example:
./examples/ownership/main.go:33:2: m.Body is changed after m was handed to out.Queue on line 32
out.Queue(m) // line 32: out.Queue keeps m
m.Body[0] = 'D' // line 33: this also changes the copy out.Queue kept, which shares m.Body's memory
patina mode does not copy m on its own: a copy would not share that memory, so the program could behave differently
if out.Queue should keep the original, hand it a copy: Message{To: m.To, Body: bytes.Clone(m.Body)}
or finish using m before handing it over
Goroutines
Goroutines are not supported yet; this part is designed, not built. In patina mode, goroutines are designed to run as tasks on Tokio's multi-threaded runtime, the closest match to Go's own scheduler. Channels map to Tokio channels and select to tokio::select!. The compiler decides which functions must be async, so Go code never says async or await. Data races, which Go finds only at run time with -race, are to become compile errors or be fixed automatically.
Portability
A patina binary is native code, so the target machine needs neither Go nor Rust installed. GOOS and GOARCH choose the Rust target. Phase 1 builds for each platform's default C runtime (the -gnu targets on Linux); static musl binaries by default, and cross-compiling with a fetched target, are planned.
Compatibility as Go and Rust evolve
Default mode always uses your installed Go, so new Go releases work there immediately. Patina modes support the two latest Go releases and refuse, by name, any Go feature they do not support yet; they never miscompile silently. Generated Rust uses stable Rust only, a declared edition (2024) and a minimum supported Rust version (1.85), and CI tests against Go and Rust release channels every week.
Try it today
Requires Go 1.25 or later; -patina and gopatina verify also need a Rust toolchain. Phase 1 is not released yet, so install from main:
go install github.com/pigfox/gopatina/cmd/gopatina@main
gopatina build ./... # runs go build ./...
gopatina build -emit-rust -o crate . # writes a cargo crate
gopatina build -patina -explain -o app . # native binary, with every decision
gopatina run -patina . # build and run it
gopatina build -patina=check . # patina checks, then the Go compiler
gopatina verify . # reproducible: -patina == plain cargo
The patina commands work on programs inside the phase 1 subset. See the examples for the three modes on three small programs: real output for the two that fit the subset, and the goroutine example's planned output clearly labelled.
Roadmap
| Phase | Scope | Status |
|---|---|---|
| 0 | The RFCs; the gopatina command with default-mode pass-through | Done (v0.0.1) |
| 1 | -emit-rust, -patina, -patina=check and gopatina verify for the phase 1 subset, with the borrow checker and the Rust code generator | Done (unreleased) |
| 2 | The rest of the borrow checker: maps, closures, defer, slicing, gopatina fix, the strict mode | Planned |
| 3 | Goroutines and channels on a multi-threaded async runtime, with shared-ownership and mutex fixes | Planned |
| 4 | A standard library subset and Rust crate interop | Planned |
Quality policy
Every Go package in the project has 100% unit-test coverage, enforced in CI, and each phase adds its own required test layers: golden tests of generated Rust, compile-and-run tests, rejection and fuzz tests for the borrow checker. Every change, including the maintainer's own, goes through a pull request that the project lead approves.
Benchmarks
No benchmarks have been run yet on the maintainer's test server, so no performance figures are published. The goal is to shadow Rust and keep up: within 10% of equivalent hand-written Rust on every benchmark, built with the latest stable Rust. That is a goal, not a claim. Pull requests get ratio checks in CI; official numbers will come only from the maintainer's dedicated test server, run on the full suite and published in BENCHMARKS.md with the machine, Go and Rust versions, commit and date.
Frequently asked questions
- What is GoPatina?
- GoPatina is an open-source Go toolchain front end by Pigfox. Without a flag it is plain Go. With an opt-in flag, a defined subset of Go compiles through Rust, with no garbage collector and Rust's memory safety.
- Does GoPatina work today?
- Partly. Default mode works for all Go: it passes every command through to the installed go tool. The Rust-based modes work for the phase 1 subset of Go: functions, structs and methods, slices, strings, errors and fmt printing. Goroutines, maps, closures, interfaces, generics and most of the standard library are not supported yet and are rejected with a clear error.
- Will my existing Go code still work?
- Yes. Without a patina flag, gopatina runs go with the same arguments, so every Go program builds exactly as before. Only code you opt into patina mode must follow its stricter rules.
- Do I need to learn Rust to use GoPatina?
- No. You write Go. Without a garbage collector a few ownership rules remain, but GoPatina's borrow checker infers ownership and borrows, fixes what it safely can, and explains the rest in Go terms.
- How fast is GoPatina?
- Nobody knows yet. No benchmarks have been published. Official results will be published in BENCHMARKS.md, measured against hand-written Rust and plain Go.
- What does a machine need to run a patina binary?
- Nothing extra. A patina binary is native machine code, so the target needs neither Go nor Rust installed, just like a Go binary. Phase 1 links against the platform's default C runtime; static binaries are planned.
- Who makes GoPatina, and under what license?
- GoPatina was started by Peter Sjolin as an experiment by Pigfox. It is open source under MIT OR Apache-2.0, and every change goes through a reviewed pull request on GitHub.
Read more
- Source code and README on GitHub
- Examples of the three build modes
- The phase 1 subset: what the patina modes accept
- Feature matrix: what is supported, by Go feature
- Where Go and Rust semantics differ, and what GoPatina does
- RFC 0001: the design, the borrow checker, Rust underneath
- RFC 0002: concurrency in patina mode
- RFC 0003: toolchain compatibility and versioning
- Benchmarks (none yet)