Zig-gobject: GObject, GTK, etc. bindings for Zig

zig-gobject is a project to generate Zig bindings to GObject, GTK, and a bunch of other libraries using GObject introspection metadata. This metadata gives much richer information about the associated APIs than their C header files, including type nullability, class hierarchy, signals, and more, allowing safer and more usable bindings to be created than what zig translate-c can provide.

The generated bindings are supplemented with some extensions to make common tasks simpler, such as defining new classes in the GObject type system. For a more detailed overview of how the bindings are structured, there is documentation on the binding strategy in the repository.

There is more documentation and an example project in the repository, and my Nonograms application uses these bindings and provides a more complete example of how they can be integrated into a real project.

My plans for the future of this project include a bunch of stuff detailed in the issue tracker. In particular,

  1. Documentation: more detailed documentation for how to use the bindings in a real project, and a tutorial for users unfamiliar with GTK or C programming. I’d also like to publish API documentation, but my initial attempts at using Autodoc for this have failed. I have some nebulous ideas around improving Zig documentation tooling which I may explore to help with this.

  2. Ecosystem tooling: once Zig 0.12 is released, I’d like to get a more stable development environment set up using Flatpak (my ziglang-master Flatpak is a stop-gap solution which I don’t want to maintain in the long term) and focus on how to provide all the tools and build setup needed by real projects (Flatpak creation, internationalization, etc.).

  3. Continued expansion of extension functionality to make more use-cases easier.

Side note: this was actually one of the first Zig projects I started on, but it’s only become really usable recently due to the fantastic improvements in the Zig build system and package manager. Thank you to all their contributors for making this project possible.


Now here’s a project I myself wouldn’t dare even approach.

A year and a half ago I tried digging into GTK (and then GObject, on which GTK is based) to figure out how it works, to figure out a way of using it from another language.

It was a macro jungle, a preprocessor nightmare.

You sir are far braver (and I guess far more knowledgeable) than me, and I salute you!


Thank you! The macros were (and still are) definitely hard to get through and figure out in Zig. This documentation helped a lot in understanding how the type system works and what a lot of those macros are doing: GObject – 2.0: Type System Concepts I’m still definitely no expert with GObject or GTK, but having a detailed reference for how things work under the hood makes it a lot easier.

1 Like