From ed8c5632e0228b1b821c87b511beb474c6a41f0c Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 26 Aug 2026 09:24:17 -0300 Subject: Fix the console: std.time.milliTimestamp does not exist, and zig build test could not see it `zig build interact` did not compile. The mouse coalescer dated its held report with `std.time.milliTimestamp`, and this Zig's `std.time` has constants and `epoch` and no clock at all: the repo's own idiom is `std.Io.Timestamp`, already wrapped as `serial.Port.nowMs`, which is what the three call sites now use. The reason it survived every check I ran is worth writing down, because the same hole will swallow the next one. `zig build test` compiles `tools/console.zig` as a test module, and Zig only analyses what is REACHABLE: no test calls `attach`, so the loop containing the bad call was never looked at. Seven passing MouseFilter tests and a green `zig build test` said nothing whatsoever about whether the file compiles as part of an executable. Nor does plain `zig build` - p4-console is not in the default install step - so the only thing that would have caught it is building or running the named step, which is also the documented way to use this repo: `zig build interact -Dpardes`. Verified the way it should have been the first time: `zig build interact -Dpardes -Dcpu-mhz=360` with piped stdin flashes, attaches, takes the keystrokes and detaches at EOF. Also compiled every step's artifacts - elf, console, bench - and re-ran the matrix that matters for the editor side: default, Debug, ReleaseFast, ReleaseSafe, ReleaseSmall, and -Dplatform=p4 at Debug and ReleaseSmall, plus -Dp4-cols/-Dp4-rows at 40x12 and 80x24. Note for anyone reading a failing `zig build console` or `bench`: those RUN their tool, so they fail with DeviceBusy when something else is attached to the port. That is not a build error, and it is how this one hid in plain sight in the middle of the output. --- tools/console.zig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/console.zig b/tools/console.zig index 4b13513..39a829b 100644 --- a/tools/console.zig +++ b/tools/console.zig @@ -336,7 +336,7 @@ pub fn attach(port_path: []const u8, baud: serial.Baud, opts: Options) !void { // A bounded wait, and shorter while a motion report is being held: the hold has to end on // time even when the human has stopped moving the mouse and nothing else is arriving. const wait: i32 = if (held_at) |at| blk: { - const left = coalesce_ms - (std.time.milliTimestamp() - at); + const left = coalesce_ms - (port.nowMs() - at); break :blk if (left <= 0) 0 else @intCast(left); } else 200; const ready = posix.poll(&pfd, wait) catch continue; @@ -385,9 +385,9 @@ pub fn attach(port_path: []const u8, baud: serial.Baud, opts: Options) !void { // The coalescing window. A held motion report goes out when the interval has elapsed, which // is what turns a drag into a bounded stream of positions rather than one per cell crossed. if (mouse.pending()) { - const at = held_at orelse std.time.milliTimestamp(); + const at = held_at orelse port.nowMs(); held_at = at; - if (std.time.milliTimestamp() - at >= coalesce_ms) { + if (port.nowMs() - at >= coalesce_ms) { const send = mouse.flushHeld(&to_board); if (send > 0) port.write(to_board[0..send]) catch {}; held_at = null; -- cgit v1.3