Bug(linux): add musl native targets#1114
Open
riggy2013 wants to merge 2 commits into
Open
Conversation
Added x86_64-linux-musl and aarch64-linux-musl to SUPPORTED_TARGETS in build.zig. Updated zig.ts to try musl native package first on Linux, falling back to glibc. Added musl optionalDependencies to core package.json. Updated build.ts variants with musl ABI support. Fixes futex deadlock on musl-based systems (e.g. CentOS 7.9) caused by glibc pthread_mutex_t ABI mismatch in the native addon.
kommander
reviewed
May 27, 2026
| } | ||
| return await import(`@opentui/core-${process.platform}-${process.arch}`) | ||
| } | ||
| const nativePackage = await resolveNativePackage() |
Collaborator
There was a problem hiding this comment.
Did you build the opencode standalone executable with a version of this? Afaik this cannot be statically analyzed by the bundler and thus the native lib is not bundled in the standalone executable so won't be available when distributed.
Author
There was a problem hiding this comment.
Yes, I have built the opencode musl with a patched opentui .so lib and it can work on centos 7.9 w/o issue.
I am new to this project but an opencode user. If you feel more tests needed, please tell me, or help to do the test. Basically opentui need a musl lib now.
# Conflicts: # packages/core/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On musl-based Linux systems (Alpine, CentOS 7.9 with musl LD_LIBRARY_PATH), opentui v0.2.9+ stalls at startup with no output. strace reveals a futex deadlock:
futex(..., FUTEX_WAIT, ... <unfinished ...>
This issue impacts opencode after 1.14.49 which integrates opentui 0.2.9.
Root Cause
The native .so is compiled against glibc (x86_64-linux-gnu.2.17) and links libpthread. When dlopen loads this .so on a musl system, musl resolves pthread_* symbols from its own libc — but glibc and musl use different pthread_mutex_t internal layouts (size, alignment, field offsets). The Zig std.Thread.Mutex struct embedded in the audio Engine struct is laid out for glibc's pthread_mutex_t, causing futex operations to target the wrong memory address → deadlock.
This was introduced in v0.2.9 when Native audio (#1035) added the miniaudio C library + Zig audio wrapper which links libpthread.
Fix
build.zig — Add musl compilation targets:
x86_64-linux-musl, aarch64-linux-musl
zig.ts — ABI-aware native package resolution: on Linux, try @opentui/core-linux-{arch}-musl first, fall back to glibc if unavailable.
package.json — Add musl optionalDependencies for npm publication.
build.ts — Extend build variants with abi field for musl package creation.
Testing
Zig 0.15.2 cross-compiled from macOS → x86_64-linux-musl and aarch64-linux-musl
Verified .so loads successfully on CentOS 7.9 (kernel 3.10.x) with musl libc
Testing performed with opencode TUI at full load (all layers initialized)