build: make FSEvents backend optional and link it against xcode-frameworks

This commit is contained in:
CJ van den Berg 2026-02-26 13:49:01 +01:00
parent a720697618
commit f326b73457
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 26 additions and 1 deletions

View file

@ -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);

View file

@ -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"),