CodexBar icon indicating copy to clipboard operation
CodexBar copied to clipboard

Linux CLI: ship fully-static (musl) builds so it runs on older glibc (Ubuntu 20.04 / Jetson) and NixOS

Open guhyun9454 opened this issue 5 months ago • 2 comments

Follow-up to #1039 (Ubuntu 20.04) and #198 (musl / NixOS). I dug into this and have a working fully-static aarch64 build, so opening this to confirm direction before sending a PR.

Problem

The Linux CLI release artifacts fail on any distro whose glibc is older than the CI builder's:

codexbar: /lib/aarch64-linux-gnu/libc.so.6: version `GLIBC_2.38' not found
codexbar: /lib/aarch64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.30' not found

Repro: NVIDIA Jetson AGX (L4T R35.6.4 = Ubuntu 20.04, glibc 2.31, aarch64). Same class as #1039 on x86_64. Even the oldest published tarball (v0.15.0) requires GLIBC_2.38 + GLIBCXX_3.4.30.

Root cause (build environment, not code)

release-cli.yml / ci.yml build on ubuntu-24.04 / ubuntu-24.04-arm with only --static-swift-stdlib. That statically links the Swift runtime, but libc / libstdc++ / libcurl / libsqlite3 stay dynamically linked against the 24.04 host, so the binary inherits a glibc 2.38 / GLIBCXX 3.4.30 floor.

What works: fully-static musl build

Building CodexBarCLI with the Swift Static Linux SDK (musl) produces a fully static binary with zero dynamic dependencies, which runs unmodified on glibc 2.31:

swift sdk install <swift-6.2.1 static-linux SDK>
swift build -c release --product CodexBarCLI --swift-sdk aarch64-swift-linux-musl

Verified on the Jetson (glibc 2.31): --version, config providers, and a live usage --provider codex --source oauth --json (real OAuth refresh over TLS, returned usage windows) all work. readelf -d shows no NEEDED entries. This also solves NixOS (#198) and is immune to future SONAME bumps like the libxml2.so.2 → .so.16 break in #1046.

What it took (PR surface)

  1. import Glibc → add a Musl branch. 12 files use #if canImport(Darwin) … #else import Glibc #endif; musl exposes the C library as the Musl module, so they need a 3-way #elseif canImport(Glibc) … #elseif canImport(Musl). Plus 4 small spots: qualified Glibc.exit/signal/close and SOCK_STREAM.rawValue (an enum on Glibc, a plain Int32 on musl). All trivial and Darwin/glibc behavior is unchanged.
  2. One cross-repo blocker — SweetCookieKit's .linkedLibrary("sqlite3"). The static musl sysroot has no system libsqlite3, so linking fails with unable to find library -lsqlite3. I worked around it by compiling the SQLite amalgamation into a static libsqlite3.a and passing -Xlinker -L…. A clean fix likely belongs in SweetCookieKit (vendor the SQLite amalgamation as a C target) or as a CI step that provides a static libsqlite3.

Questions before I PR

  • Are you open to a PR adding the Musl import shims here + a musl-static entry in the release matrix?
  • Preference for the artifacts: replace the current glibc-linked Linux tarballs with musl-static, or add musl-static alongside?
  • For the SQLite dependency, do you prefer vendoring the amalgamation in SweetCookieKit, or a CI-provided static lib?

Happy to send the PR (source shim + CI matrix + docs) once the direction is settled. Have the aarch64 build and diffs ready.

guhyun9454 avatar Jun 14 '26 14:06 guhyun9454

Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 14, 2026, 10:36 AM ET / 14:36 UTC.

Summary Keep open: current main and the latest release still ship dynamically linked Linux CLI artifacts, and the musl/static path needs maintainer direction because it changes release, toolchain, and dependency behavior.

Reproducibility: yes. source and release-artifact inspection give a high-confidence reproduction path: the latest Linux tarball is dynamically linked and advertises GLIBC_2.38/GLIBCXX_3.4.30 symbols. I did not run it on the reporter's Jetson, so this is source-reproducible rather than live-reproduced here.

Next step Maintainers need to choose the artifact strategy and static SQLite/SweetCookieKit approach before a repair PR should be queued.

Review details

Best possible solution:

Pick the release artifact strategy first, then land a focused build-system/source-shim change with static SQLite handling and proof for x86_64 and aarch64 musl artifacts.

Do we have a high-confidence way to reproduce the issue?

Yes, source and release-artifact inspection give a high-confidence reproduction path: the latest Linux tarball is dynamically linked and advertises GLIBC_2.38/GLIBCXX_3.4.30 symbols. I did not run it on the reporter's Jetson, so this is source-reproducible rather than live-reproduced here.

Is this the best way to solve the issue?

Unclear until maintainers choose the release policy. The musl static SDK path looks plausible and evidence-backed, but replacing versus adding artifacts and resolving static SQLite are product/toolchain decisions rather than a narrow automatic bug fix.

AGENTS.md: found and applied where relevant.

Remaining risk / open question:

  • Replacing the existing Linux tarballs versus adding musl-static variants affects Homebrew tap target aliases and existing Linux users' upgrade path.
  • The static SQLite solution may require a SweetCookieKit change or a CI-provided static library, so the import-shim work alone is not enough to land safely.

Codex review notes: model internal, reasoning high; reviewed against 2e4b3556802d.

Label changes

Label changes:

  • add P2: This is a concrete Linux distribution/runtime compatibility problem with a bounded but release-sensitive implementation path.
  • add impact:crash-loop: Affected Linux users get a loader failure before CodexBarCLI can start, which is a process availability issue.
  • add issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.
  • add clawsweeper:source-repro: Current issue advisory state selects this label.
  • add clawsweeper:no-new-fix-pr: Current issue advisory state selects this label.
  • add clawsweeper:fix-shape-clear: Current issue advisory state selects this label.
  • add clawsweeper:needs-maintainer-review: Current issue advisory state selects this label.
  • add clawsweeper:needs-product-decision: Current issue advisory state selects this label.

Label justifications:

  • P2: This is a concrete Linux distribution/runtime compatibility problem with a bounded but release-sensitive implementation path.
  • impact:crash-loop: Affected Linux users get a loader failure before CodexBarCLI can start, which is a process availability issue.
Evidence reviewed

Acceptance criteria:

  • After direction, inspect Linux artifacts with file/readelf/strings to confirm no dynamic NEEDED entries and no glibc/libstdc++ symbol floor.
  • Run Linux Swift tests and CLI smoke checks for the chosen build path; avoid live provider probes unless explicitly requested.
  • Validate both x86_64 and aarch64 release artifacts and the Homebrew tap target mapping before release.

What I checked:

  • Repository policy read: AGENTS.md was read in full; its release/testing guidance and no-live-provider-probe caution were applied to keep this review source/release-artifact based. (AGENTS.md:1, 2e4b3556802d)
  • Current release workflow still builds glibc-hosted Linux artifacts: The release matrix uses ubuntu-24.04/ubuntu-24.04-arm for Linux and only adds --static-swift-stdlib, with the current Linux artifact names remaining linux-x86_64 and linux-aarch64. (.github/workflows/release-cli.yml:22, 2e4b3556802d)
  • CI still validates the same dynamic Linux build shape: The Linux CI job runs on ubuntu-24.04 and ubuntu-24.04-arm and builds CodexBarCLI with --static-swift-stdlib rather than a Swift static Linux SDK. (.github/workflows/ci.yml:54, 2e4b3556802d)
  • No musl build support is present on current main: Searching Sources, workflows, package files, docs, and README found no canImport(Musl), import Musl, --swift-sdk, static-linux, or musl references. (2e4b3556802d)
  • Latest release artifact confirms the reported glibc floor: The v0.35.0 linux-x86_64 tarball is dynamically linked, has NEEDED entries for libc/libstdc++/libsqlite3/libcurl, and contains GLIBC_2.38 plus GLIBCXX_3.4.30 symbols. (9d3c354df9ba)
  • Static SQLite dependency is a real cross-package blocker: CodexBar depends on SweetCookieKit, and SweetCookieKit 0.4.1 declares linkerSettings .linkedLibrary("sqlite3"), matching the issue's stated musl static-link blocker. (Package.swift:45, 2e4b3556802d)

Likely related people:

  • steipete: GitHub commit history shows repeated recent changes to the CLI release workflow, CI workflow, and Package.swift dependency area that would be central to a musl artifact decision. (role: recent release and packaging contributor; confidence: high; commits: 7e97d2b27ce5, e3b80b111234, 23d5c4f042d0; files: .github/workflows/release-cli.yml, .github/workflows/ci.yml, Package.swift)
  • jskoiz: Authored the merged release-cli hardening work that changed the same workflow and artifact-publishing path involved in Linux CLI release packaging. (role: recent release workflow contributor; confidence: medium; commits: a56340cee86e, 45e2ad1dd5b1, d15a0ca3fb52; files: .github/workflows/release-cli.yml)
  • oorestisime: Merged Linux CLI compatibility work in https://github.com/steipete/CodexBar/pull/204, whose body explicitly evaluated musl static builds and removed a libxml2 runtime dependency instead. (role: prior Linux CLI compatibility contributor; confidence: medium; commits: 571cfc74d454, d230630a6d95; files: Sources/CodexBarCore/Providers/JetBrains/JetBrainsStatusProbe.swift, Sources/CodexBarCLI/CLIIO.swift, TestsLinux/JetBrainsParserLinuxTests.swift)
  • guhyun9454: Provided the current Jetson/Ubuntu 20.04 reproduction, described a working fully static aarch64 musl build, and can likely validate the target platform after maintainers choose the artifact direction. (role: reporter with prototype and target hardware proof; confidence: medium)
How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

clawsweeper[bot] avatar Jun 14 '26 14:06 clawsweeper[bot]

Implemented on main via #1609 and #1610.

  • #1609 added the musl compatibility path and opt-in static SQLite linkage.
  • #1610 switched the Linux release matrix to fully static musl artifacts for x86_64 and arm64 while preserving the existing artifact names.
  • CI and the six-target release workflow passed. The resulting Linux artifacts had no dynamic NEEDED entries and ran --version / config providers successfully in x86_64 and arm64 crabbox environments.

Landed as 016f3b9e and ae08d86d. The static artifacts will become available with the next release; this does not claim that the current published release has them yet.

Thanks for the detailed Jetson reproduction and working musl direction.

steipete avatar Jun 18 '26 17:06 steipete