Building go2cs from source

This page is for developers who want to build the converter themselves, check its results, or work on it: how to build it, how to run its tests, how to validate a converted package against go test, what its error codes mean, and where things live in the repository.

Build the converter

You need the Go release named in the README’s Requirements and the .NET 10 SDK, version 10.0.400 or later, with your Go environment set up (GOROOT/GOPATH). The repository’s global.json sets that floor, so an earlier 10.0 SDK stops at the first dotnet command with “A compatible .NET SDK was not found”. Converted projects target the framework named by src/Directory.Build.props. The converter’s module path is plain go2cs, so it cannot be installed by URL: clone the repository and install from the clone, as the README’s Installing the converter shows. Go produces a self-contained native binary; to target another platform, use Go’s standard cross-compilation (GOOS/GOARCH). Rebuild after every pull, with the same Go release you convert with.

go2cs -version prints which release the binary belongs to and which Go toolchain built it, one key=value line per key (Command-line options). Paste it into a bug report.

Run the converter’s own tests

cd go2cs/src/go2cs
go test ./...

The per-feature Go-versus-C# tests live under src/tests/Behavioral: each one is transpiled, compiled and compared against a committed expected output, and each runnable one is executed with its output compared against Go’s. CONTRIBUTING.md says how to run them before you send a change.

These focused checks run by hand when you change what they guard:

Validate a converted test suite

Every validated package ships its converted C# test sources next to the production code under src/core (for example, unicode/utf8/utf8_test.cs), so you can read the exact C# that runs — and re-run the validation yourself. You need the Go release in the README’s Requirements (for the reference go test run), the .NET 10 SDK 10.0.400 or later, and go2cs on your PATH (see Build the converter).

Run it from the root of your clone. The first argument is the package’s Go source, and the second is the package’s home in the converted tree; the converter locates the runtime and the package’s standard-library dependencies from there, so no other flags or environment setup are needed. (A go2cs root staged where GO2CSPATH points, or at ~/go2cs, takes precedence; to validate against the clone instead, add -go2cspath with the absolute path of the clone’s src folder.) The ten minutes are the deadline for running the tests and comparing them with go test; building the test host has its own, longer allowance, because the first build compiles the converted runtime and the package’s standard-library dependencies.

PowerShell, on Windows:

go2cs -tests -test-action all -test-timeout 10m "$(go env GOROOT)\src\unicode\utf8" src/core/unicode/utf8

bash, on Linux and macOS:

go2cs -tests -test-action all -test-timeout 10m "$(go env GOROOT)/src/unicode/utf8" src/core/unicode/utf8

Expected final line, in outline (its counts depend on the Go release and the platform; the package’s proof page has the current figures):

Validated <n> tests against go test (<s> skipped identically on both sides, <d> disclosed-divergent (deferred), <u> disclosed-unsupported declarations excluded).

The command converts the _test.go files to C#, generates a test host, builds it against the converted standard library, runs it in an isolated process, captures a clean go test -json -count=1 baseline, and compares terminal results by full Go test name — reporting validated only when every test agrees on both sides and every unsupported declaration (benchmarks, examples) is accounted for. It regenerates the local converted .cs in place and rewrites the package’s proof page under docs/validation/current/; the Go source copies and run manifests it stages are git-ignored. The same command validates every other package in Validated Test Packages — substitute its GOROOT source path and its src/core/<pkg> path in the two arguments.

The test host is published in the Release configuration and run with the CLR’s tiered JIT off (DOTNET_TieredCompilation=0), so every method is compiled once at full optimization and a verdict cannot depend on when the runtime promotes a method; -test-tiered turns tiering back on, and -test-config Debug publishes a Debug host (a program you ship keeps tiering on: Tuning converted code). ReadyToRun is opt-in — set PublishReadyToRun=true in the environment to publish a precompiled host (crypto/tls’s host is always published ReadyToRun, for its start-up cost) — because it buys a slower steady state on heavy suites, a larger host and a longer first publish, and because precompiled code does not keep the JIT’s stack frames, so a test that asserts on frames can answer differently.

A few packages carry a disclosed divergence: a Go test asserting something the converted runtime does not satisfy — an allocation count Go meets through compiler escape analysis, or a collectibility check Go answers from per-safepoint liveness maps. Some of these a managed runtime provably cannot satisfy; others — marked deferred, such as unicode/utf8’s own zero-allocation TestRuneCountNonASCIIAllocation — it can, and each of those is pinned against the named plan that will retire it. Rather than skip those tests, each affected package pins the divergence in a hand-owned, committed go2cs_test_disclosures.json that the differential oracle matches by exact failure signature — any other failure is still a hard mismatch — and reports as disclosed-divergent in the summary. Packages without a manifest compare strictly.

The GO2CS codes a conversion or a build reports are listed in Diagnostic codes.

Project layout

Path Contents
src/go2cs/ The converter (written in Go, using go/ast + go/types).
src/core/ The converted Go standard library — every package, with unsafe and testing hand-written rather than converted. Everything (tests, tour, NuGet) builds against this one tree.
src/core/golib/ The C# runtime library (slice, map, channel, @string, built-ins, type aliases).
src/core/go2cs/ Shared Symbols project — the canonical marker glyphs used by the runtime and the generators.
src/gen/go2cs-gen/ Roslyn source generators (interface implementation, receiver overloads, struct embedding).
src/tour/ Tour of go2cs — the Tour of Go beside a live Go-to-C# workspace.
src/tests/Behavioral/ Per-feature Go↔C# equivalence tests (transpile, compile, run-and-compare).
src/tests/Performance/ Go vs transpiled C# runtime benchmarks (JIT and Native AOT) — see the performance comparison for current numbers.

To build the whole converted standard library in Visual Studio, open the Go Standard Library Solution. Neither solution names a startup project, because the .slnx format has no place for one: Visual Studio picks a class library (go.arrays today), and keeps your choice per user in .vs/. In src/go2cs.slnx, right-click a program, such as BehavioralRunner or any behavioral test, and choose Set as Startup Project. The standard library solution holds only libraries, so it has nothing to start.

In VS Code, open the repository root: the committed .vscode/settings.json selects src/go2cs.slnx as the C# Dev Kit’s solution (opening src/ selects it too), and Terminal > Run Build Task builds it. The Go extension’s language server leaves out the behavioral tests, the converted standard library, the archived examples and docs/, whose small Go modules would otherwise fill its views; open one of those folders on its own to work in it. The Go extension’s Test Explorer is turned off at the root, because it lists every go.mod it finds and has no setting to leave any out; run the converter’s tests with go test in src/go2cs, or with the run test link above each test function, or open src/go2cs on its own to get the Test Explorer back.

Contributing

Contributors: start with CONTRIBUTING.md, then see Architecture.md, ConversionStrategies.md and Roadmap.md for details.

The most useful help right now is running go2cs on your own Go code. When the C# fails to build, or behaves differently from Go, a small program that reproduces it makes the best issue. Known Issues and Limitations list what is already known. For anything sizable, start a Discussion first so we can agree on an approach.