Skip to content

Bug(linux): add musl native targets#1114

Open
riggy2013 wants to merge 2 commits into
anomalyco:mainfrom
riggy2013:feat/musl-linux-targets
Open

Bug(linux): add musl native targets#1114
riggy2013 wants to merge 2 commits into
anomalyco:mainfrom
riggy2013:feat/musl-linux-targets

Conversation

@riggy2013
Copy link
Copy Markdown

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)

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.
Comment thread packages/core/src/zig.ts
}
return await import(`@opentui/core-${process.platform}-${process.arch}`)
}
const nativePackage = await resolveNativePackage()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Author

@riggy2013 riggy2013 May 28, 2026

Choose a reason for hiding this comment

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

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
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