From 9a9cc9c96d2640b573a1b31b6562f9369e971105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 30 Nov 2025 23:01:50 +0100 Subject: [PATCH] compiler: define ___OpenBSD and OpenBSDX_Y when targeting openbsd libc --- src/Compilation.zig | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Compilation.zig b/src/Compilation.zig index 687525cbf3..be3d49e31a 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -6884,6 +6884,21 @@ fn addCommonCCArgs( // would be inconsistent with header declarations. (min_ver.major * 100_000_000) + (min_ver.minor * 1_000_000), })); + } else if (target.isOpenBSDLibC()) { + const min_ver = target.os.version_range.semver.min; + // The macro in sys/param.h doesn't have the leading underscores, but we don't want to pollute the + // global namespace in all compilation units. So we use leading underscores and modify sys/param.h + // to just alias this one. + try argv.append(try std.fmt.allocPrint(arena, "-D___OpenBSD={d}", .{ + // Brilliantly, OpenBSD defines this macro to the year and month of the release, so we need to + // maintain a manual mapping here whenever we update the headers. + 202510, + })); + // We can't avoid pollution for this one... + try argv.append(try std.fmt.allocPrint(arena, "-DOpenBSD{d}_{d}", .{ + min_ver.major, + min_ver.minor, + })); } }