From f326b734572d41bea8f9a5d1337716d9bdcf71c8 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Thu, 26 Feb 2026 13:49:01 +0100 Subject: [PATCH] build: make FSEvents backend optional and link it against xcode-frameworks --- build.zig | 24 ++++++++++++++++++++++++ src/nightwatch.zig | 3 ++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/build.zig b/build.zig index a737665..46f975d 100644 --- a/build.zig +++ b/build.zig @@ -4,10 +4,31 @@ pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); + const use_fsevents = if (target.result.os.tag == .macos) blk: { + break :blk b.option( + bool, + "use_fsevents", + "Use the FSEvents backend on macOS instead of kqueue (requires Xcode frameworks)", + ) orelse false; + } else false; + + const options = b.addOptions(); + options.addOption(bool, "use_fsevents", use_fsevents); + const mod = b.addModule("nightwatch", .{ .root_source_file = b.path("src/nightwatch.zig"), .target = target, }); + mod.addOptions("build_options", options); + + if (use_fsevents) { + const xcode_frameworks = b.lazyDependency("xcode-frameworks", .{}) orelse + @panic("xcode-frameworks dependency not available"); + mod.addSystemFrameworkPath(xcode_frameworks.path("Frameworks")); + mod.addLibraryPath(xcode_frameworks.path("lib")); + mod.linkFramework("CoreServices", .{}); + mod.linkFramework("CoreFoundation", .{}); + } const exe = b.addExecutable(.{ .name = "nightwatch", @@ -47,6 +68,9 @@ pub fn build(b: *std.Build) void { .root_source_file = b.path("src/nightwatch_test.zig"), .target = target, .optimize = optimize, + .imports = &.{ + .{ .name = "nightwatch", .module = mod }, + }, }), }); const run_integration_tests = b.addRunArtifact(integration_tests); diff --git a/src/nightwatch.zig b/src/nightwatch.zig index 4a4ce8c..3e1e046 100644 --- a/src/nightwatch.zig +++ b/src/nightwatch.zig @@ -1,5 +1,6 @@ const std = @import("std"); const builtin = @import("builtin"); +const build_options = @import("build_options"); pub const EventType = enum { created, @@ -80,7 +81,7 @@ pub fn handle_read_ready(self: *@This()) !void { const Backend = switch (builtin.os.tag) { .linux => INotifyBackend, - .macos => FSEventsBackend, + .macos => if (build_options.use_fsevents) FSEventsBackend else KQueueBackend, .freebsd => KQueueBackend, .windows => WindowsBackend, else => @compileError("file_watcher: unsupported OS"),