Skip to content

fix(windows): fix MSVC shared library CRT linking in libghostty-vt - #13151

Open
eunos-1128 wants to merge 7 commits into
ghostty-org:mainfrom
eunos-1128:bugfix/libghostty-vt-msvc-ucrt
Open

eunos-1128 wants to merge 7 commits into
ghostty-org:mainfrom
eunos-1128:bugfix/libghostty-vt-msvc-ucrt

Conversation

@eunos-1128

@eunos-1128 eunos-1128 commented Jul 2, 2026 •

Copy link
Copy Markdown

Problem

Building libghostty-vt as a shared library on Windows with MSVC fails
due to missing CRT libraries. Explicitly linking these libraries also
exposes a duplicate memset symbol between Ghostty's custom implementation
and libvcruntime.

This blocks downstream projects such as herdr.

Changes

  • Explicitly link libvcruntime and libucrt for MSVC shared library builds.
  • Detect the Windows SDK and add its architecture-specific UCRT library path.
  • Disable the custom memset override when targeting MSVC with libc linked
    to avoid the duplicate symbol.

The CRT linking follows the existing approach in GhosttyLib.zig.

Verification

  • Pending Windows/MSVC build verification after the memset fix.

Related

Addresses the Windows/MSVC build issue encountered when packaging herdr
for conda-forge:
conda-forge/staged-recipes#34029

@ghostty-vouch

ghostty-vouch Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

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.

@pluiedev

pluiedev commented Jul 3, 2026

Copy link
Copy Markdown
Member

Vouched manually in #13166

@VectorPeak

This comment has been minimized.

@eunos-1128 eunos-1128 changed the title Fix MSVC shared library CRT linking in libghostty-vt fix(windows): Fix MSVC shared library CRT linking in libghostty-vt Jul 3, 2026
@eunos-1128 eunos-1128 changed the title fix(windows): Fix MSVC shared library CRT linking in libghostty-vt fix(build): Fix MSVC shared library CRT linking in libghostty-vt Jul 3, 2026
@eunos-1128 eunos-1128 changed the title fix(build): Fix MSVC shared library CRT linking in libghostty-vt fix(windows): fix MSVC shared library CRT linking in libghostty-vt Jul 5, 2026
@eunos-1128

Copy link
Copy Markdown
Author

The CI logs have expired and can no longer be viewed. It might fail again, but could you please run the CI once more?

@eunos-1128
eunos-1128 requested a review from mitchellh July 27, 2026 16:35
@eunos-1128
eunos-1128 marked this pull request as draft July 28, 2026 04:22
@eunos-1128
eunos-1128 marked this pull request as ready for review July 28, 2026 04:55
@jcollie

jcollie commented Oct 12, 2026

Copy link
Copy Markdown
Member

Don't mind me, just trying to see if I can trigger a workflow run.

@jcollie jcollie closed this Oct 12, 2026
@jcollie

jcollie commented Oct 12, 2026

Copy link
Copy Markdown
Member

Let's see if workflows will run now.

@jcollie jcollie reopened this Oct 12, 2026
@jcollie

jcollie commented Oct 12, 2026

Copy link
Copy Markdown
Member

If CI is green I'll approve, but I wanted to note a couple of things for a followup:

  1. MSVC isn't tested in CI. Re-enabling it in the build-libghostty-vt should hopefully work for that:

build-libghostty-vt:
strategy:
matrix:
target: [
aarch64-macos,
x86_64-macos,
aarch64-linux,
x86_64-linux,
x86_64-linux-musl,
x86_64-windows-gnu,
# doesn't work yet, we need a way to find msvc libc/c++ headers
# x86_64-windows-msvc
]
runs-on: namespace-profile-ghostty-sm
needs: test
env:
ZIG_LOCAL_CACHE_DIR: /zig/local-cache
ZIG_GLOBAL_CACHE_DIR: /zig/global-cache
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup Cache
uses: namespacelabs/nscloud-cache-action@1124a6f3ce44e5cf84cc22111530961f4d2a15f9 # v1.7.0
with:
path: |
/nix
/zig

  1. A helper that's shared between GhosttyLib.zig and GhosttyLibVt.zig will help prevent drift in the future.
  2. It silently ignores a failure to find the SDK.

@jcollie

jcollie commented Oct 12, 2026

Copy link
Copy Markdown
Member

Oof. Looks like we have some real CI errors.

@eunos-1128

Copy link
Copy Markdown
Author

Oof. Looks like we have some real CI errors.

Would it make sense to disable the custom memset override when targeting MSVC with libc linked?

The Windows CI failures show a duplicate symbol between quirks_memset.zig and libvcruntime.lib.

@jcollie

jcollie commented Oct 12, 2026

Copy link
Copy Markdown
Member

Would it make sense to disable the custom memset override when targeting MSVC with libc linked?

Yes, I think that makes sense.

@eunos-1128

Copy link
Copy Markdown
Author

@jcollie

Ghostty's custom memset override is now disabled when targeting MSVC with libc linked.

@jcollie

jcollie commented Oct 29, 2026

Copy link
Copy Markdown
Member

@eunos-1128 can you rebase and fix the conflicts?

eunos-1128 and others added 5 commits October 30, 2026 17:27
Clarified comments regarding Windows DLL requirements and CRT library linking.
)

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: UENO, M. <eunosium-1128@live.jp>
@eunos-1128
eunos-1128 force-pushed the bugfix/libghostty-vt-msvc-ucrt branch from 9e54e06 to 4733f8d Compare October 30, 2026 17:29
@eunos-1128

Copy link
Copy Markdown
Author

@eunos-1128 can you rebase and fix the conflicts?

@jcollie I did it.

@jcollie jcollie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/build/GhosttyLibVt.zig Outdated
.aarch64 => "arm64",
else => "x64",
};
const ucrt_lib_path = std.fmt.allocPrint(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std.fmt.allocPrint is deprecated in favor of b.allocator.print

Comment thread src/build/GhosttyLibVt.zig Outdated
.x86_64 => "x64",
.x86 => "x86",
.aarch64 => "arm64",
else => "x64",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be an error, or at least have a warning logged. Silently falling back to x64 is wrong.

Comment thread src/build/GhosttyLibVt.zig Outdated
b.allocator,
"{s}\\Lib\\{s}\\ucrt\\{s}",
.{ w10.path, w10.version, arch_str },
) catch null;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silent failure to find the SDK is wrong here.

@jcollie jcollie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more changes needed.

Comment thread src/build/GhosttyLibVt.zig Outdated
const ucrt_lib_path = try b.allocator.print(
"{s}\\Lib\\{s}\\ucrt\\{s}",
.{ w10.path, w10.version, arch_str },
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread .github/workflows/test.yml Outdated

# 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread .github/workflows/test.yml Outdated

- name: Build libghostty-vt (x86_64-windows-msvc)
run: zig build -Demit-lib-vt -Dtarget=x86_64-windows-msvc

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@eunos-1128
eunos-1128 requested a review from jcollie October 31, 2026 07:58

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants