Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/compiler/build_runner.zig
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ pub fn main() !void {
// recursive dependants.
var caption_buf: [std.Progress.Node.max_name_len]u8 = undefined;
const caption = std.fmt.bufPrint(&caption_buf, "watching {d} directories, {d} processes", .{
w.dir_table.entries.len, countSubProcesses(run.step_stack.keys()),
w.dir_count, countSubProcesses(run.step_stack.keys()),
}) catch &caption_buf;
var debouncing_node = main_progress_node.start(caption, 0);
var debounce_timeout: Watch.Timeout = .none;
Expand Down
39 changes: 36 additions & 3 deletions lib/std/Build/Watch.zig
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
const builtin = @import("builtin");
const std = @import("../std.zig");
const Watch = @This();
const Step = std.Build.Step;
const Allocator = std.mem.Allocator;
const assert = std.debug.assert;
const fatal = std.process.fatal;
const Watch = @This();
const FsEvents = @import("Watch/FsEvents.zig");

dir_table: DirTable,
os: Os,
/// The number to show as the number of directories being watched.
dir_count: usize,
// These fields are common to most implementations so are kept here for simplicity.
// They are `undefined` on implementations which do not utilize then.
dir_table: DirTable,
generation: Generation,

pub const have_impl = Os != void;
Expand Down Expand Up @@ -97,6 +102,7 @@ const Os = switch (builtin.os.tag) {
fn init() !Watch {
return .{
.dir_table = .{},
.dir_count = 0,
.os = switch (builtin.os.tag) {
.linux => .{
.handle_table = .{},
Expand Down Expand Up @@ -273,6 +279,7 @@ const Os = switch (builtin.os.tag) {
}
w.generation +%= 1;
}
w.dir_count = w.dir_table.count();
}

fn wait(w: *Watch, gpa: Allocator, timeout: Timeout) !WaitResult {
Expand Down Expand Up @@ -408,6 +415,7 @@ const Os = switch (builtin.os.tag) {
fn init() !Watch {
return .{
.dir_table = .{},
.dir_count = 0,
.os = switch (builtin.os.tag) {
.windows => .{
.handle_table = .{},
Expand Down Expand Up @@ -572,6 +580,7 @@ const Os = switch (builtin.os.tag) {
}
w.generation +%= 1;
}
w.dir_count = w.dir_table.count();
}

fn wait(w: *Watch, gpa: Allocator, timeout: Timeout) !WaitResult {
Expand Down Expand Up @@ -605,7 +614,7 @@ const Os = switch (builtin.os.tag) {
};
}
},
.dragonfly, .freebsd, .netbsd, .openbsd, .ios, .macos, .tvos, .visionos, .watchos => struct {
.dragonfly, .freebsd, .netbsd, .openbsd, .ios, .tvos, .visionos, .watchos => struct {
const posix = std.posix;

kq_fd: i32,
Expand Down Expand Up @@ -639,6 +648,7 @@ const Os = switch (builtin.os.tag) {
errdefer posix.close(kq_fd);
return .{
.dir_table = .{},
.dir_count = 0,
.os = .{
.kq_fd = kq_fd,
.handles = .empty,
Expand Down Expand Up @@ -769,6 +779,7 @@ const Os = switch (builtin.os.tag) {
}
w.generation +%= 1;
}
w.dir_count = w.dir_table.count();
}

fn wait(w: *Watch, gpa: Allocator, timeout: Timeout) !WaitResult {
Expand Down Expand Up @@ -812,6 +823,28 @@ const Os = switch (builtin.os.tag) {
return any_dirty;
}
},
.macos => struct {
fse: FsEvents,

fn init() !Watch {
return .{
.os = .{ .fse = try .init() },
.dir_count = 0,
.dir_table = undefined,
.generation = undefined,
};
}
fn update(w: *Watch, gpa: Allocator, steps: []const *Step) !void {
try w.os.fse.setPaths(gpa, steps);
w.dir_count = w.os.fse.watch_roots.len;
}
fn wait(w: *Watch, gpa: Allocator, timeout: Timeout) !WaitResult {
return w.os.fse.wait(gpa, switch (timeout) {
.none => null,
.ms => |ms| @as(u64, ms) * std.time.ns_per_ms,
});
}
},
else => void,
};

Expand Down
Loading