Commit 15ce965252

Phil Richards <phildrip@users.noreply.github.com>
2023-09-26 21:25:08
define `_WIN32_WINNT` for windows compilations based on target minver (#17224)
1 parent f4c8846
Changed files (2)
src/Compilation.zig
@@ -4880,6 +4880,14 @@ pub fn addCCArgs(
     const llvm_triple = try @import("codegen/llvm.zig").targetTriple(arena, target);
     try argv.appendSlice(&[_][]const u8{ "-target", llvm_triple });
 
+    if (target.os.tag == .windows) switch (ext) {
+        .c, .cpp, .m, .mm, .h, .cu, .rc, .assembly, .assembly_with_cpp => {
+            const minver: u16 = @truncate(@intFromEnum(target.os.getVersionRange().windows.min) >> 16);
+            try argv.append(try std.fmt.allocPrint(argv.allocator, "-D_WIN32_WINNT=0x{x:0>4}", .{minver}));
+        },
+        else => {},
+    };
+
     switch (ext) {
         .c, .cpp, .m, .mm, .h, .cu, .rc => {
             try argv.appendSlice(&[_][]const u8{
src/mingw.zig
@@ -89,7 +89,6 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
 
                     "-std=gnu99",
                     "-D_CRTBLD",
-                    "-D_WIN32_WINNT=0x0f00",
                     "-D__MSVCRT_VERSION__=0x700",
                     "-D__USE_MINGW_ANSI_STDIO=0",
                 });
@@ -114,7 +113,6 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
 
                 "-std=gnu99",
                 "-D_CRTBLD",
-                "-D_WIN32_WINNT=0x0f00",
                 "-D__MSVCRT_VERSION__=0x700",
                 "-D__USE_MINGW_ANSI_STDIO=0",
 
@@ -163,7 +161,6 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
 
                 "-std=gnu99",
                 "-D_CRTBLD",
-                "-D_WIN32_WINNT=0x0f00",
                 "-D__MSVCRT_VERSION__=0x700",
                 "-D__USE_MINGW_ANSI_STDIO=0",
 
@@ -226,7 +223,6 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
 
                 "-std=gnu99",
                 "-D_CRTBLD",
-                "-D_WIN32_WINNT=0x0f00",
                 "-D__MSVCRT_VERSION__=0x700",
                 "-D__USE_MINGW_ANSI_STDIO=0",
 
@@ -272,7 +268,6 @@ fn add_cc_args(
     try args.appendSlice(&[_][]const u8{
         "-std=gnu11",
         "-D_CRTBLD",
-        "-D_WIN32_WINNT=0x0f00",
         "-D__MSVCRT_VERSION__=0x700",
         "-D__USE_MINGW_ANSI_STDIO=0",
     });