authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-03-28 14:16:30-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-03-28 14:16:30-07:00
log3661133f989fefa64c58447dd0073b8c0e8050fc
treec1cd62ba6278ab912f9fcdbc0b6ea27778b2dc10
parentc808e546a766192c4a9bd45190d4bcfae61d6f3b
parentbad9efbcc140ce5e9837ef06652610636593c1d0
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #19399 from ypsvlq/mingw

mingw: support -municode

15 files changed, 231 insertions(+), 26 deletions(-)

lib/libc/mingw/crt/crtexewin.c created+68
...@@ -0,0 +1,68 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6#include <windows.h>
7#include <tchar.h>
8#include <corecrt_startup.h>
9
10#ifndef _UNICODE
11#include <mbctype.h>
12#endif
13
14#define SPACECHAR _T(' ')
15#define DQUOTECHAR _T('\"')
16
17extern IMAGE_DOS_HEADER __ImageBase;
18
19int _tmain (int, _TCHAR **, _TCHAR **);
20int _tmain (int __UNUSED_PARAM(argc),
21 _TCHAR ** __UNUSED_PARAM(argv),
22 _TCHAR ** __UNUSED_PARAM(envp))
23{
24 HINSTANCE hInstance;
25 _TCHAR *lpCmdLine;
26 DWORD nShowCmd;
27
28 hInstance = (HINSTANCE) &__ImageBase;
29
30#ifdef _UNICODE
31 lpCmdLine = _wcmdln;
32#else
33 lpCmdLine = _acmdln;
34#endif
35 if (lpCmdLine)
36 {
37 BOOL inDoubleQuote = FALSE;
38 while (*lpCmdLine > SPACECHAR || (*lpCmdLine && inDoubleQuote))
39 {
40 if (*lpCmdLine == DQUOTECHAR)
41 inDoubleQuote = !inDoubleQuote;
42#ifndef _UNICODE
43 if (_ismbblead (*lpCmdLine))
44 {
45 if (lpCmdLine[1])
46 ++lpCmdLine;
47 }
48#endif
49 ++lpCmdLine;
50 }
51 while (*lpCmdLine && (*lpCmdLine <= SPACECHAR))
52 lpCmdLine++;
53 }
54 else
55 lpCmdLine = _TEXT("");
56
57 {
58 STARTUPINFO StartupInfo;
59 memset (&StartupInfo, 0, sizeof (STARTUPINFO));
60 GetStartupInfo (&StartupInfo);
61 if (StartupInfo.dwFlags & STARTF_USESHOWWINDOW)
62 nShowCmd = StartupInfo.wShowWindow;
63 else
64 nShowCmd = SW_SHOWDEFAULT;
65 }
66
67 return _tWinMain (hInstance, NULL, lpCmdLine, nShowCmd);
68}
lib/libc/mingw/crt/ucrtexewin.c created+14
...@@ -0,0 +1,14 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#ifndef UNICODE
8#define UNICODE
9#endif
10#ifndef _UNICODE
11#define _UNICODE
12#endif
13
14#include "crtexewin.c"
lib/std/Build/Step/Compile.zig+7
...@@ -161,6 +161,9 @@ dll_export_fns: ?bool = null,...@@ -161,6 +161,9 @@ dll_export_fns: ?bool = null,
161161
162subsystem: ?std.Target.SubSystem = null,162subsystem: ?std.Target.SubSystem = null,
163163
164/// (Windows) When targeting the MinGW ABI, use the unicode entry point (wmain/wWinMain)
165mingw_unicode_entry_point: bool = false,
166
164/// How the linker must handle the entry point of the executable.167/// How the linker must handle the entry point of the executable.
165entry: Entry = .default,168entry: Entry = .default,
166169
...@@ -1583,6 +1586,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -1583,6 +1586,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
1583 });1586 });
1584 }1587 }
15851588
1589 if (self.mingw_unicode_entry_point) {
1590 try zig_args.append("-municode");
1591 }
1592
1586 if (self.error_limit) |err_limit| try zig_args.appendSlice(&.{1593 if (self.error_limit) |err_limit| try zig_args.appendSlice(&.{
1587 "--error-limit",1594 "--error-limit",
1588 b.fmt("{}", .{err_limit}),1595 b.fmt("{}", .{err_limit}),
src/Compilation.zig+5-2
...@@ -173,6 +173,7 @@ global_cache_directory: Directory,...@@ -173,6 +173,7 @@ global_cache_directory: Directory,
173libc_include_dir_list: []const []const u8,173libc_include_dir_list: []const []const u8,
174libc_framework_dir_list: []const []const u8,174libc_framework_dir_list: []const []const u8,
175rc_includes: RcIncludes,175rc_includes: RcIncludes,
176mingw_unicode_entry_point: bool,
176thread_pool: *ThreadPool,177thread_pool: *ThreadPool,
177178
178/// Populated when we build the libc++ static library. A Job to build this is placed in the queue179/// Populated when we build the libc++ static library. A Job to build this is placed in the queue
...@@ -758,7 +759,7 @@ pub const MiscTask = enum {...@@ -758,7 +759,7 @@ pub const MiscTask = enum {
758759
759 @"mingw-w64 crt2.o",760 @"mingw-w64 crt2.o",
760 @"mingw-w64 dllcrt2.o",761 @"mingw-w64 dllcrt2.o",
761 @"mingw-w64 mingwex.lib",762 @"mingw-w64 mingw32.lib",
762};763};
763764
764pub const MiscError = struct {765pub const MiscError = struct {
...@@ -1101,6 +1102,7 @@ pub const CreateOptions = struct {...@@ -1101,6 +1102,7 @@ pub const CreateOptions = struct {
1101 test_name_prefix: ?[]const u8 = null,1102 test_name_prefix: ?[]const u8 = null,
1102 test_runner_path: ?[]const u8 = null,1103 test_runner_path: ?[]const u8 = null,
1103 subsystem: ?std.Target.SubSystem = null,1104 subsystem: ?std.Target.SubSystem = null,
1105 mingw_unicode_entry_point: bool = false,
1104 /// (Zig compiler development) Enable dumping linker's state as JSON.1106 /// (Zig compiler development) Enable dumping linker's state as JSON.
1105 enable_link_snapshots: bool = false,1107 enable_link_snapshots: bool = false,
1106 /// (Darwin) Install name of the dylib1108 /// (Darwin) Install name of the dylib
...@@ -1427,6 +1429,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil...@@ -1427,6 +1429,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
1427 .libc_include_dir_list = libc_dirs.libc_include_dir_list,1429 .libc_include_dir_list = libc_dirs.libc_include_dir_list,
1428 .libc_framework_dir_list = libc_dirs.libc_framework_dir_list,1430 .libc_framework_dir_list = libc_dirs.libc_framework_dir_list,
1429 .rc_includes = options.rc_includes,1431 .rc_includes = options.rc_includes,
1432 .mingw_unicode_entry_point = options.mingw_unicode_entry_point,
1430 .thread_pool = options.thread_pool,1433 .thread_pool = options.thread_pool,
1431 .clang_passthrough_mode = options.clang_passthrough_mode,1434 .clang_passthrough_mode = options.clang_passthrough_mode,
1432 .clang_preprocessor_mode = options.clang_preprocessor_mode,1435 .clang_preprocessor_mode = options.clang_preprocessor_mode,
...@@ -1768,7 +1771,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil...@@ -1768,7 +1771,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
17681771
1769 const crt_job: Job = .{ .mingw_crt_file = if (is_dyn_lib) .dllcrt2_o else .crt2_o };1772 const crt_job: Job = .{ .mingw_crt_file = if (is_dyn_lib) .dllcrt2_o else .crt2_o };
1770 try comp.work_queue.ensureUnusedCapacity(2);1773 try comp.work_queue.ensureUnusedCapacity(2);
1771 comp.work_queue.writeItemAssumeCapacity(.{ .mingw_crt_file = .mingwex_lib });1774 comp.work_queue.writeItemAssumeCapacity(.{ .mingw_crt_file = .mingw32_lib });
1772 comp.work_queue.writeItemAssumeCapacity(crt_job);1775 comp.work_queue.writeItemAssumeCapacity(crt_job);
17731776
1774 // When linking mingw-w64 there are some import libs we always need.1777 // When linking mingw-w64 there are some import libs we always need.
src/clang_options_data.zig+8-1
...@@ -6895,7 +6895,14 @@ joinpd1("mdouble="),...@@ -6895,7 +6895,14 @@ joinpd1("mdouble="),
6895joinpd1("mfpmath="),6895joinpd1("mfpmath="),
6896joinpd1("mhwmult="),6896joinpd1("mhwmult="),
6897joinpd1("mthreads"),6897joinpd1("mthreads"),
6898joinpd1("municode"),6898.{
6899 .name = "municode",
6900 .syntax = .joined,
6901 .zig_equivalent = .mingw_unicode_entry_point,
6902 .pd1 = true,
6903 .pd2 = false,
6904 .psl = false,
6905},
6899joinpd1("mwindows"),6906joinpd1("mwindows"),
6900.{6907.{
6901 .name = "offload=",6908 .name = "offload=",
src/link/Coff/lld.zig+1-1
...@@ -409,7 +409,7 @@ pub fn linkWithLLD(self: *Coff, arena: Allocator, prog_node: *std.Progress.Node)...@@ -409,7 +409,7 @@ pub fn linkWithLLD(self: *Coff, arena: Allocator, prog_node: *std.Progress.Node)
409 try argv.append(try comp.get_libc_crt_file(arena, "crt2.obj"));409 try argv.append(try comp.get_libc_crt_file(arena, "crt2.obj"));
410 }410 }
411411
412 try argv.append(try comp.get_libc_crt_file(arena, "mingwex.lib"));412 try argv.append(try comp.get_libc_crt_file(arena, "mingw32.lib"));
413 } else {413 } else {
414 const lib_str = switch (comp.config.link_mode) {414 const lib_str = switch (comp.config.link_mode) {
415 .dynamic => "",415 .dynamic => "",
src/main.zig+7
...@@ -450,6 +450,7 @@ const usage_build_generic =...@@ -450,6 +450,7 @@ const usage_build_generic =
450 \\ -fstructured-cfg (SPIR-V) force SPIR-V kernels to use structured control flow450 \\ -fstructured-cfg (SPIR-V) force SPIR-V kernels to use structured control flow
451 \\ -fno-structured-cfg (SPIR-V) force SPIR-V kernels to not use structured control flow451 \\ -fno-structured-cfg (SPIR-V) force SPIR-V kernels to not use structured control flow
452 \\ -mexec-model=[value] (WASI) Execution model452 \\ -mexec-model=[value] (WASI) Execution model
453 \\ -municode (Windows) Use wmain/wWinMain as entry point
453 \\454 \\
454 \\Per-Module Compile Options:455 \\Per-Module Compile Options:
455 \\ -target [name] <arch><sub>-<os>-<abi> see the targets command456 \\ -target [name] <arch><sub>-<os>-<abi> see the targets command
...@@ -893,6 +894,7 @@ fn buildOutputType(...@@ -893,6 +894,7 @@ fn buildOutputType(
893 var subsystem: ?std.Target.SubSystem = null;894 var subsystem: ?std.Target.SubSystem = null;
894 var major_subsystem_version: ?u16 = null;895 var major_subsystem_version: ?u16 = null;
895 var minor_subsystem_version: ?u16 = null;896 var minor_subsystem_version: ?u16 = null;
897 var mingw_unicode_entry_point: bool = false;
896 var enable_link_snapshots: bool = false;898 var enable_link_snapshots: bool = false;
897 var debug_incremental: bool = false;899 var debug_incremental: bool = false;
898 var install_name: ?[]const u8 = null;900 var install_name: ?[]const u8 = null;
...@@ -1686,6 +1688,8 @@ fn buildOutputType(...@@ -1686,6 +1688,8 @@ fn buildOutputType(
1686 }1688 }
1687 } else if (mem.startsWith(u8, arg, "-mexec-model=")) {1689 } else if (mem.startsWith(u8, arg, "-mexec-model=")) {
1688 create_module.opts.wasi_exec_model = parseWasiExecModel(arg["-mexec-model=".len..]);1690 create_module.opts.wasi_exec_model = parseWasiExecModel(arg["-mexec-model=".len..]);
1691 } else if (mem.eql(u8, arg, "-municode")) {
1692 mingw_unicode_entry_point = true;
1689 } else {1693 } else {
1690 fatal("unrecognized parameter: '{s}'", .{arg});1694 fatal("unrecognized parameter: '{s}'", .{arg});
1691 }1695 }
...@@ -2091,6 +2095,7 @@ fn buildOutputType(...@@ -2091,6 +2095,7 @@ fn buildOutputType(
2091 try force_undefined_symbols.put(arena, it.only_arg, {});2095 try force_undefined_symbols.put(arena, it.only_arg, {});
2092 },2096 },
2093 .force_load_objc => force_load_objc = true,2097 .force_load_objc => force_load_objc = true,
2098 .mingw_unicode_entry_point => mingw_unicode_entry_point = true,
2094 .weak_library => try create_module.system_libs.put(arena, it.only_arg, .{2099 .weak_library => try create_module.system_libs.put(arena, it.only_arg, .{
2095 .needed = false,2100 .needed = false,
2096 .weak = true,2101 .weak = true,
...@@ -3229,6 +3234,7 @@ fn buildOutputType(...@@ -3229,6 +3234,7 @@ fn buildOutputType(
3229 .rc_source_files = create_module.rc_source_files.items,3234 .rc_source_files = create_module.rc_source_files.items,
3230 .manifest_file = manifest_file,3235 .manifest_file = manifest_file,
3231 .rc_includes = rc_includes,3236 .rc_includes = rc_includes,
3237 .mingw_unicode_entry_point = mingw_unicode_entry_point,
3232 .link_objects = create_module.link_objects.items,3238 .link_objects = create_module.link_objects.items,
3233 .framework_dirs = create_module.framework_dirs.items,3239 .framework_dirs = create_module.framework_dirs.items,
3234 .frameworks = resolved_frameworks.items,3240 .frameworks = resolved_frameworks.items,
...@@ -5792,6 +5798,7 @@ pub const ClangArgIterator = struct {...@@ -5792,6 +5798,7 @@ pub const ClangArgIterator = struct {
5792 install_name,5798 install_name,
5793 undefined,5799 undefined,
5794 force_load_objc,5800 force_load_objc,
5801 mingw_unicode_entry_point,
5795 };5802 };
57965803
5797 const Args = struct {5804 const Args = struct {
src/mingw.zig+18-22
...@@ -13,7 +13,7 @@ const Cache = std.Build.Cache;...@@ -13,7 +13,7 @@ const Cache = std.Build.Cache;
13pub const CRTFile = enum {13pub const CRTFile = enum {
14 crt2_o,14 crt2_o,
15 dllcrt2_o,15 dllcrt2_o,
16 mingwex_lib,16 mingw32_lib,
17};17};
1818
19pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progress.Node) !void {19pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progress.Node) !void {
...@@ -28,14 +28,9 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr...@@ -28,14 +28,9 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
28 .crt2_o => {28 .crt2_o => {
29 var args = std.ArrayList([]const u8).init(arena);29 var args = std.ArrayList([]const u8).init(arena);
30 try add_cc_args(comp, arena, &args);30 try add_cc_args(comp, arena, &args);
31 try args.appendSlice(&[_][]const u8{31 if (comp.mingw_unicode_entry_point) {
32 // Prevents warning: 'used' attribute ignored on a non-definition declaration32 try args.appendSlice(&.{ "-DUNICODE", "-D_UNICODE" });
33 // pointing at extern _CRTALLOC33 }
34 "-Wno-ignored-attributes",
35 // Uncommenting this makes mingw-w64 look for wmain instead of main.
36 //"-DUNICODE",
37 //"-D_UNICODE",
38 });
39 var files = [_]Compilation.CSourceFile{34 var files = [_]Compilation.CSourceFile{
40 .{35 .{
41 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{36 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
...@@ -63,12 +58,12 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr...@@ -63,12 +58,12 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
63 return comp.build_crt_file("dllcrt2", .Obj, .@"mingw-w64 dllcrt2.o", prog_node, &files);58 return comp.build_crt_file("dllcrt2", .Obj, .@"mingw-w64 dllcrt2.o", prog_node, &files);
64 },59 },
6560
66 .mingwex_lib => {61 .mingw32_lib => {
67 var args = std.ArrayList([]const u8).init(arena);62 var args = std.ArrayList([]const u8).init(arena);
68 try add_cc_args(comp, arena, &args);63 try add_cc_args(comp, arena, &args);
69 var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena);64 var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena);
7065
71 for (mingwex_generic_src) |dep| {66 for (mingw32_generic_src) |dep| {
72 try c_source_files.append(.{67 try c_source_files.append(.{
73 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{68 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
74 "libc", "mingw", dep,69 "libc", "mingw", dep,
...@@ -79,7 +74,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr...@@ -79,7 +74,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
79 }74 }
80 const target = comp.getTarget();75 const target = comp.getTarget();
81 if (target.cpu.arch == .x86 or target.cpu.arch == .x86_64) {76 if (target.cpu.arch == .x86 or target.cpu.arch == .x86_64) {
82 for (mingwex_x86_src) |dep| {77 for (mingw32_x86_src) |dep| {
83 try c_source_files.append(.{78 try c_source_files.append(.{
84 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{79 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
85 "libc", "mingw", dep,80 "libc", "mingw", dep,
...@@ -89,7 +84,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr...@@ -89,7 +84,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
89 });84 });
90 }85 }
91 if (target.cpu.arch == .x86) {86 if (target.cpu.arch == .x86) {
92 for (mingwex_x86_32_src) |dep| {87 for (mingw32_x86_32_src) |dep| {
93 try c_source_files.append(.{88 try c_source_files.append(.{
94 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{89 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
95 "libc", "mingw", dep,90 "libc", "mingw", dep,
...@@ -100,7 +95,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr...@@ -100,7 +95,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
100 }95 }
101 }96 }
102 } else if (target.cpu.arch.isARM()) {97 } else if (target.cpu.arch.isARM()) {
103 for (mingwex_arm32_src) |dep| {98 for (mingw32_arm32_src) |dep| {
104 try c_source_files.append(.{99 try c_source_files.append(.{
105 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{100 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
106 "libc", "mingw", dep,101 "libc", "mingw", dep,
...@@ -110,7 +105,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr...@@ -110,7 +105,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
110 });105 });
111 }106 }
112 } else if (target.cpu.arch.isAARCH64()) {107 } else if (target.cpu.arch.isAARCH64()) {
113 for (mingwex_arm64_src) |dep| {108 for (mingw32_arm64_src) |dep| {
114 try c_source_files.append(.{109 try c_source_files.append(.{
115 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{110 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
116 "libc", "mingw", dep,111 "libc", "mingw", dep,
...@@ -122,7 +117,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr...@@ -122,7 +117,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
122 } else {117 } else {
123 @panic("unsupported arch");118 @panic("unsupported arch");
124 }119 }
125 return comp.build_crt_file("mingwex", .Lib, .@"mingw-w64 mingwex.lib", prog_node, c_source_files.items);120 return comp.build_crt_file("mingw32", .Lib, .@"mingw-w64 mingw32.lib", prog_node, c_source_files.items);
126 },121 },
127 }122 }
128}123}
...@@ -389,14 +384,16 @@ fn findDef(...@@ -389,14 +384,16 @@ fn findDef(
389 return error.FileNotFound;384 return error.FileNotFound;
390}385}
391386
392const mingwex_generic_src = [_][]const u8{387const mingw32_generic_src = [_][]const u8{
393 // mingw32388 // mingw32
389 "crt" ++ path.sep_str ++ "crtexewin.c",
394 "crt" ++ path.sep_str ++ "dll_argv.c",390 "crt" ++ path.sep_str ++ "dll_argv.c",
395 "crt" ++ path.sep_str ++ "gccmain.c",391 "crt" ++ path.sep_str ++ "gccmain.c",
396 "crt" ++ path.sep_str ++ "natstart.c",392 "crt" ++ path.sep_str ++ "natstart.c",
397 "crt" ++ path.sep_str ++ "pseudo-reloc-list.c",393 "crt" ++ path.sep_str ++ "pseudo-reloc-list.c",
398 "crt" ++ path.sep_str ++ "wildcard.c",394 "crt" ++ path.sep_str ++ "wildcard.c",
399 "crt" ++ path.sep_str ++ "charmax.c",395 "crt" ++ path.sep_str ++ "charmax.c",
396 "crt" ++ path.sep_str ++ "ucrtexewin.c",
400 "crt" ++ path.sep_str ++ "dllargv.c",397 "crt" ++ path.sep_str ++ "dllargv.c",
401 "crt" ++ path.sep_str ++ "_newmode.c",398 "crt" ++ path.sep_str ++ "_newmode.c",
402 "crt" ++ path.sep_str ++ "tlssup.c",399 "crt" ++ path.sep_str ++ "tlssup.c",
...@@ -814,7 +811,7 @@ const mingwex_generic_src = [_][]const u8{...@@ -814,7 +811,7 @@ const mingwex_generic_src = [_][]const u8{
814 "libsrc" ++ path.sep_str ++ "activeds-uuid.c",811 "libsrc" ++ path.sep_str ++ "activeds-uuid.c",
815};812};
816813
817const mingwex_x86_src = [_][]const u8{814const mingw32_x86_src = [_][]const u8{
818 // mingwex815 // mingwex
819 "math" ++ path.sep_str ++ "cbrtl.c",816 "math" ++ path.sep_str ++ "cbrtl.c",
820 "math" ++ path.sep_str ++ "erfl.c",817 "math" ++ path.sep_str ++ "erfl.c",
...@@ -873,8 +870,7 @@ const mingwex_x86_src = [_][]const u8{...@@ -873,8 +870,7 @@ const mingwex_x86_src = [_][]const u8{
873 "math" ++ path.sep_str ++ "nexttowardf.c",870 "math" ++ path.sep_str ++ "nexttowardf.c",
874};871};
875872
876const mingwex_x86_32_src = [_][]const u8{873const mingw32_x86_32_src = [_][]const u8{
877 // ucrtbase
878 "math" ++ path.sep_str ++ "coshf.c",874 "math" ++ path.sep_str ++ "coshf.c",
879 "math" ++ path.sep_str ++ "expf.c",875 "math" ++ path.sep_str ++ "expf.c",
880 "math" ++ path.sep_str ++ "log10f.c",876 "math" ++ path.sep_str ++ "log10f.c",
...@@ -896,7 +892,7 @@ const mingwex_x86_32_src = [_][]const u8{...@@ -896,7 +892,7 @@ const mingwex_x86_32_src = [_][]const u8{
896 "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "tanf.c",892 "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "tanf.c",
897};893};
898894
899const mingwex_arm32_src = [_][]const u8{895const mingw32_arm32_src = [_][]const u8{
900 "math" ++ path.sep_str ++ "arm-common" ++ path.sep_str ++ "ldexpl.c",896 "math" ++ path.sep_str ++ "arm-common" ++ path.sep_str ++ "ldexpl.c",
901 "math" ++ path.sep_str ++ "arm" ++ path.sep_str ++ "_chgsignl.S",897 "math" ++ path.sep_str ++ "arm" ++ path.sep_str ++ "_chgsignl.S",
902 "math" ++ path.sep_str ++ "arm" ++ path.sep_str ++ "s_rint.c",898 "math" ++ path.sep_str ++ "arm" ++ path.sep_str ++ "s_rint.c",
...@@ -905,7 +901,7 @@ const mingwex_arm32_src = [_][]const u8{...@@ -905,7 +901,7 @@ const mingwex_arm32_src = [_][]const u8{
905 "math" ++ path.sep_str ++ "arm" ++ path.sep_str ++ "sincosf.S",901 "math" ++ path.sep_str ++ "arm" ++ path.sep_str ++ "sincosf.S",
906};902};
907903
908const mingwex_arm64_src = [_][]const u8{904const mingw32_arm64_src = [_][]const u8{
909 "math" ++ path.sep_str ++ "arm-common" ++ path.sep_str ++ "ldexpl.c",905 "math" ++ path.sep_str ++ "arm-common" ++ path.sep_str ++ "ldexpl.c",
910 "math" ++ path.sep_str ++ "arm64" ++ path.sep_str ++ "_chgsignl.S",906 "math" ++ path.sep_str ++ "arm64" ++ path.sep_str ++ "_chgsignl.S",
911 "math" ++ path.sep_str ++ "arm64" ++ path.sep_str ++ "rint.c",907 "math" ++ path.sep_str ++ "arm64" ++ path.sep_str ++ "rint.c",
test/standalone.zig+4
...@@ -195,6 +195,10 @@ pub const build_cases = [_]BuildCase{...@@ -195,6 +195,10 @@ pub const build_cases = [_]BuildCase{
195 .build_root = "test/standalone/windows_resources",195 .build_root = "test/standalone/windows_resources",
196 .import = @import("standalone/windows_resources/build.zig"),196 .import = @import("standalone/windows_resources/build.zig"),
197 },197 },
198 .{
199 .build_root = "test/standalone/windows_entry_points",
200 .import = @import("standalone/windows_entry_points/build.zig"),
201 },
198 .{202 .{
199 .build_root = "test/standalone/windows_spawn",203 .build_root = "test/standalone/windows_spawn",
200 .import = @import("standalone/windows_spawn/build.zig"),204 .import = @import("standalone/windows_spawn/build.zig"),
test/standalone/windows_entry_points/build.zig created+68
...@@ -0,0 +1,68 @@
1const std = @import("std");
2
3pub fn build(b: *std.Build) void {
4 const test_step = b.step("test", "Test it");
5 b.default_step = test_step;
6
7 const target = b.resolveTargetQuery(.{
8 .cpu_arch = .x86_64,
9 .os_tag = .windows,
10 .abi = .gnu,
11 });
12
13 {
14 const exe = b.addExecutable(.{
15 .name = "main",
16 .target = target,
17 .optimize = .Debug,
18 .link_libc = true,
19 });
20 exe.addCSourceFile(.{ .file = .{ .path = "main.c" } });
21
22 _ = exe.getEmittedBin();
23 test_step.dependOn(&exe.step);
24 }
25
26 {
27 const exe = b.addExecutable(.{
28 .name = "wmain",
29 .target = target,
30 .optimize = .Debug,
31 .link_libc = true,
32 });
33 exe.mingw_unicode_entry_point = true;
34 exe.addCSourceFile(.{ .file = .{ .path = "wmain.c" } });
35
36 _ = exe.getEmittedBin();
37 test_step.dependOn(&exe.step);
38 }
39
40 {
41 const exe = b.addExecutable(.{
42 .name = "winmain",
43 .target = target,
44 .optimize = .Debug,
45 .link_libc = true,
46 });
47 // Note: `exe.subsystem = .Windows;` is not necessary
48 exe.addCSourceFile(.{ .file = .{ .path = "winmain.c" } });
49
50 _ = exe.getEmittedBin();
51 test_step.dependOn(&exe.step);
52 }
53
54 {
55 const exe = b.addExecutable(.{
56 .name = "wwinmain",
57 .target = target,
58 .optimize = .Debug,
59 .link_libc = true,
60 });
61 exe.mingw_unicode_entry_point = true;
62 // Note: `exe.subsystem = .Windows;` is not necessary
63 exe.addCSourceFile(.{ .file = .{ .path = "wwinmain.c" } });
64
65 _ = exe.getEmittedBin();
66 test_step.dependOn(&exe.step);
67 }
68}
test/standalone/windows_entry_points/main.c created+6
...@@ -0,0 +1,6 @@
1#include <stdio.h>
2
3int main(int argc, char *argv[ ], char *envp[ ]) {
4 printf("hello from main\n");
5 return 0;
6}
\ No newline at end of file
test/standalone/windows_entry_points/winmain.c created+7
...@@ -0,0 +1,7 @@
1#include <windows.h>
2#include <stdio.h>
3
4int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, PSTR cmdline, int cmdshow) {
5 printf("hello from WinMain\n");
6 return 0;
7}
\ No newline at end of file
test/standalone/windows_entry_points/wmain.c created+7
...@@ -0,0 +1,7 @@
1#include <stdio.h>
2#include <windows.h>
3
4int wmain(int argc, wchar_t *argv[ ], wchar_t *envp[ ]) {
5 printf("hello from wmain\n");
6 return 0;
7}
\ No newline at end of file
test/standalone/windows_entry_points/wwinmain.c created+7
...@@ -0,0 +1,7 @@
1#include <windows.h>
2#include <stdio.h>
3
4int APIENTRY wWinMain(HINSTANCE hInst, HINSTANCE hInstPrev, PWSTR cmdline, int cmdshow) {
5 printf("hello from wWinMain\n");
6 return 0;
7}
\ No newline at end of file
tools/update_clang_options.zig+4
...@@ -532,6 +532,10 @@ const known_options = [_]KnownOpt{...@@ -532,6 +532,10 @@ const known_options = [_]KnownOpt{
532 .name = "ObjC",532 .name = "ObjC",
533 .ident = "force_load_objc",533 .ident = "force_load_objc",
534 },534 },
535 .{
536 .name = "municode",
537 .ident = "mingw_unicode_entry_point",
538 },
535};539};
536540
537const blacklisted_options = [_][]const u8{};541const blacklisted_options = [_][]const u8{};