mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-07-30 20:37:55 +00:00
gtk: build gtk4-layer-shell ourselves
As of now `gtk4-layer-shell` is unavailable on recent, stable releases of many distros (Debian 12, Ubuntu 24.04, openSUSE Leap & Tumbleweed, etc.) and outdated on many others (Nixpkgs 24.11/unstable, Fedora 41, etc.) This is inconvenient for our users and severely limits where the quick terminal can be used. As a result we then build gtk4-layer-shell ourselves by default unless `--system` or `-fsys=gtk4-layer-shell` are specified. This also allows me to add an idiomatic Zig API on top of the library and avoiding adding even more raw C code in the GTK apprt. Since we now build gtk4-layer-shell it should be theoretically available on all Linux systems we target. As such, the `-Dgtk-layer-shell` build option has been removed. This is somewhat of an experimental change as I don't know if gtk4-layer-shell works perfectly across all distros, and we can always add the option back if need be.
This commit is contained in:
@@ -34,7 +34,6 @@ font_backend: font.Backend = .freetype,
|
||||
/// Feature flags
|
||||
x11: bool = false,
|
||||
wayland: bool = false,
|
||||
layer_shell: bool = false,
|
||||
sentry: bool = true,
|
||||
wasm_shared: bool = true,
|
||||
|
||||
@@ -163,12 +162,6 @@ pub fn init(b: *std.Build) !Config {
|
||||
"Enables linking against X11 libraries when using the GTK rendering backend.",
|
||||
) orelse gtk_targets.x11;
|
||||
|
||||
config.layer_shell = b.option(
|
||||
bool,
|
||||
"gtk-layer-shell",
|
||||
"Enables linking against the gtk4-layer-shell library for quick terminal support. Requires Wayland.",
|
||||
) orelse gtk_targets.layer_shell;
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Ghostty Exe Properties
|
||||
|
||||
@@ -366,6 +359,7 @@ pub fn init(b: *std.Build) !Config {
|
||||
"libpng",
|
||||
"zlib",
|
||||
"oniguruma",
|
||||
"gtk4-layer-shell",
|
||||
}) |dep| {
|
||||
_ = b.systemIntegrationOption(
|
||||
dep,
|
||||
@@ -398,7 +392,6 @@ pub fn addOptions(self: *const Config, step: *std.Build.Step.Options) !void {
|
||||
step.addOption(bool, "flatpak", self.flatpak);
|
||||
step.addOption(bool, "x11", self.x11);
|
||||
step.addOption(bool, "wayland", self.wayland);
|
||||
step.addOption(bool, "layer_shell", self.layer_shell);
|
||||
step.addOption(bool, "sentry", self.sentry);
|
||||
step.addOption(apprt.Runtime, "app_runtime", self.app_runtime);
|
||||
step.addOption(font.Backend, "font_backend", self.font_backend);
|
||||
|
||||
@@ -484,7 +484,24 @@ pub fn add(
|
||||
step.root_module.addImport("wayland", wayland);
|
||||
step.root_module.addImport("gdk_wayland", gobject.module("gdkwayland4"));
|
||||
|
||||
if (self.config.layer_shell) step.linkSystemLibrary2("gtk4-layer-shell", dynamic_link_opts);
|
||||
const gtk4_layer_shell = b.dependency("gtk4_layer_shell", .{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
const layer_shell_module = gtk4_layer_shell.module("gtk4-layer-shell");
|
||||
layer_shell_module.addImport("gtk", gobject.module("gtk4"));
|
||||
step.root_module.addImport("gtk4-layer-shell", layer_shell_module);
|
||||
|
||||
// IMPORTANT: gtk4-layer-shell must be linked BEFORE
|
||||
// wayland-client, as it relies on shimming libwayland's APIs.
|
||||
if (b.systemIntegrationOption("gtk4-layer-shell", .{})) {
|
||||
step.linkSystemLibrary2("gtk4-layer-shell", dynamic_link_opts);
|
||||
} else {
|
||||
// gtk4-layer-shell *must* be dynamically linked,
|
||||
// so we don't add it as a static library
|
||||
step.linkLibrary(gtk4_layer_shell.artifact("gtk4-layer-shell"));
|
||||
}
|
||||
|
||||
step.linkSystemLibrary2("wayland-client", dynamic_link_opts);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,5 +51,6 @@ RUN ZIG_GLOBAL_CACHE_DIR=/zig/global-cache ./nix/build-support/fetch-zig-cache.s
|
||||
|
||||
COPY ./src /src/src
|
||||
|
||||
RUN zig build -Doptimize=Debug -Dcpu=baseline -Dapp-runtime=gtk --system /zig/global-cache/p
|
||||
# Debian 12 doesn't have gtk4-layer-shell, so we have to manually compile it ourselves
|
||||
RUN zig build -Doptimize=Debug -Dcpu=baseline -Dapp-runtime=gtk -fno-sys=gtk4-layer-shell --system /zig/global-cache/p
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ const std = @import("std");
|
||||
pub const Targets = packed struct {
|
||||
x11: bool = false,
|
||||
wayland: bool = false,
|
||||
layer_shell: bool = false,
|
||||
};
|
||||
|
||||
/// Returns the targets that GTK4 was compiled with.
|
||||
@@ -21,21 +20,8 @@ pub fn targets(b: *std.Build) Targets {
|
||||
const x11 = std.mem.indexOf(u8, output, "x11") != null;
|
||||
const wayland = std.mem.indexOf(u8, output, "wayland") != null;
|
||||
|
||||
const layer_shell = layer_shell: {
|
||||
if (!wayland) break :layer_shell false;
|
||||
|
||||
_ = b.runAllowFail(
|
||||
&.{ "pkg-config", "--exists", "gtk4-layer-shell-0" },
|
||||
&code,
|
||||
.Ignore,
|
||||
) catch break :layer_shell false;
|
||||
|
||||
break :layer_shell true;
|
||||
};
|
||||
|
||||
return .{
|
||||
.x11 = x11,
|
||||
.wayland = wayland,
|
||||
.layer_shell = layer_shell,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user