
goffi: Zero-CGO Foreign Function Interface for Go — How We Call C Libraries Without a C Compiler
Every Go developer who has worked with C libraries knows the pain: CGO requires a C compiler, breaks cross-compilation, bloats binaries, and adds ~200ns overhead per call. For our WebGPU bindings and ML framework , calling wgpu-native through CGO was a non-starter — we needed to ship a single static binary across Windows, Linux, and macOS without requiring users to install gcc. So we built goffi — a pure Go FFI library that calls C functions through hand-written assembly, with zero C dependencies and zero per-call allocations. It now powers an entire ecosystem: go-webgpu/webgpu bindings, born-ml/born ML framework, and the GoGPU GPU computing platform with dual Rust and pure Go backends. This article explains the architecture, the hard problems we solved, how goffi compares to purego, and how you can use it in your own projects. The Problem Our stack looks like this: Go application (gogpu) └─ wgpu bindings (gogpu/wgpu) ← needs to call C functions └─ goffi ← this library └─ wgpu-native (
Continue reading on Dev.to
Opens in a new tab


