From 9f1688653653400b7de3d91cc22dc5036593425a 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 82f45ee9f0189bdc1d26b292624e4c2ab42726ea..cea53b0532c3db0377932fa2258c1744e961826e 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -6978,6 +6978,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, + })); } } -- 2.54.0