Skip to content

Conversation

@remorses
Copy link
Contributor

@remorses remorses commented Jan 6, 2026

Adds -fPIC flag for musl targets when building highway and simdutf C++ dependencies, matching the existing freebsd behavior.

What is PIC?

Position Independent Code (PIC) generates machine code using relative addresses instead of absolute ones, allowing the code to be loaded at any memory address. This is required when linking static libraries into shared libraries (.so files).

Why both freebsd and musl need it

Both freebsd and musl use strict relocation policies that reject non-PIC code in shared libraries. Without -fPIC, linking fails with errors like:

relocation R_X86_64_PC32 cannot be used against symbol '__cxa_begin_catch'

glibc is more permissive and handles these relocations at runtime, which is why linux-gnu targets work without this flag.

Context

This enables cross-compiling ghostty-vt to musl/Alpine Linux targets. Discovered while integrating ghostty-vt into opentui: anomalyco/opentui#440


This PR was created with help from Claude Opus 4.5.

Copilot AI review requested due to automatic review settings January 6, 2026 23:59
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds the -fPIC compiler flag for musl ABI targets when building the highway and simdutf C++ dependencies, addressing linking issues when building static libraries for musl/Alpine Linux. This matches the existing behavior for FreeBSD targets, both of which enforce strict relocation policies.

Key Changes:

  • Extended the FreeBSD-specific -fPIC condition to also include musl targets in both highway and simdutf build configurations

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pkg/simdutf/build.zig Updated conditional to add -fPIC flag for both FreeBSD and musl ABI targets
pkg/highway/build.zig Updated conditional to add -fPIC flag for both FreeBSD and musl ABI targets

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@remorses remorses requested review from a team as code owners January 7, 2026 00:01
@remorses remorses changed the title build: add -fPIC for musl targets in highway and simdutf build: add -fPIC for musl targets Jan 7, 2026
@mitchellh
Copy link
Contributor

Thanks! Ghostty (the GUI) in history has never worked with musl, but libghostty-vt has a good chance. I think we should add musl build targets to the CI for libghostty because this is a good thing to ensure...

@mitchellh
Copy link
Contributor

I'll take over. Thanks!

Copy link
Contributor

@mitchellh mitchellh left a comment

Choose a reason for hiding this comment

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

Approved pending CI. I added a CI test case for musl and libghostty-vt.

@mitchellh mitchellh added this to the 1.3.0 milestone Jan 7, 2026
@mitchellh mitchellh merged commit ba1952c into ghostty-org:main Jan 7, 2026
53 checks passed
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