diff options
| author | Alex Rønne Petersen <alex@alexrp.com> | 2024-12-15 14:37:50 +0100 |
|---|---|---|
| committer | Alex Rønne Petersen <alex@alexrp.com> | 2024-12-16 01:56:55 +0100 |
| commit | 8f330ab70ea4f28b0b5efb349b89a9c9a8b95bf0 (patch) | |
| tree | ccd714b87f0f235740778b424294a26bb27a4074 /src | |
| parent | aa0377794df692ede9bc19d8e5296ab90ce6df68 (diff) | |
| download | zig-8f330ab70ea4f28b0b5efb349b89a9c9a8b95bf0.tar.gz zig-8f330ab70ea4f28b0b5efb349b89a9c9a8b95bf0.zip | |
mingw: Fix CFLAGS for winpthreads.
It should not use the CRT ones, and it also needs a few flags of its own that I
forgot to add in #22156.
Follow-up fix for #10989.
Diffstat (limited to 'src')
| -rw-r--r-- | src/mingw.zig | 192 |
1 files changed, 115 insertions, 77 deletions
diff --git a/src/mingw.zig b/src/mingw.zig index 63c5a8f991..7725a91f50 100644 --- a/src/mingw.zig +++ b/src/mingw.zig @@ -32,7 +32,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre switch (crt_file) { .crt2_o => { var args = std.ArrayList([]const u8).init(arena); - try add_cc_args(comp, arena, &args); + try addCrtCcArgs(comp, arena, &args); if (comp.mingw_unicode_entry_point) { try args.appendSlice(&.{ "-DUNICODE", "-D_UNICODE" }); } @@ -52,7 +52,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre .dllcrt2_o => { var args = std.ArrayList([]const u8).init(arena); - try add_cc_args(comp, arena, &args); + try addCrtCcArgs(comp, arena, &args); var files = [_]Compilation.CSourceFile{ .{ .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ @@ -68,81 +68,109 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre }, .mingw32_lib => { - var args = std.ArrayList([]const u8).init(arena); - try add_cc_args(comp, arena, &args); var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena); - for (mingw32_generic_src) |dep| { - try c_source_files.append(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ - "libc", "mingw", dep, - }), - .extra_flags = args.items, - .owner = undefined, - }); - } - if (target.cpu.arch.isX86()) { - for (mingw32_x86_src) |dep| { + { + var crt_args = std.ArrayList([]const u8).init(arena); + try addCrtCcArgs(comp, arena, &crt_args); + + for (mingw32_generic_src) |dep| { try c_source_files.append(.{ .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "mingw", dep, }), - .extra_flags = args.items, + .extra_flags = crt_args.items, .owner = undefined, }); } - if (target.cpu.arch == .x86) { - for (mingw32_x86_32_src) |dep| { + if (target.cpu.arch.isX86()) { + for (mingw32_x86_src) |dep| { try c_source_files.append(.{ .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "mingw", dep, }), - .extra_flags = args.items, + .extra_flags = crt_args.items, .owner = undefined, }); } + if (target.cpu.arch == .x86) { + for (mingw32_x86_32_src) |dep| { + try c_source_files.append(.{ + .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + "libc", "mingw", dep, + }), + .extra_flags = crt_args.items, + .owner = undefined, + }); + } + } + } else if (target.cpu.arch == .thumb) { + for (mingw32_arm_src) |dep| { + try c_source_files.append(.{ + .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + "libc", "mingw", dep, + }), + .extra_flags = crt_args.items, + .owner = undefined, + }); + } + for (mingw32_arm32_src) |dep| { + try c_source_files.append(.{ + .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + "libc", "mingw", dep, + }), + .extra_flags = crt_args.items, + .owner = undefined, + }); + } + } else if (target.cpu.arch == .aarch64) { + for (mingw32_arm_src) |dep| { + try c_source_files.append(.{ + .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + "libc", "mingw", dep, + }), + .extra_flags = crt_args.items, + .owner = undefined, + }); + } + for (mingw32_arm64_src) |dep| { + try c_source_files.append(.{ + .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + "libc", "mingw", dep, + }), + .extra_flags = crt_args.items, + .owner = undefined, + }); + } + } else { + @panic("unsupported arch"); } - } else if (target.cpu.arch.isThumb()) { - for (mingw32_arm_src) |dep| { - try c_source_files.append(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ - "libc", "mingw", dep, - }), - .extra_flags = args.items, - .owner = undefined, - }); - } - for (mingw32_arm32_src) |dep| { - try c_source_files.append(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ - "libc", "mingw", dep, - }), - .extra_flags = args.items, - .owner = undefined, - }); - } - } else if (target.cpu.arch.isAARCH64()) { - for (mingw32_arm_src) |dep| { - try c_source_files.append(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ - "libc", "mingw", dep, - }), - .extra_flags = args.items, - .owner = undefined, - }); + } + + { + var winpthreads_args = std.ArrayList([]const u8).init(arena); + try addCcArgs(comp, arena, &winpthreads_args); + try winpthreads_args.appendSlice(&[_][]const u8{ + "-DIN_WINPTHREAD", + "-DWIN32_LEAN_AND_MEAN", + }); + + switch (comp.compilerRtOptMode()) { + .Debug, .ReleaseSafe => try winpthreads_args.append("-DWINPTHREAD_DBG"), + .ReleaseFast, .ReleaseSmall => {}, } - for (mingw32_arm64_src) |dep| { + + for (mingw32_winpthreads_src) |dep| { try c_source_files.append(.{ .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "mingw", dep, }), - .extra_flags = args.items, + .extra_flags = winpthreads_args.items, .owner = undefined, }); } - } else { - @panic("unsupported arch"); } + return comp.build_crt_file("mingw32", .Lib, .@"mingw-w64 mingw32.lib", prog_node, c_source_files.items, .{ .unwind_tables = unwind_tables, }); @@ -150,37 +178,44 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre } } -fn add_cc_args( +fn addCcArgs( comp: *Compilation, arena: Allocator, args: *std.ArrayList([]const u8), ) error{OutOfMemory}!void { try args.appendSlice(&[_][]const u8{ - "-DHAVE_CONFIG_H", - - "-I", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "mingw", "include" }), + "-std=gnu11", + "-D__USE_MINGW_ANSI_STDIO=0", "-isystem", try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "include", "any-windows-any" }), }); +} - const target = comp.getTarget(); - if (target.cpu.arch.isThumb()) { +fn addCrtCcArgs( + comp: *Compilation, + arena: Allocator, + args: *std.ArrayList([]const u8), +) error{OutOfMemory}!void { + try addCcArgs(comp, arena, args); + + if (comp.getTarget().cpu.arch == .thumb) { try args.append("-mfpu=vfp"); } try args.appendSlice(&[_][]const u8{ - "-std=gnu11", - "-D_CRTBLD", - "-D_SYSCRT=1", - "-DCRTDLL=1", - "-D_WIN32_WINNT=0x0f00", // According to Martin Storsjö, // > the files under mingw-w64-crt are designed to always // be built with __MSVCRT_VERSION__=0x700 "-D__MSVCRT_VERSION__=0x700", - "-D__USE_MINGW_ANSI_STDIO=0", + "-D_CRTBLD", + "-D_SYSCRT=1", + "-D_WIN32_WINNT=0x0f00", + "-DCRTDLL=1", + "-DHAVE_CONFIG_H", + + "-I", + try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "mingw", "include" }), }); } @@ -736,19 +771,6 @@ const mingw32_generic_src = [_][]const u8{ "stdio" ++ path.sep_str ++ "ucrt_vsprintf.c", "stdio" ++ path.sep_str ++ "ucrt_vsscanf.c", "string" ++ path.sep_str ++ "ucrt__wcstok.c", - // winpthreads - "winpthreads" ++ path.sep_str ++ "barrier.c", - "winpthreads" ++ path.sep_str ++ "clock.c", - "winpthreads" ++ path.sep_str ++ "cond.c", - "winpthreads" ++ path.sep_str ++ "misc.c", - "winpthreads" ++ path.sep_str ++ "mutex.c", - "winpthreads" ++ path.sep_str ++ "nanosleep.c", - "winpthreads" ++ path.sep_str ++ "ref.c", - "winpthreads" ++ path.sep_str ++ "rwlock.c", - "winpthreads" ++ path.sep_str ++ "sched.c", - "winpthreads" ++ path.sep_str ++ "sem.c", - "winpthreads" ++ path.sep_str ++ "spinlock.c", - "winpthreads" ++ path.sep_str ++ "thread.c", // uuid "libsrc" ++ path.sep_str ++ "ativscp-uuid.c", "libsrc" ++ path.sep_str ++ "atsmedia-uuid.c", @@ -978,6 +1000,22 @@ const mingw32_arm64_src = [_][]const u8{ "math" ++ path.sep_str ++ "arm64" ++ path.sep_str ++ "sincosf.S", }; +const mingw32_winpthreads_src = [_][]const u8{ + // winpthreads + "winpthreads" ++ path.sep_str ++ "barrier.c", + "winpthreads" ++ path.sep_str ++ "clock.c", + "winpthreads" ++ path.sep_str ++ "cond.c", + "winpthreads" ++ path.sep_str ++ "misc.c", + "winpthreads" ++ path.sep_str ++ "mutex.c", + "winpthreads" ++ path.sep_str ++ "nanosleep.c", + "winpthreads" ++ path.sep_str ++ "ref.c", + "winpthreads" ++ path.sep_str ++ "rwlock.c", + "winpthreads" ++ path.sep_str ++ "sched.c", + "winpthreads" ++ path.sep_str ++ "sem.c", + "winpthreads" ++ path.sep_str ++ "spinlock.c", + "winpthreads" ++ path.sep_str ++ "thread.c", +}; + pub const always_link_libs = [_][]const u8{ "api-ms-win-crt-conio-l1-1-0", "api-ms-win-crt-convert-l1-1-0", |
