build: bundle onnxruntime in linux releases
This commit is contained in:
@@ -40,9 +40,20 @@ Use `libpipewire-0.3`, not `pipewire-0.3`. The latter probe will fail even on a
|
||||
correctly provisioned host because it is not the module name exported by the
|
||||
PipeWire development package.
|
||||
|
||||
## Optional: bundle ONNX Runtime
|
||||
## Bundled ONNX Runtime
|
||||
|
||||
If you want the Linux bundle to include ONNX Runtime for Silero VAD, export:
|
||||
Linux release builds include ONNX Runtime for Silero VAD by default. The build
|
||||
helper downloads the official Linux CPU archive into `.cache/onnxruntime/` for
|
||||
the current target architecture and stages `libonnxruntime.so` into the app
|
||||
bundle.
|
||||
|
||||
To pin a specific ONNX Runtime release, export:
|
||||
|
||||
```bash
|
||||
export CHANORA_ONNXRUNTIME_VERSION=1.26.0
|
||||
```
|
||||
|
||||
To use a local shared library instead of downloading the archive, export:
|
||||
|
||||
```bash
|
||||
export CHANORA_ONNXRUNTIME_SHARED_LIB=/absolute/path/to/libonnxruntime.so
|
||||
@@ -87,5 +98,5 @@ To build a `.deb` package:
|
||||
./tools/build-linux-deb.sh
|
||||
```
|
||||
|
||||
If `CHANORA_ONNXRUNTIME_SHARED_LIB` is set, the Debian helper now verifies that
|
||||
`libonnxruntime.so` was actually bundled before packaging.
|
||||
The Debian helper verifies that `libonnxruntime.so` was actually bundled before
|
||||
packaging.
|
||||
|
||||
@@ -12,7 +12,6 @@ STAGE_DIR="$(mktemp -d "${TMPDIR:-/tmp}/chanora-linux-deb.XXXXXX")"
|
||||
PKG_ROOT="$STAGE_DIR/package"
|
||||
INSTALL_ROOT="$PKG_ROOT/opt/chanora"
|
||||
ICON_SRC="$APP_DIR/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png"
|
||||
ONNXRUNTIME_SHARED_LIB="${CHANORA_ONNXRUNTIME_SHARED_LIB:-}"
|
||||
|
||||
cleanup() {
|
||||
rm -rf "$STAGE_DIR"
|
||||
@@ -68,9 +67,6 @@ main() {
|
||||
require_cmd dpkg-deb
|
||||
require_file "$PUBSPEC" "Flutter pubspec"
|
||||
require_file "$ICON_SRC" "launcher icon"
|
||||
if [[ -n "$ONNXRUNTIME_SHARED_LIB" ]]; then
|
||||
require_file "$ONNXRUNTIME_SHARED_LIB" "Linux ONNX Runtime shared library"
|
||||
fi
|
||||
|
||||
if [[ ! -f "$OBOE_DIR/Cargo.toml" ]]; then
|
||||
cat >&2 <<EOF
|
||||
@@ -110,9 +106,7 @@ EOF
|
||||
local bundle_dir="$APP_DIR/build/linux/$flutter_arch/release/bundle"
|
||||
local app_binary="$bundle_dir/chanora_flutter"
|
||||
require_file "$app_binary" "Linux release bundle binary"
|
||||
if [[ -n "$ONNXRUNTIME_SHARED_LIB" ]]; then
|
||||
require_file "$bundle_dir/lib/libonnxruntime.so" "bundled Linux ONNX Runtime shared library"
|
||||
fi
|
||||
require_file "$bundle_dir/lib/libonnxruntime.so" "bundled Linux ONNX Runtime shared library"
|
||||
|
||||
mkdir -p \
|
||||
"$PKG_ROOT/DEBIAN" \
|
||||
|
||||
+69
-18
@@ -8,7 +8,7 @@
|
||||
# - CMake 3.13+, pkg-config, GTK3 dev headers, clang
|
||||
# - System libopus development package (libopus-dev / opus-devel)
|
||||
# - Optional: CHANORA_ONNXRUNTIME_SHARED_LIB=/abs/path/libonnxruntime.so
|
||||
# to bundle ONNX Runtime into the Linux app under bundle/lib/
|
||||
# to override the ONNX Runtime shared library bundled under bundle/lib/
|
||||
# - flutter_rust_bridge_codegen 2.12.0 (only if regenerating bindings)
|
||||
#
|
||||
# Usage (from the repo root ~/chanora):
|
||||
@@ -29,6 +29,7 @@ SKIP_RUST=0
|
||||
REGEN=0
|
||||
TARGET="x86_64-unknown-linux-gnu"
|
||||
ONNXRUNTIME_SHARED_LIB="${CHANORA_ONNXRUNTIME_SHARED_LIB:-}"
|
||||
ONNXRUNTIME_VERSION="${CHANORA_ONNXRUNTIME_VERSION:-1.26.0}"
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
@@ -51,12 +52,65 @@ echo "Repo root : $REPO_ROOT"
|
||||
echo "Version : $VERSION"
|
||||
echo "Target : $TARGET"
|
||||
echo "Build Rust: $([ "$SKIP_RUST" = 1 ] && echo skip || echo yes)"
|
||||
echo "Bundle ORT: ${ONNXRUNTIME_SHARED_LIB:-<not set>}"
|
||||
echo "Bundle ORT: ${ONNXRUNTIME_SHARED_LIB:-auto ($ONNXRUNTIME_VERSION)}"
|
||||
bar
|
||||
|
||||
resolve_onnxruntime_shared_lib() {
|
||||
if [[ -n "$ONNXRUNTIME_SHARED_LIB" ]]; then
|
||||
if [[ ! -f "$ONNXRUNTIME_SHARED_LIB" ]]; then
|
||||
echo " ERROR: CHANORA_ONNXRUNTIME_SHARED_LIB does not exist:" >&2
|
||||
echo " $ONNXRUNTIME_SHARED_LIB" >&2
|
||||
exit 1
|
||||
fi
|
||||
return
|
||||
fi
|
||||
|
||||
local ort_arch
|
||||
case "$TARGET" in
|
||||
x86_64-unknown-linux-gnu) ort_arch="x64" ;;
|
||||
aarch64-unknown-linux-gnu) ort_arch="aarch64" ;;
|
||||
*)
|
||||
echo " ERROR: automatic ONNX Runtime bundling does not support target $TARGET." >&2
|
||||
echo " Set CHANORA_ONNXRUNTIME_SHARED_LIB=/absolute/path/to/libonnxruntime.so." >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
local archive_name="onnxruntime-linux-${ort_arch}-${ONNXRUNTIME_VERSION}.tgz"
|
||||
local cache_dir="$REPO_ROOT/.cache/onnxruntime/$ONNXRUNTIME_VERSION/$ort_arch"
|
||||
local archive_path="$cache_dir/$archive_name"
|
||||
local extract_dir="$cache_dir/extracted"
|
||||
local extracted_lib="$extract_dir/onnxruntime-linux-${ort_arch}-${ONNXRUNTIME_VERSION}/lib/libonnxruntime.so"
|
||||
local url="https://github.com/microsoft/onnxruntime/releases/download/v${ONNXRUNTIME_VERSION}/${archive_name}"
|
||||
|
||||
if [[ ! -f "$extracted_lib" ]]; then
|
||||
mkdir -p "$cache_dir" "$extract_dir"
|
||||
if [[ ! -f "$archive_path" ]]; then
|
||||
if ! command -v curl >/dev/null; then
|
||||
echo " ERROR: curl is required to download ONNX Runtime automatically." >&2
|
||||
echo " Install curl or set CHANORA_ONNXRUNTIME_SHARED_LIB." >&2
|
||||
exit 1
|
||||
fi
|
||||
echo " Downloading ONNX Runtime $ONNXRUNTIME_VERSION for linux-$ort_arch"
|
||||
curl --fail --location --show-error --output "$archive_path" "$url"
|
||||
fi
|
||||
rm -rf "$extract_dir"
|
||||
mkdir -p "$extract_dir"
|
||||
tar -xzf "$archive_path" -C "$extract_dir"
|
||||
fi
|
||||
|
||||
if [[ ! -f "$extracted_lib" ]]; then
|
||||
echo " ERROR: ONNX Runtime archive did not contain expected library:" >&2
|
||||
echo " $extracted_lib" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ONNXRUNTIME_SHARED_LIB="$extracted_lib"
|
||||
}
|
||||
|
||||
# ---------- 1. Verify toolchain ----------
|
||||
echo "[1/6] Verify toolchain"
|
||||
for cmd in cargo rustc flutter cmake pkg-config clang gcc; do
|
||||
for cmd in cargo rustc flutter cmake pkg-config clang gcc tar; do
|
||||
if ! command -v "$cmd" >/dev/null; then
|
||||
echo " ERROR: '$cmd' not on PATH. See docs/release/linux-build.md." >&2
|
||||
exit 1
|
||||
@@ -114,12 +168,8 @@ fi
|
||||
printf " %-12s : %s\n" "libpulse" "$(pkg-config --modversion libpulse)"
|
||||
printf " %-12s : %s\n" "pulse-simple" "$(pkg-config --modversion libpulse-simple)"
|
||||
|
||||
# Verify the optional ONNX Runtime shared library when explicitly requested.
|
||||
if [[ -n "$ONNXRUNTIME_SHARED_LIB" && ! -f "$ONNXRUNTIME_SHARED_LIB" ]]; then
|
||||
echo " ERROR: CHANORA_ONNXRUNTIME_SHARED_LIB does not exist:" >&2
|
||||
echo " $ONNXRUNTIME_SHARED_LIB" >&2
|
||||
exit 1
|
||||
fi
|
||||
resolve_onnxruntime_shared_lib
|
||||
echo " ORT source : $ONNXRUNTIME_SHARED_LIB"
|
||||
|
||||
# Verify Rust target
|
||||
if ! rustup target list --installed | grep -q "^$TARGET$"; then
|
||||
@@ -174,6 +224,7 @@ fi
|
||||
echo "[5/6] flutter build linux --release"
|
||||
cd "$FLUTTER_APP"
|
||||
export CHANORA_BRIDGE_SHARED_LIB="$BRIDGE_SO"
|
||||
export CHANORA_ONNXRUNTIME_SHARED_LIB="$ONNXRUNTIME_SHARED_LIB"
|
||||
flutter pub get
|
||||
flutter build linux --release
|
||||
|
||||
@@ -184,6 +235,10 @@ if [[ ! -f "$EXE" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$BUNDLE_DIR/lib"
|
||||
rm -f "$BUNDLE_DIR/lib/libonnxruntime.so"
|
||||
cp "$ONNXRUNTIME_SHARED_LIB" "$BUNDLE_DIR/lib/libonnxruntime.so"
|
||||
|
||||
echo " Bundle dir : $BUNDLE_DIR"
|
||||
echo " EXE : $EXE"
|
||||
echo " Bridge .so : $BUNDLE_DIR/lib/libchanora_bridge.so"
|
||||
@@ -192,16 +247,12 @@ if [[ ! -f "$BUNDLE_DIR/lib/libchanora_bridge.so" ]]; then
|
||||
echo " $BUNDLE_DIR/lib/libchanora_bridge.so" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ -n "$ONNXRUNTIME_SHARED_LIB" ]]; then
|
||||
if [[ -f "$BUNDLE_DIR/lib/libonnxruntime.so" ]]; then
|
||||
echo " ORT .so : $BUNDLE_DIR/lib/libonnxruntime.so"
|
||||
else
|
||||
echo " ERROR: ONNX Runtime bundle file missing after flutter build:" >&2
|
||||
echo " $BUNDLE_DIR/lib/libonnxruntime.so" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ -f "$BUNDLE_DIR/lib/libonnxruntime.so" ]]; then
|
||||
echo " ORT .so : $BUNDLE_DIR/lib/libonnxruntime.so"
|
||||
else
|
||||
echo " ORT .so : not bundled (set CHANORA_ONNXRUNTIME_SHARED_LIB to include it)"
|
||||
echo " ERROR: ONNX Runtime bundle file missing after flutter build:" >&2
|
||||
echo " $BUNDLE_DIR/lib/libonnxruntime.so" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ---------- 6. Package the bundle ----------
|
||||
|
||||
Reference in New Issue
Block a user