From 2d4d47ed82bbfb560f8a7fe42c7aa043d8ebf90b Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Thu, 23 Apr 2026 00:42:23 +0900 Subject: [PATCH] windows: provide DllMain stub for non-MSVC ABI Part of preparation for upstreaming a Win32 application runtime (see discussion #2563). This is one of three small build-related fixes that unblock the Windows GNU-ABI library build. When targeting Windows with GNU ABI, the existing `DllMain` declaration falls through to `void` (a type), which Zig stdlib's `start.zig` then attempts to call as a function via `root.DllMain(...)` - producing the compile error "type 'type' not a function". Restructure the conditional so that: - non-Windows builds keep `DllMain = void` - Windows + MSVC keeps the existing CRT-init handler (unchanged) - Windows + non-MSVC gets a no-op `BOOL` handler This unblocks `zig build -Dtarget=native-native-gnu -Dapp-runtime=none` on Windows. --- src/main_c.zig | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main_c.zig b/src/main_c.zig index ef8d9ec7e..0ded209f6 100644 --- a/src/main_c.zig +++ b/src/main_c.zig @@ -168,8 +168,7 @@ pub export fn ghostty_string_free(str: String) void { // but not MSVC. No upstream issue tracks this exact gap as of 2026-03-26. // Closest: Codeberg ziglang/zig #30936 (reimplement crt0 code). // Remove this DllMain when Zig handles MSVC DLL CRT init natively. -pub const DllMain = if (builtin.os.tag == .windows and - builtin.abi == .msvc) struct { +pub const DllMain = if (builtin.os.tag != .windows) void else if (builtin.abi == .msvc) struct { const BOOL = std.os.windows.BOOL; const HINSTANCE = std.os.windows.HINSTANCE; const DWORD = std.os.windows.DWORD; @@ -200,7 +199,19 @@ pub const DllMain = if (builtin.os.tag == .windows and else => return TRUE, } } -}.handler else void; +}.handler else struct { + // GNU ABI: provide a no-op DllMain so Zig's start.zig doesn't + // try to call a type instead of a function. + const BOOL = std.os.windows.BOOL; + const HINSTANCE = std.os.windows.HINSTANCE; + const DWORD = std.os.windows.DWORD; + const LPVOID = std.os.windows.LPVOID; + const TRUE = std.os.windows.TRUE; + + pub fn handler(_: HINSTANCE, _: DWORD, _: LPVOID) callconv(.winapi) BOOL { + return TRUE; + } +}.handler; test "ghostty_string_s empty string" { const testing = std.testing;