| ... | @@ -32,7 +32,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre | ... | @@ -32,7 +32,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre |
| 32 | switch (crt_file) { | 32 | switch (crt_file) { |
| 33 | .crt2_o => { | 33 | .crt2_o => { |
| 34 | var args = std.ArrayList([]const u8).init(arena); | 34 | var args = std.ArrayList([]const u8).init(arena); |
| 35 | try add_cc_args(comp, arena, &args); | 35 | try addCrtCcArgs(comp, arena, &args); |
| 36 | if (comp.mingw_unicode_entry_point) { | 36 | if (comp.mingw_unicode_entry_point) { |
| 37 | try args.appendSlice(&.{ "-DUNICODE", "-D_UNICODE" }); | 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,7 +52,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre |
| 52 | | 52 | |
| 53 | .dllcrt2_o => { | 53 | .dllcrt2_o => { |
| 54 | var args = std.ArrayList([]const u8).init(arena); | 54 | var args = std.ArrayList([]const u8).init(arena); |
| 55 | try add_cc_args(comp, arena, &args); | 55 | try addCrtCcArgs(comp, arena, &args); |
| 56 | var files = [_]Compilation.CSourceFile{ | 56 | var files = [_]Compilation.CSourceFile{ |
| 57 | .{ | 57 | .{ |
| 58 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ | 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,81 +68,109 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre |
| 68 | }, | 68 | }, |
| 69 | | 69 | |
| 70 | .mingw32_lib => { | 70 | .mingw32_lib => { |
| 71 | var args = std.ArrayList([]const u8).init(arena); | | |
| 72 | try add_cc_args(comp, arena, &args); | | |
| 73 | var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena); | 71 | var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena); |
| 74 | | 72 | |
| 75 | for (mingw32_generic_src) |dep| { | 73 | { |
| 76 | try c_source_files.append(.{ | 74 | var crt_args = std.ArrayList([]const u8).init(arena); |
| 77 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ | 75 | try addCrtCcArgs(comp, arena, &crt_args); |
| 78 | "libc", "mingw", dep, | 76 | |
| 79 | }), | 77 | for (mingw32_generic_src) |dep| { |
| 80 | .extra_flags = args.items, | | |
| 81 | .owner = undefined, | | |
| 82 | }); | | |
| 83 | } | | |
| 84 | if (target.cpu.arch.isX86()) { | | |
| 85 | for (mingw32_x86_src) |dep| { | | |
| 86 | try c_source_files.append(.{ | 78 | try c_source_files.append(.{ |
| 87 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ | 79 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| 88 | "libc", "mingw", dep, | 80 | "libc", "mingw", dep, |
| 89 | }), | 81 | }), |
| 90 | .extra_flags = args.items, | 82 | .extra_flags = crt_args.items, |
| 91 | .owner = undefined, | 83 | .owner = undefined, |
| 92 | }); | 84 | }); |
| 93 | } | 85 | } |
| 94 | if (target.cpu.arch == .x86) { | 86 | if (target.cpu.arch.isX86()) { |
| 95 | for (mingw32_x86_32_src) |dep| { | 87 | for (mingw32_x86_src) |dep| { |
| 96 | try c_source_files.append(.{ | 88 | try c_source_files.append(.{ |
| 97 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ | 89 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| 98 | "libc", "mingw", dep, | 90 | "libc", "mingw", dep, |
| 99 | }), | 91 | }), |
| 100 | .extra_flags = args.items, | 92 | .extra_flags = crt_args.items, |
| 101 | .owner = undefined, | 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()) { | 148 | } |
| 106 | for (mingw32_arm_src) |dep| { | 149 | |
| 107 | try c_source_files.append(.{ | 150 | { |
| 108 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ | 151 | var winpthreads_args = std.ArrayList([]const u8).init(arena); |
| 109 | "libc", "mingw", dep, | 152 | try addCcArgs(comp, arena, &winpthreads_args); |
| 110 | }), | 153 | try winpthreads_args.appendSlice(&[_][]const u8{ |
| 111 | .extra_flags = args.items, | 154 | "-DIN_WINPTHREAD", |
| 112 | .owner = undefined, | 155 | "-DWIN32_LEAN_AND_MEAN", |
| 113 | }); | 156 | }); |
| 114 | } | 157 | |
| 115 | for (mingw32_arm32_src) |dep| { | 158 | switch (comp.compilerRtOptMode()) { |
| 116 | try c_source_files.append(.{ | 159 | .Debug, .ReleaseSafe => try winpthreads_args.append("-DWINPTHREAD_DBG"), |
| 117 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ | 160 | .ReleaseFast, .ReleaseSmall => {}, |
| 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 | }); | | |
| 133 | } | 161 | } |
| 134 | for (mingw32_arm64_src) |dep| { | 162 | |
| | 163 | for (mingw32_winpthreads_src) |dep| { |
| 135 | try c_source_files.append(.{ | 164 | try c_source_files.append(.{ |
| 136 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ | 165 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| 137 | "libc", "mingw", dep, | 166 | "libc", "mingw", dep, |
| 138 | }), | 167 | }), |
| 139 | .extra_flags = args.items, | 168 | .extra_flags = winpthreads_args.items, |
| 140 | .owner = undefined, | 169 | .owner = undefined, |
| 141 | }); | 170 | }); |
| 142 | } | 171 | } |
| 143 | } else { | | |
| 144 | @panic("unsupported arch"); | | |
| 145 | } | 172 | } |
| | 173 | |
| 146 | return comp.build_crt_file("mingw32", .Lib, .@"mingw-w64 mingw32.lib", prog_node, c_source_files.items, .{ | 174 | return comp.build_crt_file("mingw32", .Lib, .@"mingw-w64 mingw32.lib", prog_node, c_source_files.items, .{ |
| 147 | .unwind_tables = unwind_tables, | 175 | .unwind_tables = unwind_tables, |
| 148 | }); | 176 | }); |
| ... | @@ -150,37 +178,44 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre | ... | @@ -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 | comp: *Compilation, | 182 | comp: *Compilation, |
| 155 | arena: Allocator, | 183 | arena: Allocator, |
| 156 | args: *std.ArrayList([]const u8), | 184 | args: *std.ArrayList([]const u8), |
| 157 | ) error{OutOfMemory}!void { | 185 | ) error{OutOfMemory}!void { |
| 158 | try args.appendSlice(&[_][]const u8{ | 186 | try args.appendSlice(&[_][]const u8{ |
| 159 | "-DHAVE_CONFIG_H", | 187 | "-std=gnu11", |
| 160 | | 188 | "-D__USE_MINGW_ANSI_STDIO=0", |
| 161 | "-I", | | |
| 162 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "mingw", "include" }), | | |
| 163 | | 189 | |
| 164 | "-isystem", | 190 | "-isystem", |
| 165 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "include", "any-windows-any" }), | 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(); | 195 | fn addCrtCcArgs( |
| 169 | if (target.cpu.arch.isThumb()) { | 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 | try args.append("-mfpu=vfp"); | 203 | try args.append("-mfpu=vfp"); |
| 171 | } | 204 | } |
| 172 | | 205 | |
| 173 | try args.appendSlice(&[_][]const u8{ | 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 | // According to Martin Storsjö, | 207 | // According to Martin Storsjö, |
| 180 | // > the files under mingw-w64-crt are designed to always | 208 | // > the files under mingw-w64-crt are designed to always |
| 181 | // be built with __MSVCRT_VERSION__=0x700 | 209 | // be built with __MSVCRT_VERSION__=0x700 |
| 182 | "-D__MSVCRT_VERSION__=0x700", | 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,19 +771,6 @@ const mingw32_generic_src = [_][]const u8{ |
| 736 | "stdio" ++ path.sep_str ++ "ucrt_vsprintf.c", | 771 | "stdio" ++ path.sep_str ++ "ucrt_vsprintf.c", |
| 737 | "stdio" ++ path.sep_str ++ "ucrt_vsscanf.c", | 772 | "stdio" ++ path.sep_str ++ "ucrt_vsscanf.c", |
| 738 | "string" ++ path.sep_str ++ "ucrt__wcstok.c", | 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 | // uuid | 774 | // uuid |
| 753 | "libsrc" ++ path.sep_str ++ "ativscp-uuid.c", | 775 | "libsrc" ++ path.sep_str ++ "ativscp-uuid.c", |
| 754 | "libsrc" ++ path.sep_str ++ "atsmedia-uuid.c", | 776 | "libsrc" ++ path.sep_str ++ "atsmedia-uuid.c", |
| ... | @@ -978,6 +1000,22 @@ const mingw32_arm64_src = [_][]const u8{ | ... | @@ -978,6 +1000,22 @@ const mingw32_arm64_src = [_][]const u8{ |
| 978 | "math" ++ path.sep_str ++ "arm64" ++ path.sep_str ++ "sincosf.S", | 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 | pub const always_link_libs = [_][]const u8{ | 1019 | pub const always_link_libs = [_][]const u8{ |
| 982 | "api-ms-win-crt-conio-l1-1-0", | 1020 | "api-ms-win-crt-conio-l1-1-0", |
| 983 | "api-ms-win-crt-convert-l1-1-0", | 1021 | "api-ms-win-crt-convert-l1-1-0", |