Skip to content

Commit e780dfd

Browse files
committed
allow using system provided wayland-protocols
1 parent c937a9d commit e780dfd

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

build.zig

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,25 @@ pub fn build(b: *std.Build) !void {
352352
else
353353
null;
354354

355-
if (b.lazyDependency("wayland_protocols", .{})) |wayland_protocols| {
355+
const use_system_wayland_protocols = b.systemIntegrationOption("wayland-protocols", .{});
356+
357+
const wayland_protocols_dir: ?std.Build.LazyPath = if (use_system_wayland_protocols) blk: {
358+
var code: u8 = undefined;
359+
const pkgdatadir = if (b.runAllowFail(&[_][]const u8{
360+
b.graph.env_map.get("PKG_CONFIG") orelse "pkg-config",
361+
"wayland-protocols",
362+
"--variable=pkgdatadir",
363+
}, &code, .Ignore)) |stdout| stdout else |err| switch (err) {
364+
error.ProcessTerminated => return error.PkgConfigCrashed,
365+
error.ExecNotSupported => return error.PkgConfigFailed,
366+
error.ExitCodeFailure => return error.PkgConfigFailed,
367+
error.FileNotFound => return error.PkgConfigNotInstalled,
368+
else => return err,
369+
};
370+
break :blk .{ .cwd_relative = std.mem.trim(u8, pkgdatadir, &std.ascii.whitespace) };
371+
} else if (b.lazyDependency("wayland_protocols", .{})) |wayland_protocols| wayland_protocols.path(".") else null;
372+
373+
if (wayland_protocols_dir) |wayland_protocols| {
356374
for (
357375
[_][]const u8{
358376
"staging/xdg-activation/xdg-activation-v1.xml",
@@ -385,14 +403,14 @@ pub fn build(b: *std.Build) !void {
385403

386404
{
387405
run_wayland_scanner1.addArg("client-header");
388-
run_wayland_scanner1.addFileArg(wayland_protocols.path(input_file));
406+
run_wayland_scanner1.addFileArg(wayland_protocols.path(b, input_file));
389407
const header_file = run_wayland_scanner1.addOutputFileArg(b.fmt("{s}-client-protocol.h", .{output_filename}));
390408
tracy_profiler.root_module.addIncludePath(header_file.dirname());
391409
}
392410

393411
{
394412
run_wayland_scanner2.addArg("public-code");
395-
run_wayland_scanner2.addFileArg(wayland_protocols.path(input_file));
413+
run_wayland_scanner2.addFileArg(wayland_protocols.path(b, input_file));
396414
const source_file = run_wayland_scanner2.addOutputFileArg(b.fmt("{s}.c", .{output_filename}));
397415
tracy_profiler.root_module.addCSourceFile(.{ .file = source_file });
398416
}

build.zig.zon.nix

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,6 @@ in
134134
rev = "9d3d387087d252970923db7f297f681622c4e026";
135135
};
136136
}
137-
{
138-
name = "N-V-__8AAPSiCwBmhGfdDQlw65XlO55QP1pogBUo1ZeGUv_C";
139-
path = fetchZigArtifact {
140-
name = "wayland_protocols";
141-
url = "git+https://gitlab.freedesktop.org/wayland/wayland-protocols.git?ref=1.38#9ac1a0977eea1b2f525e375089131f7d696a74ee";
142-
hash = "sha256-64cjsF3uRdhDW3gx4bc3rwJd0tMIKZW20x1yeesvM6o=";
143-
rev = "9ac1a0977eea1b2f525e375089131f7d696a74ee";
144-
};
145-
}
146137
{
147138
name = "N-V-__8AADb7TQBhnAapR8-szphSk_8WmU22BY8jadPC_8-d";
148139
path = fetchZigArtifact {

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
++ lib.optionals (stdenv.hostPlatform.isLinux) [libxkbcommon];
5454
nativeBuildInputs = with pkgs;
5555
[zig_hook pkg-config makeWrapper]
56-
++ lib.optionals (stdenv.hostPlatform.isLinux) [wayland-scanner];
56+
++ lib.optionals (stdenv.hostPlatform.isLinux) [wayland-scanner wayland-protocols];
5757
zigBuildFlags = ["--system" "${deps}"];
5858

5959
postFixup = pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isLinux ''

0 commit comments

Comments
 (0)