ebitengine / purego
git clone https://github.com/ebitengine/purego.git
v0.11.2 · 4d ago
🔥 on GitHub Trending today
A library for calling C functions from Go without Cgo
+0
stars, 24h · #15,375
+~0
stars, 7 days · #15,913
+86
stars, 30 days · #6,199
4.0k
★ total
135
forks · 35 open issues
Star history (as recorded here)
LanguageAssembly
LicenseApache-2.0
Created2022-05-14 (4y ago)
Last push4d ago
Watchers28
OwnerOrganization
Seen on GitHub Trending
- 2026-10-22 — #4 daily in assembly · +2 ★
- 2026-10-22 — #15 monthly in assembly · +83 ★
- 2026-10-22 — #8 weekly in assembly · +12 ★
- 2026-10-21 — #5 daily in assembly
- 2026-10-21 — #13 monthly in assembly · +86 ★
- 2026-10-20 — #5 daily in assembly
- 2026-10-20 — #13 monthly in assembly · +86 ★
GitHub topics
Links
README excerpt
# purego A library for calling C functions from Go without Cgo. > This is beta software so expect bugs and potentially API breaking changes > but each release will be tagged to avoid breaking people's code. > Bug reports are encouraged. ## Motivation The Ebitengine game engine was ported to use only Go on Windows. This enabled cross-compiling to Windows from any other operating system simply by setting `GOOS=windows`. The purego project was born to bring that same vision to the other platforms supported by Ebitengine. ## Benefits - **Simple Cross-Compilation**: No C means you can build for other platforms easily without a C compiler. - **Faster Compilation**: Efficiently cache your entirely Go builds. - **Smaller Binaries**: Using Cgo generates a C wrapper function for each C function called. Purego doesn't! - **Dynamic Linking**: Load symbols at runtime and use it as a plugin system. - **Foreign Function Interface**: Call into other languages that are compiled into shared objects. - **Cgo Fallback**: Works even with CGO_ENABLED=1 so incremental porting is possible. This also means unsupported GOARCHs (freebsd/riscv64, linux/mips, etc.) will still work except for float arguments and return values. ## Supported Platforms ### Tier 1 Tier 1 platforms are the primary targets officially supported by PureGo. When a new version of PureGo is released, any critical bugs found on Tier 1 platforms are treated as release blockers. The release will be postponed until such issues are resolved. - **Android**: amd64 1 , arm64 1 - **iOS**: amd64 1 , arm64 1 - **Linux**: amd64, arm64 - **macOS**: amd64, arm64 - **Windows**: amd64 2 , arm64 2 ### Tier 2 Tier 2 platforms are supported by PureGo on a best-effort basis. Critical bugs on Tier 2 platforms do not block new PureGo releases. However, fixes contributed by external contributors are very welcome and encouraged. - **Android**: 386 1,3 , arm 1,3 - **FreeBSD**: amd64 3,4 , arm64 3,4 - **Linux**: 386 3 , arm 3 , loong64 2 , ppc64le 2 , riscv64 3 , s390x 3, 5 - **NetBSD**: amd64 3 , arm64 3 - **Windows**: 386 3,6 , arm 3,6,7 #### Support Notes 1. These architectures require CGO_ENABLED=1 to compile 2. These architectures support passing structs by value as arguments and return values when calling C functions, but not in callbacks created with `NewCallback` 3. These architectures do not support passing structs by value as arguments or return values 4. These architectures require the special flag `-gcflags="github.com/ebitengine/purego/internal/fakecgo=-std"` to compile with CGO_ENABLED=0 5. These architectures require CGO_ENABLED=1 to compile in versions before Go 1.27, but will be supported without Cgo in Go 1.27 and later 6. These architectures only support `SyscallN` and `NewCallback` 7. These architectures are no longer supported as of Go 1.26 ## Example The example below only showcases purego use for macOS and Linux. The other platforms require special handling which can be seen in the complete exampl