@@ -352,7 +352,25 @@ pub fn build(b: *std.Build) !void {
352
352
else
353
353
null ;
354
354
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 | {
356
374
for (
357
375
[_ ][]const u8 {
358
376
"staging/xdg-activation/xdg-activation-v1.xml" ,
@@ -385,14 +403,14 @@ pub fn build(b: *std.Build) !void {
385
403
386
404
{
387
405
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 ));
389
407
const header_file = run_wayland_scanner1 .addOutputFileArg (b .fmt ("{s}-client-protocol.h" , .{output_filename }));
390
408
tracy_profiler .root_module .addIncludePath (header_file .dirname ());
391
409
}
392
410
393
411
{
394
412
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 ));
396
414
const source_file = run_wayland_scanner2 .addOutputFileArg (b .fmt ("{s}.c" , .{output_filename }));
397
415
tracy_profiler .root_module .addCSourceFile (.{ .file = source_file });
398
416
}
0 commit comments