mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-09-03 21:00:27 +00:00
This fixes regressions in the flatpak/snap builds, and knock-on stuff that was discovered as as a result: * Update the Zig versions in the flatpak/snap build configuration files. * Restore the classic -Dpatch-rpath option, and add a new -Dpatch-interp option. This ensures that the snap can still use -Dpatch-rpath correctly. * There seems to be an issue in Zig when parsing IPv6 addresses that leads to issues loading resolv.conf files; when trying to load a nameserver that has an IPv6 address with a numeric interface index as the scoped zone ID, Zig will try to resolve the interface as a name rather than just use the index. This is coming up in snap builds because the build process seems to, by default, use the exhaustive /run/systemd/resolve/resolv.conf file, versus the simpler stub (stub-resolv.conf) file. We work around this for the time being by linking the stub at the end of the Zig part, overwriting the link to the non-stub file. * Fixed gtk4-layer-shell packaging - the migration to external translate-c meant that non-system builds of the dependency were not handing the local gtk4-layer-shell headers over for translation. Now, instead, we've extracted the management of the gtk4-layer-shell source and wayland-protocols generation to a locally-cached object so that the source can be shared by both C translation and the library build in a way that is not coupled to any particular step.
181 lines
6.3 KiB
Zig
181 lines
6.3 KiB
Zig
const std = @import("std");
|
|
|
|
const version = @import("build.zig.zon").version;
|
|
|
|
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(.{});
|
|
|
|
// Zig API
|
|
const module = b.addModule("gtk4-layer-shell", .{
|
|
.root_source_file = b.path("src/main.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
|
|
translate: {
|
|
const translate_c = b.lazyImport(@This(), "translate_c") orelse break :translate;
|
|
const translate_c_dep = b.lazyDependency("translate_c", .{}) orelse break :translate;
|
|
const Translator = translate_c.Translator;
|
|
|
|
const link_system_libs_full: [2]Translator.LinkSystemLib = .{
|
|
.{ .name = "gtk4", .options = dynamic_link_opts },
|
|
.{ .name = "gtk4-layer-shell-0", .options = dynamic_link_opts },
|
|
};
|
|
|
|
const headers = Translator.init(translate_c_dep, .{
|
|
.c_source_file = b.addWriteFiles().add("c.h",
|
|
\\#include <gtk4-layer-shell.h>
|
|
),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.link_system_libs = if (b.systemIntegrationOption("gtk4-layer-shell", .{}))
|
|
&link_system_libs_full
|
|
else
|
|
link_system_libs_full[0..1],
|
|
});
|
|
|
|
if (!b.systemIntegrationOption("gtk4-layer-shell", .{})) {
|
|
// local deps (non-system layer-shell/wayland)
|
|
const deps = try LocalDeps.get(b) orelse break :translate;
|
|
headers.addIncludePath(deps.upstream.path("include"));
|
|
headers.addIncludePath(deps.upstream.path("src"));
|
|
headers.addIncludePath(deps.client_header_directory);
|
|
}
|
|
|
|
module.addImport("c", headers.mod);
|
|
}
|
|
|
|
if (!b.systemIntegrationOption("gtk4-layer-shell", .{})) {
|
|
_ = try buildLib(b, .{ .target = target, .optimize = optimize });
|
|
}
|
|
}
|
|
|
|
fn buildLib(b: *std.Build, options: anytype) !*std.Build.Step.Compile {
|
|
const lib_version = try std.SemanticVersion.parse(version);
|
|
const target = options.target;
|
|
const optimize = options.optimize;
|
|
|
|
// Shared library
|
|
const lib = b.addLibrary(.{
|
|
.name = "gtk4-layer-shell",
|
|
.linkage = .dynamic,
|
|
.root_module = b.createModule(.{
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.link_libc = true,
|
|
}),
|
|
});
|
|
b.installArtifact(lib);
|
|
|
|
// GTK
|
|
lib.root_module.linkSystemLibrary("gtk4", dynamic_link_opts);
|
|
|
|
// local deps (non-system layer-shell/wayland)
|
|
const deps = try LocalDeps.get(b) orelse return lib;
|
|
lib.root_module.addIncludePath(deps.upstream.path("include"));
|
|
lib.root_module.addIncludePath(deps.upstream.path("src"));
|
|
lib.root_module.addIncludePath(deps.client_header_directory);
|
|
for (deps.private_code_files) |source| {
|
|
lib.root_module.addCSourceFile(.{ .file = source });
|
|
}
|
|
|
|
lib.installHeadersDirectory(
|
|
deps.upstream.path("include"),
|
|
"",
|
|
.{ .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.root_module.addCSourceFiles(.{
|
|
.root = deps.upstream.path("src"),
|
|
.files = srcs,
|
|
.flags = &.{
|
|
b.fmt("-DGTK_LAYER_SHELL_MAJOR={}", .{lib_version.major}),
|
|
b.fmt("-DGTK_LAYER_SHELL_MINOR={}", .{lib_version.minor}),
|
|
b.fmt("-DGTK_LAYER_SHELL_MICRO={}", .{lib_version.patch}),
|
|
},
|
|
});
|
|
|
|
return lib;
|
|
}
|
|
|
|
const LocalDeps = struct {
|
|
var cached: ?LocalDeps = null;
|
|
|
|
upstream: *std.Build.Dependency,
|
|
wayland_protocols: *std.Build.Dependency,
|
|
client_header_directory: std.Build.LazyPath,
|
|
private_code_files: []std.Build.LazyPath,
|
|
|
|
fn init(b: *std.Build) !?LocalDeps {
|
|
var result: LocalDeps = .{
|
|
.upstream = b.lazyDependency("gtk4_layer_shell", .{}) orelse return null,
|
|
.wayland_protocols = b.lazyDependency("wayland_protocols", .{}) orelse return null,
|
|
.client_header_directory = undefined,
|
|
.private_code_files = &.{},
|
|
};
|
|
|
|
// Wayland headers and source files
|
|
{
|
|
const protocols = [_]struct { []const u8, std.Build.LazyPath }{
|
|
.{
|
|
"wlr-layer-shell-unstable-v1",
|
|
result.upstream.path("protocol/wlr-layer-shell-unstable-v1.xml"),
|
|
},
|
|
.{
|
|
"xdg-shell",
|
|
result.wayland_protocols.path("stable/xdg-shell/xdg-shell.xml"),
|
|
},
|
|
// Even though we don't use session lock, we still need its headers
|
|
.{
|
|
"ext-session-lock-v1",
|
|
result.wayland_protocols.path("staging/ext-session-lock/ext-session-lock-v1.xml"),
|
|
},
|
|
};
|
|
|
|
const wf = b.addWriteFiles();
|
|
const private_code_files = try b.allocator.alloc(std.Build.LazyPath, protocols.len);
|
|
for (protocols, 0..) |protocol, idx| {
|
|
const name, const xml = protocol;
|
|
|
|
const header_scanner = b.addSystemCommand(&.{ "wayland-scanner", "client-header" });
|
|
header_scanner.addFileArg(xml);
|
|
_ = wf.addCopyFile(
|
|
header_scanner.addOutputFileArg(name),
|
|
b.fmt("{s}-client.h", .{name}),
|
|
);
|
|
|
|
const source_scanner = b.addSystemCommand(&.{ "wayland-scanner", "private-code" });
|
|
source_scanner.addFileArg(xml);
|
|
const source = source_scanner.addOutputFileArg(b.fmt("{s}.c", .{name}));
|
|
private_code_files[idx] = source;
|
|
}
|
|
result.private_code_files = private_code_files;
|
|
result.client_header_directory = wf.getDirectory();
|
|
}
|
|
|
|
cached = result;
|
|
return result;
|
|
}
|
|
|
|
fn get(b: *std.Build) !?LocalDeps {
|
|
if (cached) |c| return c;
|
|
return init(b);
|
|
}
|
|
};
|