From 1f6275976b177419eacf8268e8df9f931ef157bd Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Wed, 24 Jun 2026 17:16:39 +0000 Subject: [PATCH] fix(backends): darwin/metal support for supertonic The supertonic Go TTS backend dlopens ONNX Runtime, but its runtime and packaging scripts were Linux-only: run.sh exported LD_LIBRARY_PATH, pointed ONNXRUNTIME_LIB_PATH at libonnxruntime.so, and always tried the ld.so exec path, while package.sh hard-failed on any non-Linux host. On macOS dyld has no ld.so loader, uses DYLD_LIBRARY_PATH, and ONNX Runtime ships as a .dylib. This applies the same purego .dylib/DYLD_LIBRARY_PATH fix that PR #10481 landed for 15 other ONNX/purego backends (sherpa-onnx, silero-vad, etc.) but which omitted supertonic: - run.sh: on darwin export DYLD_LIBRARY_PATH and point ONNXRUNTIME_LIB_PATH at libonnxruntime.dylib; guard the ld.so exec path to Linux only. - package.sh: recognize Darwin instead of erroring out; the bundled .dylib is resolved via DYLD_LIBRARY_PATH, no glibc/ld.so to bundle. - helper.go: platform-native default library extension (dylib on darwin) for the last-resort dlopen fallback. It also wires the darwin CI build and gallery entries, resolving the inconsistency where backend/index.yaml advertised metal for supertonic but no includeDarwin matrix entry built the image: - .github/backend-matrix.yml: add the -metal-darwin-arm64-supertonic Go entry. - backend/index.yaml: declare metal capabilities and add the concrete metal-supertonic / metal-supertonic-development child entries. The Makefile already detects Darwin/osx/arm64 and stages the per-OS ONNX Runtime tarball, mirroring sherpa-onnx, so no Makefile change is required. Signed-off-by: Ettore Di Giacinto Assisted-by: Claude:opus-4.8 [Claude Code] --- .github/backend-matrix.yml | 4 ++++ backend/go/supertonic/helper.go | 9 ++++++++- backend/go/supertonic/package.sh | 4 ++++ backend/go/supertonic/run.sh | 17 ++++++++++++----- backend/index.yaml | 12 ++++++++++++ 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/.github/backend-matrix.yml b/.github/backend-matrix.yml index 593e44cde714..4cfc937acee9 100644 --- a/.github/backend-matrix.yml +++ b/.github/backend-matrix.yml @@ -4990,6 +4990,10 @@ includeDarwin: tag-suffix: "-metal-darwin-arm64-sherpa-onnx" build-type: "metal" lang: "go" + - backend: "supertonic" + tag-suffix: "-metal-darwin-arm64-supertonic" + build-type: "metal" + lang: "go" - backend: "local-store" tag-suffix: "-metal-darwin-arm64-local-store" build-type: "metal" diff --git a/backend/go/supertonic/helper.go b/backend/go/supertonic/helper.go index 9f927d5d3f0d..884077e756c9 100644 --- a/backend/go/supertonic/helper.go +++ b/backend/go/supertonic/helper.go @@ -16,6 +16,7 @@ import ( "os" "path/filepath" "regexp" + "runtime" "strings" "time" "unicode" @@ -943,7 +944,13 @@ func InitializeONNXRuntime() error { } } if libPath == "" { - libPath = "/usr/local/lib/libonnxruntime.so" + // LocalAI: default to the platform-native shared library + // extension when nothing else is found (dyld vs ld.so). + if runtime.GOOS == "darwin" { + libPath = "/usr/local/lib/libonnxruntime.dylib" + } else { + libPath = "/usr/local/lib/libonnxruntime.so" + } } } ort.SetSharedLibraryPath(libPath) diff --git a/backend/go/supertonic/package.sh b/backend/go/supertonic/package.sh index 9e2a016256a9..678ca5eadcb3 100755 --- a/backend/go/supertonic/package.sh +++ b/backend/go/supertonic/package.sh @@ -32,6 +32,10 @@ elif [ -f "/lib/ld-linux-aarch64.so.1" ]; then cp -arfLv /lib/aarch64-linux-gnu/libdl.so.2 $CURDIR/package/lib/libdl.so.2 cp -arfLv /lib/aarch64-linux-gnu/librt.so.1 $CURDIR/package/lib/librt.so.1 cp -arfLv /lib/aarch64-linux-gnu/libpthread.so.0 $CURDIR/package/lib/libpthread.so.0 +elif [ $(uname -s) = "Darwin" ]; then + # macOS: dyld resolves the bundled .dylib via DYLD_LIBRARY_PATH (set in + # run.sh); there is no ld.so loader nor glibc to bundle. + echo "Detected Darwin" else echo "Error: Could not detect architecture" exit 1 diff --git a/backend/go/supertonic/run.sh b/backend/go/supertonic/run.sh index 2dabf7eb3337..683c52ab2745 100755 --- a/backend/go/supertonic/run.sh +++ b/backend/go/supertonic/run.sh @@ -3,12 +3,19 @@ set -ex CURDIR=$(dirname "$(realpath $0)") -export LD_LIBRARY_PATH=$CURDIR/lib:$LD_LIBRARY_PATH -export ONNXRUNTIME_LIB_PATH=$CURDIR/lib/libonnxruntime.so +if [ "$(uname)" = "Darwin" ]; then + # macOS uses dyld: there is no ld.so loader, and the search path env + # var is DYLD_LIBRARY_PATH. ONNX Runtime ships as a .dylib here. + export DYLD_LIBRARY_PATH=$CURDIR/lib:$DYLD_LIBRARY_PATH + export ONNXRUNTIME_LIB_PATH=$CURDIR/lib/libonnxruntime.dylib +else + export LD_LIBRARY_PATH=$CURDIR/lib:$LD_LIBRARY_PATH + export ONNXRUNTIME_LIB_PATH=$CURDIR/lib/libonnxruntime.so -if [ -f $CURDIR/lib/ld.so ]; then - echo "Using lib/ld.so" - exec $CURDIR/lib/ld.so $CURDIR/supertonic "$@" + if [ -f $CURDIR/lib/ld.so ]; then + echo "Using lib/ld.so" + exec $CURDIR/lib/ld.so $CURDIR/supertonic "$@" + fi fi exec $CURDIR/supertonic "$@" diff --git a/backend/index.yaml b/backend/index.yaml index 3f61f7b4ee1b..592c8fd6b2c0 100644 --- a/backend/index.yaml +++ b/backend/index.yaml @@ -1569,6 +1569,7 @@ - TTS capabilities: default: "cpu-supertonic" + metal: "metal-supertonic" - !!merge <<: *neutts name: "neutts-development" capabilities: @@ -5484,6 +5485,7 @@ name: "supertonic-development" capabilities: default: "cpu-supertonic-development" + metal: "metal-supertonic-development" - !!merge <<: *supertonic name: "cpu-supertonic" uri: "quay.io/go-skynet/local-ai-backends:latest-cpu-supertonic" @@ -5494,3 +5496,13 @@ uri: "quay.io/go-skynet/local-ai-backends:master-cpu-supertonic" mirrors: - localai/localai-backends:master-cpu-supertonic +- !!merge <<: *supertonic + name: "metal-supertonic" + uri: "quay.io/go-skynet/local-ai-backends:latest-metal-darwin-arm64-supertonic" + mirrors: + - localai/localai-backends:latest-metal-darwin-arm64-supertonic +- !!merge <<: *supertonic + name: "metal-supertonic-development" + uri: "quay.io/go-skynet/local-ai-backends:master-metal-darwin-arm64-supertonic" + mirrors: + - localai/localai-backends:master-metal-darwin-arm64-supertonic