gtk4-builder-tool validate and libadwaita
Hello, I'm willing to do a bit of work to get this going and was interested in the GTK devs' views.
I've been using gtk4-builder-tool
with Flycheck to help with writing UI builder files. However, third-party libraries like libadwaita don't work with the tool.
I'm sure this issue is familiar to you all, I've had a look at #5232 (closed) to try to get some background. It would be nice to have a solution that works as broadly as possible, but I'm particularly interesting in supporting libadwaita due to its importance in the GNOME ecosystem.
Firstly, using a build with !5541 (merged) and LD_PRELOADing libadwaita, along with hacking gtk4-builder-tool
to call adw_init, does seem to work. Files can then be validated properly.
Perhaps it would be useful to leverage the "requires" element? I note the comment in gtkbuilderparser.c:2046 about the possibility of some future enhancement in this direction re: custom widget libraries.
Here's an initial idea from me:
- I noted Emmanuele's suggestion in the MR about using GIR files. Could we redefine the
requires
element to say that thelib
attribute should refer to a valid GIR namespace? - Assuming this is ok, we could by some means make sure this information gets to
gtk4-builder-tool
during parsing. I would be interested in your views as to the best way.gtk4-builder-tool
could then load any shared libraries defined in the referenced GI typelib. - After this, we're left with the issue of how to initialise libraries like
libadwaita
, which needs its call toadw_init
. One possibility is to define an API interface forgtk4-builder-tool
, for example, looking for a symbol calledadw_gtk_builder_tool_on_validate
, and calling that function if it's found. We then ask libadwaita to implement this function.
This leaves several problems still not covered:
- Custom widgets written in languages other than C.
- Widget libraries not having GI typelibs.
- Custom widgets defined in the application exe.
On the last point, I actually think it's not too bad to ask applications to make use of a separate shared library and generate GI typelib data if they wish to integrate their custom widgets with gtk4-builder-tool
. That seems like a reasonable solution to me.
The other cases will still be outstanding, but this solution could be a good step forward. What do you think?