Repository navigation
fix(windows): fix MSVC shared library CRT linking in libghostty-vt - #13151
eunos-1128 wants to merge 7 commits into
Conversation
|
Hi @eunos-1128, thanks for your interest in contributing! This project requires that pull request authors are vouched, and you are not in the list of vouched users. This PR will be closed automatically. See https://github.com/ghostty-org/ghostty/blob/main/CONTRIBUTING.md for more details. |
|
Vouched manually in #13166 |
This comment has been minimized.
This comment has been minimized.
|
The CI logs have expired and can no longer be viewed. It might fail again, but could you please run the CI once more? |
|
Don't mind me, just trying to see if I can trigger a workflow run. |
|
Let's see if workflows will run now. |
|
If CI is green I'll approve, but I wanted to note a couple of things for a followup:
ghostty/.github/workflows/test.yml Lines 608 to 635 in 1e9e14a
|
|
Oof. Looks like we have some real CI errors. |
Would it make sense to disable the custom The Windows CI failures show a duplicate symbol between |
Yes, I think that makes sense. |
|
Ghostty's custom memset override is now disabled when targeting MSVC with libc linked. |
|
@eunos-1128 can you rebase and fix the conflicts? |
Clarified comments regarding Windows DLL requirements and CRT library linking.
9e54e06 to
4733f8d
Compare
@jcollie I did it. |
jcollie
left a comment
There was a problem hiding this comment.
When compiling with -Dsimd=false you can still get duplicate symbols.
Re-enable x86_64-windows-msvc in the CI matrix so that this doesn't bitrot.
| .aarch64 => "arm64", | ||
| else => "x64", | ||
| }; | ||
| const ucrt_lib_path = std.fmt.allocPrint( |
There was a problem hiding this comment.
std.fmt.allocPrint is deprecated in favor of b.allocator.print
| .x86_64 => "x64", | ||
| .x86 => "x86", | ||
| .aarch64 => "arm64", | ||
| else => "x64", |
There was a problem hiding this comment.
This should be an error, or at least have a warning logged. Silently falling back to x64 is wrong.
| b.allocator, | ||
| "{s}\\Lib\\{s}\\ucrt\\{s}", | ||
| .{ w10.path, w10.version, arch_str }, | ||
| ) catch null; |
There was a problem hiding this comment.
Silent failure to find the SDK is wrong here.
| const ucrt_lib_path = try b.allocator.print( | ||
| "{s}\\Lib\\{s}\\ucrt\\{s}", | ||
| .{ w10.path, w10.version, arch_str }, | ||
| ); |
There was a problem hiding this comment.
The code in GhosttyLib.zig that handles MSVC builds has the same problems, but isn't getting updated. We need a shared helper function so that this all gets handled in one place.
|
|
||
| # Duplicate symbols (e.g. memset) can show up without SIMD. | ||
| - name: Build libghostty-vt (x86_64-windows-msvc, no SIMD) | ||
| run: zig build -Demit-lib-vt -Dtarget=x86_64-windows-msvc -Dsimd=false |
There was a problem hiding this comment.
This will only detect the duplicate symbols, it's not fixed. Either only link the CRT when libc is linked, or stop making the memset condition depend on link_libc.
|
|
||
| - name: Build libghostty-vt (x86_64-windows-msvc) | ||
| run: zig build -Demit-lib-vt -Dtarget=x86_64-windows-msvc | ||
|
|
There was a problem hiding this comment.
We should be running zig build test-lib-vt -Dtarget=x86_64-windows-msvc so that loading the DLL is actually tested.
The MSVC CRT linking logic (libvcruntime, the Windows SDK ucrt library path, and libucrt) was duplicated in GhosttyLibVt.zig and GhosttyLib.zig, and the two copies had drifted: libghostty silently ignored a missing SDK and fell back to x64 for unknown architectures, while libghostty-vt reported errors. Move the logic into a shared WindowsCrt.link helper that both call. The memset override was skipped for MSVC only when libc was linked, so builds without libc (e.g. -Dsimd=false) could still produce a duplicate memset symbol against libvcruntime. Skip the override for all MSVC targets instead of depending on link_libc. CI now runs test-lib-vt for x86_64-windows-msvc so that the DLL is actually loaded rather than only built, which replaces the separate build steps, including the no-SIMD one.
Problem
Building
libghostty-vtas a shared library on Windows with MSVC failsdue to missing CRT libraries. Explicitly linking these libraries also
exposes a duplicate
memsetsymbol between Ghostty's custom implementationand
libvcruntime.This blocks downstream projects such as
herdr.Changes
libvcruntimeandlibucrtfor MSVC shared library builds.memsetoverride when targeting MSVC with libc linkedto avoid the duplicate symbol.
The CRT linking follows the existing approach in
GhosttyLib.zig.Verification
memsetfix.Related
Addresses the Windows/MSVC build issue encountered when packaging
herdrfor conda-forge:
conda-forge/staged-recipes#34029