main zmx / src / cross.zig
Eric Bower  ·  2026-05-20
 1const builtin = @import("builtin");
 2const std = @import("std");
 3const posix = std.posix;
 4
 5pub const c = switch (builtin.os.tag) {
 6    .macos => @cImport({
 7        @cInclude("sys/ioctl.h"); // ioctl and constants
 8        @cInclude("termios.h");
 9        @cInclude("stdlib.h");
10        @cInclude("unistd.h");
11    }),
12    .freebsd => @cImport({
13        @cInclude("termios.h"); // ioctl and constants
14        @cInclude("libutil.h"); // openpty()
15        @cInclude("stdlib.h");
16        @cInclude("unistd.h");
17    }),
18    else => @cImport({
19        @cInclude("sys/ioctl.h"); // ioctl and constants
20        @cInclude("pty.h");
21        @cInclude("stdlib.h");
22        @cInclude("unistd.h");
23    }),
24};
25
26// Manually declare forkpty for macOS since util.h is not available during cross-compilation
27pub const forkpty = if (builtin.os.tag == .macos)
28    struct {
29        extern "c" fn forkpty(master_fd: *c_int, name: ?[*:0]u8, termp: ?*const c.struct_termios, winp: ?*const c.struct_winsize) c_int;
30    }.forkpty
31else
32    c.forkpty;