aboutsummaryrefslogtreecommitdiff
path: root/lib/std/start.zig
diff options
context:
space:
mode:
authorRyan Liptak <squeek502@hotmail.com>2025-11-08 01:39:15 -0800
committerRyan Liptak <squeek502@hotmail.com>2025-11-08 17:11:12 -0800
commitb31a03f134792b8fae20a625f68499c6548f8443 (patch)
treead42b9f6811ab64efc449cb2fdcdb05868e3128b /lib/std/start.zig
parentbe4eaed7c41fb194014d862648ff586797e39e84 (diff)
downloadzig-b31a03f134792b8fae20a625f68499c6548f8443.tar.gz
zig-b31a03f134792b8fae20a625f68499c6548f8443.zip
Let CRT take care of the entry point for wWinMain if libc is linked
Fixes #7852 Before, the modified test would fail with: ``` error: lld-link: undefined symbol: wWinMain note: referenced by C:\Users\Ryan\Programming\Zig\zig-x86_64-windows-0.15.1\lib\libc\mingw\crt\crtexewin.c:66 note: libmingw32.lib(ucrtexewin.obj):(wmain) ```
Diffstat (limited to 'lib/std/start.zig')
-rw-r--r--lib/std/start.zig8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/std/start.zig b/lib/std/start.zig
index c22a36f24f..98f8e43b8a 100644
--- a/lib/std/start.zig
+++ b/lib/std/start.zig
@@ -61,6 +61,10 @@ comptime {
} else if (!@typeInfo(@TypeOf(root.main)).@"fn".calling_convention.eql(.c)) {
@export(&main, .{ .name = "main" });
}
+ } else if (native_os == .windows and builtin.link_libc and @hasDecl(root, "wWinMain")) {
+ if (!@typeInfo(@TypeOf(root.wWinMain)).@"fn".calling_convention.eql(.c)) {
+ @export(&wWinMain, .{ .name = "wWinMain" });
+ }
} else if (native_os == .windows) {
if (!@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup") and
!@hasDecl(root, "wWinMain") and !@hasDecl(root, "wWinMainCRTStartup"))
@@ -527,6 +531,10 @@ fn wWinMainCRTStartup() callconv(.withStackAlign(.c, 1)) noreturn {
std.os.windows.ntdll.RtlExitUserProcess(@as(std.os.windows.UINT, @bitCast(result)));
}
+fn wWinMain(hInstance: *anyopaque, hPrevInstance: ?*anyopaque, pCmdLine: [*:0]u16, nCmdShow: c_int) callconv(.c) c_int {
+ return root.wWinMain(@ptrCast(hInstance), @ptrCast(hPrevInstance), pCmdLine, @intCast(nCmdShow));
+}
+
fn posixCallMainAndExit(argc_argv_ptr: [*]usize) callconv(.c) noreturn {
// We're not ready to panic until thread local storage is initialized.
@setRuntimeSafety(false);