Purego is a library for calling C functions from Go without Cgo.
Purego solves the problem of cross-platform compilation and binary size by enabling Go programs to invoke C functions directly without requiring a C compiler or generating wrapper functions. It works by using assembly code to handle the calling conventions and argument passing for different architectures, allowing dynamic symbol loading at runtime. This approach eliminates the need for Cgo's C wrapper generation while maintaining compatibility across multiple platforms and architectures.
Purego suits projects that need to call C libraries but want simpler cross-compilation workflows, faster builds, and smaller binaries. It is particularly valuable for game engines and other applications targeting multiple platforms where avoiding C compiler dependencies streamlines the build process. The tool includes a Cgo fallback mode, allowing incremental porting of existing Cgo-based code. Tier 1 support covers the primary targets including Linux, macOS, Windows, iOS, and Android on common architectures, while Tier 2 extends support to less common architectures and operating systems on a best-effort basis. Some architectures have limitations: struct-by-value passing is not supported on several Tier 2 platforms, and a few architectures support only specific function types like SyscallN and NewCallback.
The project maintains clear separation between Tier 1 and Tier 2 platforms, treating critical bugs on primary targets as release blockers while accepting contributed fixes for secondary platforms. Development acknowledges the beta status of the software and encourages bug reports, with each release tagged to prevent breaking changes to existing code.