define _WIN32_WINNT for windows compilations based on target minver (#17224)

This commit is contained in:
Phil Richards 2023-09-26 20:25:08 +01:00 committed by GitHub
parent f4c884617f
commit 15ce965252
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -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{

View File

@ -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",
});