diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8e82a2853..bc0de2691 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -742,6 +742,10 @@ jobs: - name: Build libghostty-vt run: zig build -Demit-lib-vt + - name: Test static linking + working-directory: example/c-vt-static + run: zig build + build-libghostty-windows-gnu: runs-on: namespace-profile-ghostty-windows timeout-minutes: 45 diff --git a/example/c-vt-static/build.zig b/example/c-vt-static/build.zig index 0e53d69c5..23f6f9d0f 100644 --- a/example/c-vt-static/build.zig +++ b/example/c-vt-static/build.zig @@ -14,6 +14,7 @@ pub fn build(b: *std.Build) void { .root = b.path("src"), .files = &.{"main.c"}, }); + exe_mod.addCMacro("GHOSTTY_STATIC", ""); // You'll want to use a lazy dependency here so that ghostty is only // downloaded if you actually need it. diff --git a/src/build/GhosttyLibVt.zig b/src/build/GhosttyLibVt.zig index b3b89a88e..389be4ef5 100644 --- a/src/build/GhosttyLibVt.zig +++ b/src/build/GhosttyLibVt.zig @@ -247,6 +247,14 @@ fn initLib( // Zig's ubsan emits /exclude-symbols linker directives that // are incompatible with the MSVC linker (LNK4229). lib.bundle_ubsan_rt = false; + + if (kind == .static) { + // compiler_rt expects ntdll to provide _fltused when libc is + // linked, and the Zig standard library uses other NT and kernel32 + // symbols. + lib.root_module.linkSystemLibrary("ntdll", .{}); + lib.root_module.linkSystemLibrary("kernel32", .{}); + } } if (lib.rootModuleTarget().abi.isAndroid()) {