Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

gdk_backend config flags #995

Merged
merged 3 commits into from
May 1, 2020
Merged

Conversation

kinnison
Copy link
Contributor

@kinnison kinnison commented May 1, 2020

This is a proposed approach for better handling of targets. The pkg-config file defines a targets variable which is whitespace separated. This PR consumes that in build.rs and sets target="x11" and friends as config values.

To demonstrate its use, this then switches gtk::Plug and gtk::Socket to be predicated on target="x11" rather than all(not(windows), not(target_os = "macos"))

@sdroege What do you think of this as an approach? If considered good, it should probably be spread to gtk-sys and possibly other crates.

Gir.toml Outdated
@@ -1535,7 +1535,7 @@ status = "generate"
[[object]]
name = "Gtk.Plug"
status = "generate"
cfg_condition = "all(not(windows),not(target_os = \"macos\"))"
cfg_condition = "target = \"x11\""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know you could define your own targets 😮

We should also do the same with gio-unix and things like that I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean re gio-unix since this is mostly a gdk/gtk thing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a similar problem with GIO (and GLib) about Windows/POSIX/Linux specific APIs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aah, I don't think gio exports such info in their pkg-config but perhaps there's a different way to discover it for that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate pkg-config files

@sdroege
Copy link
Member

sdroege commented May 1, 2020

Looks like a good solution to me, only makes it more confusing for users if they want to use the API but it does not exist because of their GTK version. With a feature flag we could print some more useful error if the user tries to enable it but it does not exist.

This adds a gdk_backend="x11" etc set of flags
which can be used in #[cfg] checks.

Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
@kinnison kinnison changed the title Target feature flags gdk_backend config flags May 1, 2020
@kinnison
Copy link
Contributor Author

kinnison commented May 1, 2020

I've changed the config to gdk_backend="x11" and friends, since that seems more descriptive. I've also added explanatory notes in build.rs

Copy link
Member

@GuillaumeGomez GuillaumeGomez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome!

@GuillaumeGomez GuillaumeGomez self-requested a review May 1, 2020 10:19
Copy link
Member

@GuillaumeGomez GuillaumeGomez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome!

@GuillaumeGomez GuillaumeGomez merged commit 06466b7 into gtk-rs:master May 1, 2020
@kinnison kinnison deleted the x11-features branch May 1, 2020 15:51
@EPashkin
Copy link
Member

EPashkin commented May 1, 2020

Is there no way to add it to gdk-sys?

@kinnison
Copy link
Contributor Author

kinnison commented May 2, 2020

@EPashkin Yes, the same work ought to work for gdk-sys if you want to use the capability there for any reason.

@EPashkin
Copy link
Member

EPashkin commented May 3, 2020

I want detect flags in gdk-sys and use it here

@kinnison
Copy link
Contributor Author

kinnison commented May 3, 2020

@EPashkin Aaah, right, to my knowledge it's not possible for crates to acquire configuration flags from their dependencies. If you know of a way to do this, I'm happy to rework it.

@EPashkin
Copy link
Member

EPashkin commented May 3, 2020

I thought about something like "DEP_GDK_BACKEND" from https://doc.rust-lang.org/cargo/reference/build-scripts.html#the-links-manifest-key
It should works if gtk depends of gdk-sys directly and need "build.rs" in "gtk" too.

@kinnison
Copy link
Contributor Author

kinnison commented May 3, 2020

Oh that's interesting, I shall look at doing that because yes, that makes a lot of sense. I think gdk-sys should compute them gtk-sys should propagate them, and gtk can then consume them. Hmm...

@kinnison
Copy link
Contributor Author

kinnison commented May 3, 2020

I've pushed the first part of that new variant here - gtk-rs/sys#167
Once that merges, I'll pop a PR up for replacing this calculating with inheriting it from gtk-sys

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants