The name ‘gtk-rs’, like ‘gtk-doc’, is a bit of a misdirect. Whilst the project’s main goal is Gtk bindings it’s really a system for building rust crates wrapping GLib-style libraries via gobject-introspection. Much of the work is done by the
gir3 4 tool which both generates the low-level C ffi and automates most of the high-level binding – with the notable exception of subclass support.
Fortunately, we can look at the Gtk4 bindings for help, I found layout_manager.rs to be a useful example – one gotcha to watch out for is vfuncs, especially signals, as they don’t necessarily have a default implementation
Unfortunatly gtk-rs doesn’t have any magic for generating introspection data (yet?) so we follow rsvg’s example and manually build C-ABI wrappers along with a hand-written header to use with
g-ir-scanner – handle.rs is a useful resource when doing this.
Happy multi-language hacking 🙂
- This was orignally an minimal reproducer, turns out I was just being silly
- Of course it doesn’t have to be GJS, PyGObject etc should work as well
- You could think of it as a high-level (and specialised) version of bindgen
- The name is a tad confusing and may change
Thanks to Bilal, Jordan, Chris, Sebastian, and others for their tips/fixes and/or rubber ducking as well as the wider gtk-rs/g-i communities who build this tooling