mirror of
https://github.com/mudler/LocalAI.git
synced 2026-07-31 10:28:43 -04:00
refactor(backends): extract shared package-system-libs.sh from package.sh
The arch-detect-and-copy-system-libs block (Darwin rpath / x86_64 / aarch64
loader + libc/libstdc++/libgcc_s/libm/libgomp/libdl/librt/libpthread) was
inlined verbatim in 31 backend package.sh scripts. Extract it into a single
sourced scripts/build/package-system-libs.sh, the CPU-side counterpart to
scripts/build/package-gpu-libs.sh and its sourcing contract.
Consolidating the copies fixes three drift classes that had crept in:
- libgcc_s.so.1 and libstdc++.so.6 were listed twice in 9 backends
(acestep-cpp, crispasr, moss-tts-cpp, omnivoice-cpp, piper,
qwen3-tts-cpp, silero-vad, stablediffusion-ggml, whisper); the shared
script copies each once.
- libgomp.so.1 was omitted from opus. OpenMP consumers dlopen it rather
than link it, so the missing copy only failed at runtime; the shared
script always includes it.
- the Darwin @loader_path/lib rpath was applied only in piper and
silero-vad; both now pass their packaged binary to the shared script,
preserving that behavior. Every other backend passes an empty binary
path so no rpath is added, preserving its current behavior.
Each backend's pre/post packaging steps (binary copy, run.sh, ldd closure
walks, ggml variant bundling, espeak/OpenBLAS extras, the ds4 validate step)
are preserved verbatim; only the inline if/elif/else arch block is replaced
by a single source line.
Signed-off-by: supermario_leo <leo.stack@outlook.com>
Co-authored-by: localai-org-maint-bot <bot-opensource@localaisrl.com>
66 lines
2.1 KiB
Bash
Executable File
66 lines
2.1 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
CURDIR=$(dirname "$(realpath "$0")")
|
|
REPO_ROOT="${CURDIR}/../../.."
|
|
PACKAGE_DIR="$CURDIR/package"
|
|
|
|
rm -rf "$PACKAGE_DIR"
|
|
mkdir -p "$PACKAGE_DIR/lib"
|
|
cp -avf "$CURDIR/grpc-server" "$PACKAGE_DIR/"
|
|
cp -avf "$CURDIR/ds4-worker" "$PACKAGE_DIR/"
|
|
cp -rfv "$CURDIR/run.sh" "$PACKAGE_DIR/"
|
|
|
|
UNAME_S=$(uname -s)
|
|
if [ "$UNAME_S" = "Darwin" ]; then
|
|
# Darwin: bundle dylibs via otool -L (handled by scripts/build/ds4-darwin.sh).
|
|
echo "package.sh: Darwin handled by ds4-darwin.sh"
|
|
exit 0
|
|
fi
|
|
|
|
source "$CURDIR/../../../scripts/build/package-system-libs.sh" "$CURDIR/package/lib" ""
|
|
|
|
# Bundle the complete dependency closure for both executables. In particular,
|
|
# grpc-server links the distro gRPC/protobuf/absl stack; copying only the core
|
|
# C/C++ runtime libraries leaves the scratch image unable to start.
|
|
{
|
|
ldd "$CURDIR/grpc-server"
|
|
ldd "$CURDIR/ds4-worker"
|
|
} | awk '$2 == "=>" && $3 ~ /^\// { print $3 }' | sort -u | \
|
|
while read -r so; do
|
|
cp -arfLv "$so" "$PACKAGE_DIR/lib/"
|
|
done
|
|
|
|
GPU_LIB_SCRIPT="${REPO_ROOT}/scripts/build/package-gpu-libs.sh"
|
|
if [ -f "$GPU_LIB_SCRIPT" ]; then
|
|
# shellcheck source=/dev/null
|
|
source "$GPU_LIB_SCRIPT" "$PACKAGE_DIR/lib"
|
|
package_gpu_libs
|
|
fi
|
|
|
|
# Resolve every dependency through the same loader and library path used by
|
|
# the from-scratch image. The loader can still search host defaults, so reject
|
|
# any absolute dependency path that escapes the package instead of accepting a
|
|
# false-positive validation against a library that scratch will not contain.
|
|
validate_packaged_binary() {
|
|
local binary="$1"
|
|
local resolution
|
|
resolution=$("$PACKAGE_DIR/lib/ld.so" \
|
|
--library-path "$PACKAGE_DIR/lib" \
|
|
--list "$PACKAGE_DIR/$binary")
|
|
|
|
printf '%s\n' "$resolution" | awk -v prefix="$PACKAGE_DIR/lib/" '
|
|
$2 == "=>" && $3 ~ /^\// && index($3, prefix) != 1 {
|
|
print "package.sh: dependency resolved outside package: " $0 > "/dev/stderr"
|
|
invalid = 1
|
|
}
|
|
END { exit invalid }
|
|
'
|
|
}
|
|
|
|
for binary in grpc-server ds4-worker; do
|
|
validate_packaged_binary "$binary"
|
|
done
|
|
|
|
echo "ds4 package contents:"
|
|
ls -lah "$PACKAGE_DIR/" "$PACKAGE_DIR/lib/"
|