Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gtk: add option to not link against libX11 #3748

Merged
merged 5 commits into from
Dec 28, 2024
Merged

Conversation

jcollie
Copy link
Collaborator

@jcollie jcollie commented Dec 28, 2024

Possible fix for #3477. Needs testing.

@tristan957
Copy link
Collaborator

tristan957 commented Dec 28, 2024

Does the zig build system have a notion of Meson's feature options where you can detect if GTK was built without X11, and then build ghostty without X11 support too? Essentially, just automatically do the right thing.

build.zig Outdated
config.x11 = b.option(
bool,
"gtk-x11",
"Enables the linking against X11 libraries when using the GTK rendering backend.",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"Enables the linking against X11 libraries when using the GTK rendering backend.",
"Enables linking against X11 libraries when using the GTK rendering backend.",

Comment on lines 15 to 22

#ifndef False
#define False 0
#endif

#ifndef True
#define True 1
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Somewhere in <gdk/x11/gdkx.h> or <X11/XKBlib.h> C macros for True and False get defined and they are used in a couple of places in gtk/Window.zig and gtk/Surface.zig. I suppose it would be just as easy to replace the uses in the Zig code.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I would recommend that

@jcollie
Copy link
Collaborator Author

jcollie commented Dec 28, 2024

Does the zig build system have a notion of Meson's feature options where you can detect if GTK was built without X11, and then build ghostty without X11 support too? Essentially, just automatically do the right thing.

If there's a command that we can run to determine if GTK was built without X11, we should be able to take advantage of that in build.zig. I'm not aware of a native feature in Zig that does that.

@tristan957
Copy link
Collaborator

$ pkg-config --variable=targets gtk4
broadway wayland x11

@tristan957
Copy link
Collaborator

pkgconf is also another tool for querying, so you may want to check both. Not sure if pkg-config is guaranteed to exist.

@mitchellh
Copy link
Contributor

mitchellh commented Dec 28, 2024

Ghostty already requires pkg-config to build so it’s fine to rely on it. If it’s unavailable we can just assume x11 is available

@jcollie
Copy link
Collaborator Author

jcollie commented Dec 28, 2024

pkgconf is also another tool for querying, so you may want to check both. Not sure if pkg-config is guaranteed to exist.

Pretty sure that the Zig build system requires pkg-config to exist to find system libraries, so I think that we can depend on it being available.

@tristan957
Copy link
Collaborator

Even better!

@jcollie
Copy link
Collaborator Author

jcollie commented Dec 28, 2024

$ pkg-config --variable=targets gtk4
broadway wayland x11

That should be easy enough to check for.

@jcollie
Copy link
Collaborator Author

jcollie commented Dec 28, 2024

OK, the latest commit should detect X11 support in GTK4 but I don't have a system handy that has GTK4 without X11 support. I thought it would be possible to set that up in the devshell but I wasn't able to get that to work.

So if someone has a system without X11 installed it would be great if they can test it out.

@mitchellh
Copy link
Contributor

This looks good to me. I want to make a couple stylistic tweaks but this is well done!

@mitchellh mitchellh added this to the 1.0.1 milestone Dec 28, 2024
@jcollie jcollie marked this pull request as ready for review December 28, 2024 20:49
@mitchellh
Copy link
Contributor

Moved the GTK tests to a matrix. If that's good will merge.

Comment on lines 343 to 345
adwaita: ["true", "false"]
x11: ["true", "false"]
runs-on: namespace-profile-ghostty-md
Copy link
Collaborator

@tristan957 tristan957 Dec 28, 2024

Choose a reason for hiding this comment

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

I would suggest using enum like strings. Otherwise you won't know which job failed because it will look like test-gtk(true, false) or something.

adwaita: ["with-adwaita", "without-adwaita"]
x11: ["with-x11", "without-x11"]

Copy link
Contributor

Choose a reason for hiding this comment

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

I just named them using the name: key. Is there some other way? That's what I'm used to doing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is just a UX problem in my opinion of GitHub that have to be worked around. No biggie

@mitchellh mitchellh merged commit 5293fc9 into ghostty-org:main Dec 28, 2024
21 checks passed
mitchellh added a commit that referenced this pull request Dec 29, 2024
As a follow-up to #3477 and #3748, this eliminates the use of dlopen to
access `libX11` functions by directly linking `libX11` if X11 is
enabled. This should also fix problems with systems like NixOS and Void
Linux that have reported problems using Ghostty on X11 when using the
distribution packages.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants