gtk-rs / gir

Tool to generate rust bindings and user API for glib-based libraries
https://gtk-rs.org/gir/book/
MIT License
230 stars 102 forks source link

How to fix libgir::parser warning with GTK4? #1456

Closed pentamassiv closed 1 year ago

pentamassiv commented 1 year ago

I am generating -sys bindings for the newly released gtk4-layer-shell. My repo can be found here. Unfortunately I get a warning that I don't understand. When I run gir -o ., it returns:

[WARN  libgir::parser] <boxed name=Some("TreeRowData")>

This doesn't say much about what the problem is and I was unable to find any related issues. I guess it has to do with the Gtk-4.0.gir file, since it is the only file that contains TreeRowData. The generated bindings seem to work just fine.

Is there something I can do to fix the problem causing the warning?

jf2048 commented 1 year ago

This is not your fault, it happens because the gir parser doesn't support <glib:boxed> elements. The only real effects are gtk4-rs missing a binding for GtkTreeRowData and other bindings cannot reference that type. But that type is deprecated and nothing seems to use it anyway, so nobody fixed it.

I guess it should be able to support that by generating them the same as an opaque <record>? I only see a few other places with those.

jf2048 commented 1 year ago

After a discussion about this on matrix I think it may make sense to turn these types into something like

pub struct TreeRowData(std::marker::PhantomData<()>);

impl StaticType for TreeRowData {
    // ...
}

So you can get the type but you can't construct the object. Or, just get rid of the warning by not supporting them at all, they are rarely used...

pentamassiv commented 1 year ago

Okay, thank you very much for your reply. I'll think about how to handle this in my bindings.

I am satisfied with your reply, so feel free to close this

jf2048 commented 1 year ago

You don't need to do anything in your bindings unless the gir has one of those glib:boxed types, which Gtk4LayerShell doesn't. I made a PR to just disable the warning