From 74f09d5559a5fd0a1a73927d8ecaf8ffd76d9476 Mon Sep 17 00:00:00 2001 From: Matthew Knight Date: Sat, 30 May 2026 00:29:36 -0700 Subject: [PATCH 1/2] Zig 0.17.0-dev.420+8086ae176 --- build.zig | 8 +++----- src/serial.zig | 20 ++++++++++++-------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/build.zig b/build.zig index 2ffbe26..653ea85 100644 --- a/build.zig +++ b/build.zig @@ -12,14 +12,12 @@ pub fn build(b: *std.Build) void { const serial_mod = b.addModule("serial", .{ .root_source_file = b.path("src/serial.zig"), + .target = target, + .optimize = optimize, }); const unit_tests = b.addTest(.{ - .root_module = b.createModule(.{ - .root_source_file = b.path("src/serial.zig"), - .target = target, - .optimize = optimize, - }), + .root_module = serial_mod, }); const run_unit_tests = b.addRunArtifact(unit_tests); const test_step = b.step("test", "Run unit tests"); diff --git a/src/serial.zig b/src/serial.zig index cdd0e89..95bacf2 100644 --- a/src/serial.zig +++ b/src/serial.zig @@ -1,6 +1,6 @@ const std = @import("std"); const builtin = @import("builtin"); -const c = @cImport(@cInclude("termios.h")); +//const c = @import("c"); const Io = std.Io; pub fn list(io: Io) !PortIterator { @@ -963,12 +963,16 @@ pub fn flushSerialPort(port: std.Io.File, flush: Flush) !void { return error.FlushError; }, .macos => { + const TCIFLUSH = 1; + const TCOFLUSH = 2; + const TCIOFLUSH = 3; + const tcflush = @extern(fn (c_int, c_int) c_int, .{ .name = "tcflush" }); const mode: c_int = switch (flush) { - .input => c.TCIFLUSH, - .output => c.TCOFLUSH, - .both => c.TCIOFLUSH, + .input => TCIFLUSH, + .output => TCOFLUSH, + .both => TCIOFLUSH, }; - if (0 != c.tcflush(port.handle, mode)) + if (0 != tcflush(port.handle, mode)) return error.FlushError; }, else => @compileError("unsupported OS, please implement!"), @@ -1178,10 +1182,10 @@ test "basic configuration test" { else => unreachable, } - var port = std.Io.Dir.openFileAbsolute(std.testing.io, tty, .{ .mode = .read_write }) catch |err| switch(err) { + var port = std.Io.Dir.openFileAbsolute(std.testing.io, tty, .{ .mode = .read_write }) catch |err| switch (err) { error.FileNotFound => return error.SkipZigTest, else => |e| return e, - }; + }; defer port.close(std.testing.io); try configureSerialPort(port, cfg); @@ -1196,7 +1200,7 @@ test "basic flush test" { .macos => tty = "/dev/cu.usbmodem101", else => unreachable, } - var port = std.Io.Dir.openFileAbsolute(std.testing.io, tty, .{ .mode = .read_write }) catch |err| switch(err) { + var port = std.Io.Dir.openFileAbsolute(std.testing.io, tty, .{ .mode = .read_write }) catch |err| switch (err) { error.FileNotFound => return error.SkipZigTest, else => |e| return e, }; From 0a31d48794752e1dfbf6dcfe8f4c646667d3ca6d Mon Sep 17 00:00:00 2001 From: Matthew Knight Date: Sat, 30 May 2026 00:30:51 -0700 Subject: [PATCH 2/2] Clenaup patch --- src/serial.zig | 1 - 1 file changed, 1 deletion(-) diff --git a/src/serial.zig b/src/serial.zig index 95bacf2..4443c8b 100644 --- a/src/serial.zig +++ b/src/serial.zig @@ -1,6 +1,5 @@ const std = @import("std"); const builtin = @import("builtin"); -//const c = @import("c"); const Io = std.Io; pub fn list(io: Io) !PortIterator {