mirror of
https://github.com/mudler/LocalAI.git
synced 2026-06-27 09:57:14 -04:00
feat(backends): darwin/Metal build for the privacy-filter backend (timeboxed try)
The privacy-filter.cpp engine is already Metal-capable on Apple Silicon: it pulls ggml and never forces GGML_METAL=OFF, and ggml defaults Metal ON on Apple, so a plain Darwin build is Metal-enabled. grpc++/protobuf resolve from Homebrew via find_package(... CONFIG). It just had no darwin build path - the existing package.sh and run.sh are Linux-only and there was no make target / workflow step. Adds the bespoke darwin path, modeled on the ds4 one: - scripts/build/privacy-filter-darwin.sh: native make grpc-server, otool -L dylib bundling, create-oci-image (no Linux package.sh). - Makefile: backends/privacy-filter-darwin target (+ .NOTPARALLEL). - .github/workflows/backend_build_darwin.yml: gated build step for privacy-filter. - scripts/changed-backends.js: inferBackendPathDarwin special-case -> backend/cpp. - .github/backend-matrix.yml: includeDarwin entry (lang go, like ds4/llama-cpp). - backend/index.yaml: metal: capability + metal-privacy-filter(-development) entries. - backend/cpp/privacy-filter/run.sh: DYLD_LIBRARY_PATH branch on Darwin. Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Assisted-by: Claude:opus-4.8 [Claude Code]
This commit is contained in:
58
scripts/build/privacy-filter-darwin.sh
Normal file
58
scripts/build/privacy-filter-darwin.sh
Normal file
@@ -0,0 +1,58 @@
|
||||
#!/bin/bash
|
||||
# Darwin/Metal build for the privacy-filter backend. Mirrors ds4-darwin.sh:
|
||||
# native make of the single grpc-server, otool -L dylib bundling, then assemble
|
||||
# an OCI tar that `local-ai backends install` can consume.
|
||||
#
|
||||
# privacy-filter.cpp pulls ggml, which defaults GGML_METAL=ON on Apple - the
|
||||
# engine's CMake never forces it off, so a plain Darwin build is Metal-enabled.
|
||||
# grpc++/protobuf are resolved from Homebrew via find_package(... CONFIG).
|
||||
set -ex
|
||||
|
||||
IMAGE_NAME="${IMAGE_NAME:-localai/privacy-filter-darwin}"
|
||||
|
||||
pushd backend/cpp/privacy-filter
|
||||
make grpc-server
|
||||
popd
|
||||
|
||||
mkdir -p build/darwin
|
||||
mkdir -p build/darwin/lib
|
||||
mkdir -p backend-images
|
||||
|
||||
cp -rf backend/cpp/privacy-filter/grpc-server build/darwin/
|
||||
cp -rf backend/cpp/privacy-filter/run.sh build/darwin/
|
||||
|
||||
# Apple Silicon: pick up Homebrew-installed protobuf utf8_validity if present
|
||||
# (same as ds4-darwin.sh - it is a transitive dep otool may not surface).
|
||||
if [[ "$(uname -s)" == "Darwin" && "$(uname -m)" == "arm64" ]]; then
|
||||
ADDITIONAL_LIBS=${ADDITIONAL_LIBS:-$(ls /opt/homebrew/Cellar/protobuf/**/lib/libutf8_validity*.dylib 2>/dev/null)}
|
||||
else
|
||||
ADDITIONAL_LIBS=${ADDITIONAL_LIBS:-""}
|
||||
fi
|
||||
for file in $ADDITIONAL_LIBS; do
|
||||
cp -rfv "$file" build/darwin/lib
|
||||
done
|
||||
|
||||
# Walk dylibs via otool -L and bundle anything that isn't a system framework.
|
||||
for file in build/darwin/grpc-server; do
|
||||
LIBS="$(otool -L "$file" | awk 'NR > 1 { system("echo " $1) } ' | xargs echo)"
|
||||
for lib in $LIBS; do
|
||||
if [[ "$lib" == *.dylib ]] && [[ -e "$lib" ]]; then
|
||||
cp -rvf "$lib" build/darwin/lib
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
echo "Bundled libraries:"
|
||||
ls -la build/darwin/lib
|
||||
|
||||
# Build an OCI image tar (with manifest.json) that `local-ai backends install`
|
||||
# can consume - mirrors ds4-darwin.sh.
|
||||
PLATFORMARCH="${PLATFORMARCH:-darwin/arm64}"
|
||||
|
||||
./local-ai util create-oci-image \
|
||||
build/darwin/. \
|
||||
--output ./backend-images/privacy-filter.tar \
|
||||
--image-name "$IMAGE_NAME" \
|
||||
--platform "$PLATFORMARCH"
|
||||
|
||||
rm -rf build/darwin
|
||||
@@ -71,6 +71,11 @@ function inferBackendPathDarwin(item) {
|
||||
if (item.backend === "ds4") {
|
||||
return `backend/cpp/ds4/`;
|
||||
}
|
||||
// privacy-filter is C++ too (built via `make backends/privacy-filter-darwin`);
|
||||
// same lang=go-for-runner convention, source under backend/cpp.
|
||||
if (item.backend === "privacy-filter") {
|
||||
return `backend/cpp/privacy-filter/`;
|
||||
}
|
||||
if (!item.lang) {
|
||||
return `backend/python/${item.backend}/`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user