Skip to content

build: fat static archive and ubsan fix for external linkers#12217

Open
deblasis wants to merge 3 commits intoghostty-org:mainfrom
deblasis:build/libghostty-fat-archive-for-main
Open

build: fat static archive and ubsan fix for external linkers#12217
deblasis wants to merge 3 commits intoghostty-org:mainfrom
deblasis:build/libghostty-fat-archive-for-main

Conversation

@deblasis
Copy link
Copy Markdown
Contributor

Summary

Important

Stacked on #12214. Review that first. (i am targeting main so here you will see the full changeset, including 12214

Two changes that make the static libghostty archive consumable by external linkers (MSVC link.exe, .NET NativeAOT, Rust, Go, etc.):

Fat static archive on all platforms

The static archive previously only bundled vendored deps on macOS (via libtool). On Windows and Linux the archive contained only the Zig-compiled code, requiring consumers to find and link freetype, harfbuzz, glslang, spirv-cross, simdutf, oniguruma, etc. separately.

Now all platforms produce a single fat archive:

  • macOS: libtool (unchanged)
  • Windows: zig ar qcL --format=coff (MSVC's lib.exe can't read Zig-produced GNU-format archives, so we use the bundled LLVM archiver)
  • Linux: ar -M with MRI scripts (same approach as libghostty-vt)

MSVC ubsan suppression for C deps

Zig's ubsan runtime can't be bundled on Windows (LNK4229), leaving _ubsan_handle* symbols unresolved. freetype, glslang, spirv-cross, and highway already suppress ubsan. This adds MSVC-conditional suppression to seven more: harfbuzz, libpng, dcimgui, wuffs, oniguruma, zlib, and stb.

Gated on abi == .msvc so ubsan coverage is preserved on Linux/macOS.

Test plan

  • zig build produces a fat ghostty-static.lib (~230MB) with ~200 object files
  • MSVC's lib /LIST can read the archive
  • .NET NativeAOT consumer resolves all symbols (0 unresolved)
  • Linux/macOS builds unaffected (ubsan remains enabled)

@deblasis deblasis requested review from a team as code owners April 10, 2026 07:43
@deblasis deblasis changed the title windows: fat static archive and ubsan fix for external linkers build: fat static archive and ubsan fix for external linkers Apr 10, 2026
@deblasis deblasis force-pushed the build/libghostty-fat-archive-for-main branch 3 times, most recently from 67f75cd to 999d7b8 Compare April 11, 2026 02:17
@mitchellh
Copy link
Copy Markdown
Contributor

Rebase this please

The static libghostty archive previously only bundled vendored
dependencies on macOS (via libtool). On Windows and Linux the
archive contained only the Zig-compiled code, leaving consumers
to discover and link freetype, harfbuzz, glslang, spirv-cross,
simdutf, oniguruma, and other vendored deps separately.

Now all platforms produce a single fat archive:
- macOS: libtool (unchanged)
- Windows: zig ar qcL --format=coff (LLVM archiver with the L
  flag to flatten nested archives; MSVC's lib.exe cannot read
  Zig-produced GNU-format archives)
- Linux: ar -M with MRI scripts (same as libghostty-vt)

This makes the static library self-contained for consumers like
.NET NativeAOT that link via the platform linker (MSVC link.exe)
and need all symbols resolved from a single archive.
Zig's ubsan runtime cannot be bundled on Windows (LNK4229),
leaving __ubsan_handle_* symbols unresolved when the static
archive is consumed by an external linker like MSVC link.exe.

freetype, glslang, spirv-cross, and highway already suppress
ubsan unconditionally. Add MSVC-conditional suppression to the
seven C dependencies that were missing it: harfbuzz, libpng,
dcimgui, wuffs, oniguruma, zlib, and stb.

The fix is gated on abi == .msvc so ubsan coverage is preserved
on Linux and macOS where bundle_ubsan_rt works.
@deblasis deblasis force-pushed the build/libghostty-fat-archive-for-main branch from 999d7b8 to 2020905 Compare April 12, 2026 23:00
@deblasis
Copy link
Copy Markdown
Contributor Author

done

Comment thread src/build/GhosttyLib.zig Outdated
/// Combine multiple static archives into a single fat archive.
/// Uses libtool on Darwin, lib.exe on Windows, and ar MRI scripts
/// on other platforms.
fn combineArchives(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would be nice to combine this with ghosttylibvt combineArchives and also fix the names to the new internal name here.

Extract CombineArchivesStep.zig so both GhosttyLib and GhosttyLibVt
use the same archive-combining logic. Uses libtool on Darwin and the
cross-platform combine_archives build tool elsewhere.

Renames the internal library's fat archive outputs from ghostty to
ghostty-internal, matching the pkg-config rename from PR 12214.
@deblasis deblasis requested a review from mitchellh April 13, 2026 15:55
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.

2 participants