Include Glib not entire GTK crate in Cargo.toml

Hello,

my lib works with following components only:

use gtk::glib::{TimeZone, Uri, UriFlags};

but dependency in Cargo.toml requires entire GTK component:

[dependencies.gtk]
package = "gtk4"
version = "0.9.1"

Interesting, can I define glib components only in Cargo.toml,
to not compile entire the gtk4 binary with other components?

Or maybe another, glib-oriented crate available for these needs

gtk4::glib is just a re-export of the glib crate, so you can just add glib = "0.20" to your dependency list instead of gtk4.

In general however if it was an actual module and not a re-export then this would not be possible.

1 Like

Thanks, just one problem with Uri import:

use glib::{/* ... */ Uri, UriFlags};
unresolved imports `glib::Uri`, `glib::UriFlags`
no `Uri` in the root
[dependencies]
glib = "0.20.4"

any ideas?

Found the reason:

Available on crate feature v2_66 only

Fixed with:

[dependencies.glib]
package = "glib"
version = "0.20.4"
features = ["v2_66"]

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.