Skip to content

fix(backends): make the opus backend build and package on macOS/Darwin#10523

Merged
mudler merged 1 commit into
masterfrom
fix/opus-darwin-build
Jun 26, 2026
Merged

fix(backends): make the opus backend build and package on macOS/Darwin#10523
mudler merged 1 commit into
masterfrom
fix/opus-darwin-build

Conversation

@localai-bot

Copy link
Copy Markdown
Collaborator

What

Fixes the opus Go backend (realtime WebRTC audio codec) build on macOS / Apple Silicon (Metal). Today the published master-metal-darwin-arm64-opus image ships source only — no opus binary and no libopusshim — because every build/packaging step assumed Linux.

Why

backend/go/opus/{Makefile,run.sh,package.sh} hardcode the Linux shim name (libopusshim.so), LD_LIBRARY_PATH, and Linux-only library bundling, so make -C backend/go/opus build fails on Darwin and golang-darwin.sh packages a binary-less tree (cf. the issue #10267 class of "ships sources, no binary"). The matrix entry under includeDarwin: already exists; only the backend's build was broken.

How

  • Makefile — mirror sherpa-onnx: SHIM_EXT=so / dylib on Darwin, build libopusshim.$(SHIM_EXT), and reference the variable in every target + clean. On Darwin the shim is linked with -undefined dynamic_lookup so opus_encoder_ctl resolves from the already globally-loaded libopus (codec.go dlopens libopus RTLD_GLOBAL before the shim) — this avoids baking an absolute Homebrew install-name into the dylib and keeps the packaged shim relocatable.
  • run.sh — add a Darwin branch exporting DYLD_LIBRARY_PATH + OPUS_SHIM_LIBRARY=…/libopusshim.dylib (Linux keeps LD_LIBRARY_PATH + .so), matching sherpa-onnx/run.sh. $CURDIR stays quoted.
  • package.sh — bundle libopusshim.$(SHIM_EXT) and libopus*.dylib (in addition to libopus.so*) into package/lib, and add a Darwin arch branch (system libs are linked dynamically, no ld.so needed). This makes package/. self-contained on a runtime with no Homebrew.
  • backend_build_darwin.ymlbrew install/brew link opus + pkg-config (the Makefile/package.sh call pkg-config opus), and cache opus' Cellar dir.

Verification

  • bash -n clean on run.sh + package.sh.
  • go build ./ and go vet ./ clean in backend/go/opus/ (Go code unchanged).
  • Makefile dry-run confirms: Linux → libopusshim.so (+ pkg-config --libs opus); Darwin → libopusshim.dylib -undefined dynamic_lookup.
  • A full darwin build cannot run on the Linux dev box — validated in CI.

🤖 Generated with Claude Code

The opus Go backend (WebRTC audio codec) never built on macOS, so the
published master-metal-darwin-arm64-opus image shipped source only — no
opus binary and no libopusshim — because every step assumed Linux.

- Makefile: hardcoded libopusshim.so with no OS handling. Mirror
  sherpa-onnx: SHIM_EXT=so / dylib on Darwin and build
  libopusshim.$(SHIM_EXT). On Darwin link the shim with
  -undefined dynamic_lookup so it resolves opus_encoder_ctl from the
  already globally-loaded libopus (codec.go dlopens it RTLD_GLOBAL
  first) instead of baking an absolute Homebrew path into the dylib,
  keeping the packaged shim relocatable.
- run.sh: hardcoded LD_LIBRARY_PATH + libopusshim.so even on macOS. Add
  a Darwin branch exporting DYLD_LIBRARY_PATH and the .dylib shim, like
  sherpa-onnx/run.sh.
- package.sh: bundle libopusshim.$(SHIM_EXT) and libopus*.dylib (not
  just .so) into package/lib so the OCI image (which ships package/.)
  is self-contained on a runtime with no Homebrew; add a Darwin arch
  branch so it doesn't warn/skip.
- backend_build_darwin.yml: install + link opus and pkg-config via brew
  so the Makefile's `pkg-config opus` resolves on the macOS runner, and
  cache opus' Cellar dir.

Go code is unchanged; darwin build is validated in CI.

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
@mudler
mudler merged commit 6afe127 into master Jun 26, 2026
60 checks passed
@mudler
mudler deleted the fix/opus-darwin-build branch June 26, 2026 09:19
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