voice-dictation/scripts/build_whisper_runtime.sh

33 lines
1.4 KiB
Bash
Executable file

#!/usr/bin/env bash
# Standalone runtime from pinned upstream source; no system installation.
set -euo pipefail
WHISPER_COMMIT="306c88f4d1286aec1bf96e544632897886af5501" # v1.9.2
RUNTIME_ROOT="${1:-/tmp/voice-whisper-runtime}"
CMAKE_BIN="${CMAKE_BIN:-cmake}"
if [[ ! -d "${RUNTIME_ROOT}/.git" ]]; then
git clone --depth 1 --branch v1.9.2 https://github.com/ggml-org/whisper.cpp.git "${RUNTIME_ROOT}"
fi
ACTUAL_COMMIT="$(git -C "${RUNTIME_ROOT}" rev-parse HEAD)"
if [[ "${ACTUAL_COMMIT}" != "${WHISPER_COMMIT}" ]]; then
echo "Runtime source does not match pinned upstream commit" >&2
exit 1
fi
if [[ -n "$(git -C "${RUNTIME_ROOT}" status --porcelain --untracked-files=no)" ]]; then
echo "Runtime source has tracked modifications" >&2
exit 1
fi
"${CMAKE_BIN}" -S "${RUNTIME_ROOT}" -B "${RUNTIME_ROOT}/build" \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DGGML_BACKEND_DL=OFF \
-DGGML_NATIVE=OFF \
-DGGML_METAL_EMBED_LIBRARY=ON \
-DGGML_BLAS=OFF \
-DWHISPER_BUILD_TESTS=OFF \
-DWHISPER_BUILD_EXAMPLES=ON
"${CMAKE_BIN}" --build "${RUNTIME_ROOT}/build" --config Release \
--target whisper-cli --parallel "${BUILD_JOBS:-4}"
# Review output: only Apple/system libraries are expected for the macOS runtime.
otool -L "${RUNTIME_ROOT}/build/bin/whisper-cli"
echo "LOCAL_WHISPER_CLI=${RUNTIME_ROOT}/build/bin/whisper-cli"
echo "LOCAL_WHISPER_LICENSE_DIR=${RUNTIME_ROOT}"