mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-09-05 19:08:17 +00:00
pkg(gtk4-layer-shell): Enable using system-installed headers for dynamic linking (#6624)
I noticed we weren't doing system-integration against the pkgconfig for gtk4-layer-shell. This behaviour differed from how we handled system integration for existing deps in `pkg/` (oniguruma, fontconfig). Refactored `pkg/gtk4-layer-shell/build.zig` referencing `pkg/oniguruma/build.zig` to use pkgconfig names in system integration. Previously we used to libname `libgtk4-layer-shell.so` (`gtk4-layer-shell`) instead of pkgconfig name `gtk4-layer-shell-0.pc` which meant system integration still relied on fetching the C-headers via `zig fetch` instead of system C-headers. I've tested this with a `--system` build where the relevant `.zig-cache/p/<hash of gtk4-layer-shell>` is stubbed to an empty directory and `pkgconfig(gtk4-layer-shell-0)` is installed instead on fedora linux.
This commit is contained in:
@@ -3,23 +3,40 @@ const std = @import("std");
|
||||
// TODO: Import this from build.zig.zon when possible
|
||||
const version: std.SemanticVersion = .{ .major = 1, .minor = 1, .patch = 0 };
|
||||
|
||||
const dynamic_link_opts: std.Build.Module.LinkSystemLibraryOptions = .{
|
||||
.preferred_link_mode = .dynamic,
|
||||
.search_strategy = .mode_first,
|
||||
};
|
||||
|
||||
pub fn build(b: *std.Build) !void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const upstream = b.dependency("gtk4_layer_shell", .{});
|
||||
const wayland_protocols = b.dependency("wayland_protocols", .{});
|
||||
|
||||
// Zig API
|
||||
const module = b.addModule("gtk4-layer-shell", .{
|
||||
.root_source_file = b.path("src/main.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
module.addIncludePath(upstream.path("include"));
|
||||
// Needs the gtk.h header
|
||||
module.linkSystemLibrary("gtk4", dynamic_link_opts);
|
||||
|
||||
if (b.systemIntegrationOption("gtk4-layer-shell", .{})) {
|
||||
module.linkSystemLibrary("gtk4-layer-shell-0", dynamic_link_opts);
|
||||
} else {
|
||||
_ = try buildLib(b, module, .{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn buildLib(b: *std.Build, module: *std.Build.Module, options: anytype) !*std.Build.Step.Compile {
|
||||
const target = options.target;
|
||||
const optimize = options.optimize;
|
||||
|
||||
const upstream = b.dependency("gtk4_layer_shell", .{});
|
||||
const wayland_protocols = b.dependency("wayland_protocols", .{});
|
||||
// Shared library
|
||||
const lib = b.addSharedLibrary(.{
|
||||
.name = "gtk4-layer-shell",
|
||||
@@ -29,6 +46,7 @@ pub fn build(b: *std.Build) !void {
|
||||
lib.linkLibC();
|
||||
lib.addIncludePath(upstream.path("include"));
|
||||
lib.addIncludePath(upstream.path("src"));
|
||||
module.addIncludePath(upstream.path("include"));
|
||||
|
||||
// GTK
|
||||
lib.linkSystemLibrary2("gtk4", dynamic_link_opts);
|
||||
@@ -76,6 +94,16 @@ pub fn build(b: *std.Build) !void {
|
||||
.{ .include_extensions = &.{".h"} },
|
||||
);
|
||||
|
||||
// Certain files relating to session lock were removed as we don't use them
|
||||
const srcs: []const []const u8 = &.{
|
||||
"gtk4-layer-shell.c",
|
||||
"layer-surface.c",
|
||||
"libwayland-shim.c",
|
||||
"registry.c",
|
||||
"stolen-from-libwayland.c",
|
||||
"stubbed-surface.c",
|
||||
"xdg-surface-server.c",
|
||||
};
|
||||
lib.addCSourceFiles(.{
|
||||
.root = upstream.path("src"),
|
||||
.files = srcs,
|
||||
@@ -87,20 +115,5 @@ pub fn build(b: *std.Build) !void {
|
||||
});
|
||||
|
||||
b.installArtifact(lib);
|
||||
return lib;
|
||||
}
|
||||
|
||||
// Certain files relating to session lock were removed as we don't use them
|
||||
const srcs: []const []const u8 = &.{
|
||||
"gtk4-layer-shell.c",
|
||||
"layer-surface.c",
|
||||
"libwayland-shim.c",
|
||||
"registry.c",
|
||||
"stolen-from-libwayland.c",
|
||||
"stubbed-surface.c",
|
||||
"xdg-surface-server.c",
|
||||
};
|
||||
|
||||
const dynamic_link_opts: std.Build.Module.LinkSystemLibraryOptions = .{
|
||||
.preferred_link_mode = .dynamic,
|
||||
.search_strategy = .mode_first,
|
||||
};
|
||||
|
@@ -506,7 +506,7 @@ pub fn add(
|
||||
// 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);
|
||||
step.linkSystemLibrary2("gtk4-layer-shell-0", dynamic_link_opts);
|
||||
} else {
|
||||
// gtk4-layer-shell *must* be dynamically linked,
|
||||
// so we don't add it as a static library
|
||||
|
Reference in New Issue
Block a user