Skip to content

Commit 15ce965

Browse files
authored
define _WIN32_WINNT for windows compilations based on target minver (#17224)
1 parent f4c8846 commit 15ce965

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/Compilation.zig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4880,6 +4880,14 @@ pub fn addCCArgs(
48804880
const llvm_triple = try @import("codegen/llvm.zig").targetTriple(arena, target);
48814881
try argv.appendSlice(&[_][]const u8{ "-target", llvm_triple });
48824882

4883+
if (target.os.tag == .windows) switch (ext) {
4884+
.c, .cpp, .m, .mm, .h, .cu, .rc, .assembly, .assembly_with_cpp => {
4885+
const minver: u16 = @truncate(@intFromEnum(target.os.getVersionRange().windows.min) >> 16);
4886+
try argv.append(try std.fmt.allocPrint(argv.allocator, "-D_WIN32_WINNT=0x{x:0>4}", .{minver}));
4887+
},
4888+
else => {},
4889+
};
4890+
48834891
switch (ext) {
48844892
.c, .cpp, .m, .mm, .h, .cu, .rc => {
48854893
try argv.appendSlice(&[_][]const u8{

src/mingw.zig

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
8989

9090
"-std=gnu99",
9191
"-D_CRTBLD",
92-
"-D_WIN32_WINNT=0x0f00",
9392
"-D__MSVCRT_VERSION__=0x700",
9493
"-D__USE_MINGW_ANSI_STDIO=0",
9594
});
@@ -114,7 +113,6 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
114113

115114
"-std=gnu99",
116115
"-D_CRTBLD",
117-
"-D_WIN32_WINNT=0x0f00",
118116
"-D__MSVCRT_VERSION__=0x700",
119117
"-D__USE_MINGW_ANSI_STDIO=0",
120118

@@ -163,7 +161,6 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
163161

164162
"-std=gnu99",
165163
"-D_CRTBLD",
166-
"-D_WIN32_WINNT=0x0f00",
167164
"-D__MSVCRT_VERSION__=0x700",
168165
"-D__USE_MINGW_ANSI_STDIO=0",
169166

@@ -226,7 +223,6 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
226223

227224
"-std=gnu99",
228225
"-D_CRTBLD",
229-
"-D_WIN32_WINNT=0x0f00",
230226
"-D__MSVCRT_VERSION__=0x700",
231227
"-D__USE_MINGW_ANSI_STDIO=0",
232228

@@ -272,7 +268,6 @@ fn add_cc_args(
272268
try args.appendSlice(&[_][]const u8{
273269
"-std=gnu11",
274270
"-D_CRTBLD",
275-
"-D_WIN32_WINNT=0x0f00",
276271
"-D__MSVCRT_VERSION__=0x700",
277272
"-D__USE_MINGW_ANSI_STDIO=0",
278273
});

0 commit comments

Comments
 (0)