From d5ce05fd37d8f9c94025e71cfd0b7c9ec290a5ce Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Fri, 20 Mar 2026 10:37:42 -0500 Subject: [PATCH] core: simplify pty.c macro usage --- src/build/SharedDeps.zig | 63 ++++++++++++---------------------------- src/pty.c | 16 ++++++---- 2 files changed, 29 insertions(+), 50 deletions(-) diff --git a/src/build/SharedDeps.zig b/src/build/SharedDeps.zig index 581b0b64e..cb0b609d5 100644 --- a/src/build/SharedDeps.zig +++ b/src/build/SharedDeps.zig @@ -136,51 +136,24 @@ pub fn add( self.config.terminalOptions().add(b, step.root_module); // C imports needed to manage/create PTYs - switch (target.result.os.tag) { - .freebsd, - .linux, - .macos, - => { - const c = b.addTranslateC(.{ - .root_source_file = b.path("src/pty.c"), - .target = target, - .optimize = optimize, - }); - inline for (@typeInfo(std.Target.Os.Tag).@"enum".fields) |field| { - c.defineCMacro( - b.fmt( - "ZIG_TARGET_{s}", - .{try std.ascii.allocUpperString(b.allocator, field.name)}, - ), - b.fmt("{d}", .{field.value}), - ); - } - c.defineCMacro( - "ZIG_TARGET", - b.fmt( - "ZIG_TARGET_{s}", - .{ - try std.ascii.allocUpperString( - b.allocator, - @tagName(target.result.os.tag), - ), - }, - ), - ); - switch (target.result.os.tag) { - .macos => { - const libc = try std.zig.LibCInstallation.findNative(.{ - .allocator = b.allocator, - .target = &target.result, - .verbose = false, - }); - c.addSystemIncludePath(.{ .cwd_relative = libc.sys_include_dir.? }); - }, - else => {}, - } - step.root_module.addImport("pty-c", c.createModule()); - }, - else => {}, + { + const c = b.addTranslateC(.{ + .root_source_file = b.path("src/pty.c"), + .target = target, + .optimize = optimize, + }); + switch (target.result.os.tag) { + .macos => { + const libc = try std.zig.LibCInstallation.findNative(.{ + .allocator = b.allocator, + .target = &target.result, + .verbose = false, + }); + c.addSystemIncludePath(.{ .cwd_relative = libc.sys_include_dir.? }); + }, + else => {}, + } + step.root_module.addImport("pty-c", c.createModule()); } // Freetype. We always include this even if our font backend doesn't diff --git a/src/pty.c b/src/pty.c index 4708d0b4e..fe50d2b4b 100644 --- a/src/pty.c +++ b/src/pty.c @@ -1,19 +1,20 @@ -#if ZIG_TARGET == ZIG_TARGET_FREEBSD +#if defined(__FreeBSD__) + #include // ioctl and constants #include // openpty #include // ptsname_r #include // tcgetpgrp -#endif -#if ZIG_TARGET == ZIG_TARGET_LINUX +#elif defined(__linux__) + #define _GNU_SOURCE // ptsname_r #include // openpty #include // ptsname_r #include // ioctl and constants #include // tcgetpgrp, setsid -#endif -#if ZIG_TARGET == ZIG_TARGET_MACOS +#elif defined(__APPLE__) + #include // ioctl and constants #include // ioctl and constants for TIOCPTYGNAME #include @@ -31,4 +32,9 @@ #ifndef tiocgwinsz #define tiocgwinsz 1074295912 #endif + +#else + + #error "unsupported platform" + #endif