core: fix c macro comparisons

This commit is contained in:
Jeffrey C. Ollie
2026-03-19 22:00:24 -05:00
parent 2ea6029c7a
commit b0789af583
2 changed files with 24 additions and 4 deletions

View File

@@ -146,7 +146,27 @@ pub fn add(
.target = target,
.optimize = optimize,
});
c.defineCMacro("ZIG_TARGET", @tagName(target.result.os.tag));
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(.{

View File

@@ -1,11 +1,11 @@
#if ZIG_TARGET == freebsd
#if ZIG_TARGET == ZIG_TARGET_FREEBSD
#include <termios.h> // ioctl and constants
#include <libutil.h> // openpty
#include <stdlib.h> // ptsname_r
#include <unistd.h> // tcgetpgrp
#endif
#if ZIG_TARGET == linux
#if ZIG_TARGET == ZIG_TARGET_LINUX
#define _GNU_SOURCE // ptsname_r
#include <pty.h> // openpty
#include <stdlib.h> // ptsname_r
@@ -13,7 +13,7 @@
#include <unistd.h> // tcgetpgrp, setsid
#endif
#if ZIG_TARGET == macos
#if ZIG_TARGET == ZIG_TARGET_MACOS
#include <sys/ioctl.h> // ioctl and constants
#include <sys/ttycom.h> // ioctl and constants for TIOCPTYGNAME
#include <sys/types.h>