Lighter builds
No C toolchain, no development headers, no cgo build tags. If Go builds on the machine, the binding builds too — including on minimal containers.
CGO-free Go bindings
CGO-free Go bindings by metal3d
Go bindings for system libraries that avoid cgo. They call into C at runtime through github.com/ebitengine/purego, so the Go toolchain builds your program like any other Go program.
$ go get metal3d.org/purego/gtk4@v0.8.0
go: added metal3d.org/purego/gtk4 v0.8.0
$ go build ./cmd/app
✓ built — gcc was never invoked
# GTK4 is loaded at runtime
purego is a library that lets Go code call C
functions without cgo. At startup it opens a shared library with
dlopen, resolves the symbols it needs, and takes care
of the platform ABI when calling them. The binding packages on this
site build on that mechanism.
The result is a normal Go package: no C compiler, no C headers, no
pkg-config and no cgo at build time. For the GTK,
GLib, Pango and GStreamer bindings, GIR definitions drive the
generator; irregular APIs are wrapped by hand. Other libraries can
be bound from a different API description or written by hand.
Your code imports idiomatic Go types and functions. The C library is still there — it is simply loaded when the program runs instead of being linked when the program is built.
cgo is powerful, but it turns every consumer of a library into a C-toolchain problem. These bindings move that complexity out of the build.
No C toolchain, no development headers, no cgo build tags. If Go builds on the machine, the binding builds too — including on minimal containers.
Plain go get, ordinary Go modules, no special flags.
No build matrix that exists only to provide different C
environments.
You ship a normal Go binary. Cross-compilation is easier and CI images no longer need a full set of dev packages just to compile the bindings.
Runtime requirement: the target shared libraries
are still required at runtime. A program using the GTK4 bindings
needs GTK4 and Adwaita, plus WebKit 6 when it uses the
webkit package; the GStreamer bindings need
GStreamer. This removes the build-time C dependency, not
the runtime library.
Stable import paths under metal3d.org/purego, backed by
public repositories on git.metal3d.org/purego.
GStreamer bindings: pipelines, elements, buses and the core GObject/GStreamer types, without cgo in your build.
$ go get metal3d.org/purego/gst@v0.3.0
GTK4, Adwaita and WebKit 6 bindings: widgets, application lifecycle, GObject signals, libadwaita and embedded web views.
$ go get metal3d.org/purego/gtk4@v0.8.0
The purego organisation is a growing collection of Go
bindings, not just these two. New modules follow the same import
path and repository layout.
go get resolves these paths through the
go-import metadata served on this host, then fetches the
module from its public Git repository.
Two programs built with gtk4-purego: a WebKit 6 web
view and the GTK4 / Adwaita widget gallery.
webkit package.
gtk and adw packages.Both examples live in the gtk4-purego repository.
From a C library description to a typed Go call, with no C compiler in the chain.
metal3d.org/purego/gtk4,
versioned with ordinary Go modules.
dlopen
github.com/ebitengine/purego loads the system library
and binds its symbols.
libgtk-4.so, libgstreamer-1.0.so and their
dependencies, installed on the host.
Build time stays pure Go; the C library enters the picture only when the program runs.
These bindings are usable today, but they are not pretending to be finished.
The APIs may still evolve between minor versions. Pin versions in production and read the release notes before upgrading.
GStreamer and GTK4 are the first modules. Additional system
libraries will join the purego organisation over time.
Existing cgo-based bindings expose different APIs. Expect to adapt code rather than swap an import path and rebuild.
Deployment still needs the target shared libraries on the target system. The gain is at build time, not a way to avoid installing GTK or GStreamer.