Add wWinMain and wWinMainCRTStartup to fix #4376

This commit is contained in:
Jared Miller 2020-02-07 16:04:50 -05:00 committed by Andrew Kelley
parent 0e7461d4a3
commit b55bc5eb26
5 changed files with 13 additions and 3 deletions

View File

@ -21,7 +21,7 @@ comptime {
@export(main, .{ .name = "main", .linkage = .Weak });
}
} else if (builtin.os == .windows) {
if (!@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup")) {
if (!@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup") and !@hasDecl(root, "wWinMain") and !@hasDecl(root, "wWinMainCRTStartup")) {
@export(WinMainCRTStartup, .{ .name = "WinMainCRTStartup" });
}
} else if (builtin.os == .uefi) {

View File

@ -2175,7 +2175,9 @@ struct CodeGen {
bool is_big_endian;
bool have_c_main;
bool have_winmain;
bool have_wwinmain;
bool have_winmain_crt_startup;
bool have_wwinmain_crt_startup;
bool have_dllmain_crt_startup;
bool have_err_ret_tracing;
bool link_eh_frame_hdr;

View File

@ -3419,8 +3419,12 @@ void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, G
} else if (cc == CallingConventionStdcall && g->zig_target->os == OsWindows) {
if (strcmp(symbol_name, "WinMain") == 0) {
g->have_winmain = true;
} else if (strcmp(symbol_name, "wWinMain") == 0) {
g->have_wwinmain = true;
} else if (strcmp(symbol_name, "WinMainCRTStartup") == 0) {
g->have_winmain_crt_startup = true;
} else if (strcmp(symbol_name, "wWinMainCRTStartup") == 0) {
g->have_wwinmain_crt_startup = true;
} else if (strcmp(symbol_name, "DllMainCRTStartup") == 0) {
g->have_dllmain_crt_startup = true;
}

View File

@ -8340,9 +8340,9 @@ TargetSubsystem detect_subsystem(CodeGen *g) {
if (g->zig_target->os == OsWindows) {
if (g->have_dllmain_crt_startup || (g->out_type == OutTypeLib && g->is_dynamic))
return TargetSubsystemAuto;
if (g->have_c_main || g->is_test_build || g->have_winmain_crt_startup)
if (g->have_c_main || g->is_test_build || g->have_winmain_crt_startup || g->have_wwinmain_crt_startup)
return TargetSubsystemConsole;
if (g->have_winmain)
if (g->have_winmain || g->have_wwinmain)
return TargetSubsystemWindows;
} else if (g->zig_target->os == OsUefi) {
return TargetSubsystemEfiApplication;

View File

@ -2205,6 +2205,10 @@ static void add_win_link_args(LinkJob *lj, bool is_library, bool *have_windows_d
if (!is_library) {
if (lj->codegen->have_winmain) {
lj->args.append("-ENTRY:WinMain");
} else if (lj->codegen->have_wwinmain) {
lj->args.append("-ENTRY:wWinMain");
} else if (lj->codegen->have_wwinmain_crt_startup) {
lj->args.append("-ENTRY:wWinMainCRTStartup");
} else {
lj->args.append("-ENTRY:WinMainCRTStartup");
}