| ... | ... | @@ -32,7 +32,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre |
| 32 | 32 | switch (crt_file) { |
| 33 | 33 | .crt2_o => { |
| 34 | 34 | var args = std.ArrayList([]const u8).init(arena); |
| 35 | | try add_cc_args(comp, arena, &args); |
| 35 | try addCrtCcArgs(comp, arena, &args); |
| 36 | 36 | if (comp.mingw_unicode_entry_point) { |
| 37 | 37 | try args.appendSlice(&.{ "-DUNICODE", "-D_UNICODE" }); |
| 38 | 38 | } |
| ... | ... | @@ -52,7 +52,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre |
| 52 | 52 | |
| 53 | 53 | .dllcrt2_o => { |
| 54 | 54 | var args = std.ArrayList([]const u8).init(arena); |
| 55 | | try add_cc_args(comp, arena, &args); |
| 55 | try addCrtCcArgs(comp, arena, &args); |
| 56 | 56 | var files = [_]Compilation.CSourceFile{ |
| 57 | 57 | .{ |
| 58 | 58 | .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 |
| 68 | 68 | }, |
| 69 | 69 | |
| 70 | 70 | .mingw32_lib => { |
| 71 | | var args = std.ArrayList([]const u8).init(arena); |
| 72 | | try add_cc_args(comp, arena, &args); |
| 73 | 71 | var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena); |
| 74 | 72 | |
| 75 | | for (mingw32_generic_src) |dep| { |
| 76 | | try c_source_files.append(.{ |
| 77 | | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| 78 | | "libc", "mingw", dep, |
| 79 | | }), |
| 80 | | .extra_flags = args.items, |
| 81 | | .owner = undefined, |
| 82 | | }); |
| 83 | | } |
| 84 | | if (target.cpu.arch.isX86()) { |
| 85 | | for (mingw32_x86_src) |dep| { |
| 73 | { |
| 74 | var crt_args = std.ArrayList([]const u8).init(arena); |
| 75 | try addCrtCcArgs(comp, arena, &crt_args); |
| 76 | |
| 77 | for (mingw32_generic_src) |dep| { |
| 86 | 78 | try c_source_files.append(.{ |
| 87 | 79 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| 88 | 80 | "libc", "mingw", dep, |
| 89 | 81 | }), |
| 90 | | .extra_flags = args.items, |
| 82 | .extra_flags = crt_args.items, |
| 91 | 83 | .owner = undefined, |
| 92 | 84 | }); |
| 93 | 85 | } |
| 94 | | if (target.cpu.arch == .x86) { |
| 95 | | for (mingw32_x86_32_src) |dep| { |
| 86 | if (target.cpu.arch.isX86()) { |
| 87 | for (mingw32_x86_src) |dep| { |
| 96 | 88 | try c_source_files.append(.{ |
| 97 | 89 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| 98 | 90 | "libc", "mingw", dep, |
| 99 | 91 | }), |
| 100 | | .extra_flags = args.items, |
| 92 | .extra_flags = crt_args.items, |
| 101 | 93 | .owner = undefined, |
| 102 | 94 | }); |
| 103 | 95 | } |
| 96 | if (target.cpu.arch == .x86) { |
| 97 | for (mingw32_x86_32_src) |dep| { |
| 98 | try c_source_files.append(.{ |
| 99 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| 100 | "libc", "mingw", dep, |
| 101 | }), |
| 102 | .extra_flags = crt_args.items, |
| 103 | .owner = undefined, |
| 104 | }); |
| 105 | } |
| 106 | } |
| 107 | } else if (target.cpu.arch == .thumb) { |
| 108 | for (mingw32_arm_src) |dep| { |
| 109 | try c_source_files.append(.{ |
| 110 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| 111 | "libc", "mingw", dep, |
| 112 | }), |
| 113 | .extra_flags = crt_args.items, |
| 114 | .owner = undefined, |
| 115 | }); |
| 116 | } |
| 117 | for (mingw32_arm32_src) |dep| { |
| 118 | try c_source_files.append(.{ |
| 119 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| 120 | "libc", "mingw", dep, |
| 121 | }), |
| 122 | .extra_flags = crt_args.items, |
| 123 | .owner = undefined, |
| 124 | }); |
| 125 | } |
| 126 | } else if (target.cpu.arch == .aarch64) { |
| 127 | for (mingw32_arm_src) |dep| { |
| 128 | try c_source_files.append(.{ |
| 129 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| 130 | "libc", "mingw", dep, |
| 131 | }), |
| 132 | .extra_flags = crt_args.items, |
| 133 | .owner = undefined, |
| 134 | }); |
| 135 | } |
| 136 | for (mingw32_arm64_src) |dep| { |
| 137 | try c_source_files.append(.{ |
| 138 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| 139 | "libc", "mingw", dep, |
| 140 | }), |
| 141 | .extra_flags = crt_args.items, |
| 142 | .owner = undefined, |
| 143 | }); |
| 144 | } |
| 145 | } else { |
| 146 | @panic("unsupported arch"); |
| 104 | 147 | } |
| 105 | | } else if (target.cpu.arch.isThumb()) { |
| 106 | | for (mingw32_arm_src) |dep| { |
| 107 | | try c_source_files.append(.{ |
| 108 | | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| 109 | | "libc", "mingw", dep, |
| 110 | | }), |
| 111 | | .extra_flags = args.items, |
| 112 | | .owner = undefined, |
| 113 | | }); |
| 114 | | } |
| 115 | | for (mingw32_arm32_src) |dep| { |
| 116 | | try c_source_files.append(.{ |
| 117 | | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| 118 | | "libc", "mingw", dep, |
| 119 | | }), |
| 120 | | .extra_flags = args.items, |
| 121 | | .owner = undefined, |
| 122 | | }); |
| 123 | | } |
| 124 | | } else if (target.cpu.arch.isAARCH64()) { |
| 125 | | for (mingw32_arm_src) |dep| { |
| 126 | | try c_source_files.append(.{ |
| 127 | | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| 128 | | "libc", "mingw", dep, |
| 129 | | }), |
| 130 | | .extra_flags = args.items, |
| 131 | | .owner = undefined, |
| 132 | | }); |
| 148 | } |
| 149 | |
| 150 | { |
| 151 | var winpthreads_args = std.ArrayList([]const u8).init(arena); |
| 152 | try addCcArgs(comp, arena, &winpthreads_args); |
| 153 | try winpthreads_args.appendSlice(&[_][]const u8{ |
| 154 | "-DIN_WINPTHREAD", |
| 155 | "-DWIN32_LEAN_AND_MEAN", |
| 156 | }); |
| 157 | |
| 158 | switch (comp.compilerRtOptMode()) { |
| 159 | .Debug, .ReleaseSafe => try winpthreads_args.append("-DWINPTHREAD_DBG"), |
| 160 | .ReleaseFast, .ReleaseSmall => {}, |
| 133 | 161 | } |
| 134 | | for (mingw32_arm64_src) |dep| { |
| 162 | |
| 163 | for (mingw32_winpthreads_src) |dep| { |
| 135 | 164 | try c_source_files.append(.{ |
| 136 | 165 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| 137 | 166 | "libc", "mingw", dep, |
| 138 | 167 | }), |
| 139 | | .extra_flags = args.items, |
| 168 | .extra_flags = winpthreads_args.items, |
| 140 | 169 | .owner = undefined, |
| 141 | 170 | }); |
| 142 | 171 | } |
| 143 | | } else { |
| 144 | | @panic("unsupported arch"); |
| 145 | 172 | } |
| 173 | |
| 146 | 174 | return comp.build_crt_file("mingw32", .Lib, .@"mingw-w64 mingw32.lib", prog_node, c_source_files.items, .{ |
| 147 | 175 | .unwind_tables = unwind_tables, |
| 148 | 176 | }); |
| ... | ... | @@ -150,37 +178,44 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre |
| 150 | 178 | } |
| 151 | 179 | } |
| 152 | 180 | |
| 153 | | fn add_cc_args( |
| 181 | fn addCcArgs( |
| 154 | 182 | comp: *Compilation, |
| 155 | 183 | arena: Allocator, |
| 156 | 184 | args: *std.ArrayList([]const u8), |
| 157 | 185 | ) error{OutOfMemory}!void { |
| 158 | 186 | try args.appendSlice(&[_][]const u8{ |
| 159 | | "-DHAVE_CONFIG_H", |
| 160 | | |
| 161 | | "-I", |
| 162 | | try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "mingw", "include" }), |
| 187 | "-std=gnu11", |
| 188 | "-D__USE_MINGW_ANSI_STDIO=0", |
| 163 | 189 | |
| 164 | 190 | "-isystem", |
| 165 | 191 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "include", "any-windows-any" }), |
| 166 | 192 | }); |
| 193 | } |
| 167 | 194 | |
| 168 | | const target = comp.getTarget(); |
| 169 | | if (target.cpu.arch.isThumb()) { |
| 195 | fn addCrtCcArgs( |
| 196 | comp: *Compilation, |
| 197 | arena: Allocator, |
| 198 | args: *std.ArrayList([]const u8), |
| 199 | ) error{OutOfMemory}!void { |
| 200 | try addCcArgs(comp, arena, args); |
| 201 | |
| 202 | if (comp.getTarget().cpu.arch == .thumb) { |
| 170 | 203 | try args.append("-mfpu=vfp"); |
| 171 | 204 | } |
| 172 | 205 | |
| 173 | 206 | try args.appendSlice(&[_][]const u8{ |
| 174 | | "-std=gnu11", |
| 175 | | "-D_CRTBLD", |
| 176 | | "-D_SYSCRT=1", |
| 177 | | "-DCRTDLL=1", |
| 178 | | "-D_WIN32_WINNT=0x0f00", |
| 179 | 207 | // According to Martin Storsjö, |
| 180 | 208 | // > the files under mingw-w64-crt are designed to always |
| 181 | 209 | // be built with __MSVCRT_VERSION__=0x700 |
| 182 | 210 | "-D__MSVCRT_VERSION__=0x700", |
| 183 | | "-D__USE_MINGW_ANSI_STDIO=0", |
| 211 | "-D_CRTBLD", |
| 212 | "-D_SYSCRT=1", |
| 213 | "-D_WIN32_WINNT=0x0f00", |
| 214 | "-DCRTDLL=1", |
| 215 | "-DHAVE_CONFIG_H", |
| 216 | |
| 217 | "-I", |
| 218 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "mingw", "include" }), |
| 184 | 219 | }); |
| 185 | 220 | } |
| 186 | 221 | |
| ... | ... | @@ -736,19 +771,6 @@ const mingw32_generic_src = [_][]const u8{ |
| 736 | 771 | "stdio" ++ path.sep_str ++ "ucrt_vsprintf.c", |
| 737 | 772 | "stdio" ++ path.sep_str ++ "ucrt_vsscanf.c", |
| 738 | 773 | "string" ++ path.sep_str ++ "ucrt__wcstok.c", |
| 739 | | // winpthreads |
| 740 | | "winpthreads" ++ path.sep_str ++ "barrier.c", |
| 741 | | "winpthreads" ++ path.sep_str ++ "clock.c", |
| 742 | | "winpthreads" ++ path.sep_str ++ "cond.c", |
| 743 | | "winpthreads" ++ path.sep_str ++ "misc.c", |
| 744 | | "winpthreads" ++ path.sep_str ++ "mutex.c", |
| 745 | | "winpthreads" ++ path.sep_str ++ "nanosleep.c", |
| 746 | | "winpthreads" ++ path.sep_str ++ "ref.c", |
| 747 | | "winpthreads" ++ path.sep_str ++ "rwlock.c", |
| 748 | | "winpthreads" ++ path.sep_str ++ "sched.c", |
| 749 | | "winpthreads" ++ path.sep_str ++ "sem.c", |
| 750 | | "winpthreads" ++ path.sep_str ++ "spinlock.c", |
| 751 | | "winpthreads" ++ path.sep_str ++ "thread.c", |
| 752 | 774 | // uuid |
| 753 | 775 | "libsrc" ++ path.sep_str ++ "ativscp-uuid.c", |
| 754 | 776 | "libsrc" ++ path.sep_str ++ "atsmedia-uuid.c", |
| ... | ... | @@ -978,6 +1000,22 @@ const mingw32_arm64_src = [_][]const u8{ |
| 978 | 1000 | "math" ++ path.sep_str ++ "arm64" ++ path.sep_str ++ "sincosf.S", |
| 979 | 1001 | }; |
| 980 | 1002 | |
| 1003 | const mingw32_winpthreads_src = [_][]const u8{ |
| 1004 | // winpthreads |
| 1005 | "winpthreads" ++ path.sep_str ++ "barrier.c", |
| 1006 | "winpthreads" ++ path.sep_str ++ "clock.c", |
| 1007 | "winpthreads" ++ path.sep_str ++ "cond.c", |
| 1008 | "winpthreads" ++ path.sep_str ++ "misc.c", |
| 1009 | "winpthreads" ++ path.sep_str ++ "mutex.c", |
| 1010 | "winpthreads" ++ path.sep_str ++ "nanosleep.c", |
| 1011 | "winpthreads" ++ path.sep_str ++ "ref.c", |
| 1012 | "winpthreads" ++ path.sep_str ++ "rwlock.c", |
| 1013 | "winpthreads" ++ path.sep_str ++ "sched.c", |
| 1014 | "winpthreads" ++ path.sep_str ++ "sem.c", |
| 1015 | "winpthreads" ++ path.sep_str ++ "spinlock.c", |
| 1016 | "winpthreads" ++ path.sep_str ++ "thread.c", |
| 1017 | }; |
| 1018 | |
| 981 | 1019 | pub const always_link_libs = [_][]const u8{ |
| 982 | 1020 | "api-ms-win-crt-conio-l1-1-0", |
| 983 | 1021 | "api-ms-win-crt-convert-l1-1-0", |