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

**URL:** <https://ziggit.dev/t/zig-gobject-gobject-gtk-etc-bindings-for-zig/3306>\
**Category:** Showcase\
**Created:** [February 19, 2024, 7:52pm UTC](https://ziggit.dev/t/zig-gobject-gobject-gtk-etc-bindings-for-zig/3306 "2024-02-19T19:52:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ianprime0509](https://ziggit.dev/user_avatar/ziggit.dev/ianprime0509/32/1226_2.png) [@ianprime0509](https://ziggit.dev/u/ianprime0509)\
**Post date:** [February 19, 2024, 7:52pm UTC](https://ziggit.dev/t/zig-gobject-gobject-gtk-etc-bindings-for-zig/3306/1 "2024-02-19T19:52:11Z")

</div>

[zig-gobject](https://github.com/ianprime0509/zig-gobject) is a project to generate Zig bindings to GObject, GTK, and a bunch of other libraries using [GObject introspection](https://gitlab.gnome.org/GNOME/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](https://github.com/ianprime0509/zig-gobject/blob/main/doc/binding-strategy.md) on the binding strategy in the repository.

There is more documentation and an example project in the repository, and my [Nonograms](https://github.com/ianprime0509/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](https://github.com/ianprime0509/zig-gobject/issues). 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](https://github.com/ianprime0509/zig-gobject/pull/29) 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](https://github.com/ianprime0509/org.freedesktop.Sdk.Extension.ziglang-master) 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.

---

<div class="post-metadata">

**Author:** ![Durobot](https://ziggit.dev/user_avatar/ziggit.dev/durobot/32/447_2.png) [@Durobot](https://ziggit.dev/u/Durobot)\
**Post date:** [February 20, 2024, 11:16am UTC](https://ziggit.dev/t/zig-gobject-gobject-gtk-etc-bindings-for-zig/3306/2 "2024-02-20T11:16:25Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![ianprime0509](https://ziggit.dev/user_avatar/ziggit.dev/ianprime0509/32/1226_2.png) [@ianprime0509](https://ziggit.dev/u/ianprime0509)\
**Post date:** [February 21, 2024, 5:10am UTC](https://ziggit.dev/t/zig-gobject-gobject-gtk-etc-bindings-for-zig/3306/3 "2024-02-21T05:10:15Z")

</div>

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](https://docs.gtk.org/gobject/concepts.html) 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.

---

<div class="post-metadata">

**Author:** ![jmc](https://ziggit.dev/user_avatar/ziggit.dev/jmc/32/38_2.png) [@jmc](https://ziggit.dev/u/jmc)\
**Post date:** [July 21, 2024, 12:55pm UTC](https://ziggit.dev/t/zig-gobject-gobject-gtk-etc-bindings-for-zig/3306/4 "2024-07-21T12:55:43Z")

</div>

This is what I deserve for losing sight of the forums for a while… I was just writing my own version of this, when I discovered that this project exists and is in much better shape 😆

Well done, this looks fantastic 👍

---

<div class="post-metadata">

**Author:** ![dude\_the\_builder](https://ziggit.dev/user_avatar/ziggit.dev/dude_the_builder/32/557_2.png) [@dude\_the\_builder](https://ziggit.dev/u/dude_the_builder)\
**Post date:** [July 21, 2024, 2:05pm UTC](https://ziggit.dev/t/zig-gobject-gobject-gtk-etc-bindings-for-zig/3306/5 "2024-07-21T14:05:11Z")

</div>

> [@jmc](#):
>
> This is what I deserve for losing sight of the forums for a while

It’s been too long @jmc ! Nice to see you 'round here again.
