|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# This script builds the slm_engine for Android using docker. |
| 4 | +# It uses the Dockerfile in the current directory to build a docker image |
| 5 | +# that contains all the necessary dependencies for building the slm_engine. |
| 6 | +# The script then runs the docker image to build the slm_engine. |
| 7 | +# The script assumes that the Dockerfile is in the same directory as this script. |
| 8 | +# The script also assumes that the android-sdk and android-ndk are installed |
| 9 | +# in the /opt/android-sdk directory. |
| 10 | +# |
| 11 | + |
| 12 | +# Check the architecture |
| 13 | +if [ "$(uname -m)" != "x86_64" ]; then |
| 14 | + echo "This script is intended to run on x86_64 architecture only." |
| 15 | + exit 1 |
| 16 | +fi |
| 17 | + |
| 18 | +set -e |
| 19 | +set -x |
| 20 | +set -u |
| 21 | + |
| 22 | +# Build the docker image |
| 23 | +docker build -t slm-engine-builder -f Dockerfile . |
| 24 | + |
| 25 | +# Define base build_deps command |
| 26 | +BUILD_DEPS_CMD="python3 build_deps.py \ |
| 27 | + --build_ort_from_source \ |
| 28 | + --android_sdk_path /opt/android-sdk/ \ |
| 29 | + --android_ndk_path /opt/android-sdk/ndk/27.2.12479018/" |
| 30 | + |
| 31 | +# Docker volume mount options |
| 32 | +VOLUME_MOUNTS="-v `pwd`/../../../:`pwd`/../../../" |
| 33 | + |
| 34 | +# Check if USE_ORT_VERSION is defined |
| 35 | +if [ ! -z "${USE_ORT_VERSION:-}" ]; then |
| 36 | + BUILD_DEPS_CMD="$BUILD_DEPS_CMD --ort_version_to_use $USE_ORT_VERSION" |
| 37 | + echo "Using ONNX Runtime version: $USE_ORT_VERSION" |
| 38 | +fi |
| 39 | + |
| 40 | +# Check if QNN_SDK_HOME is defined |
| 41 | +if [ ! -z "${QNN_SDK_HOME:-}" ]; then |
| 42 | + # Create Docker mount point for QNN SDK |
| 43 | + QNN_SDK_DOCKER_PATH="/opt/qnn_sdk" |
| 44 | + |
| 45 | + # Add mount for QNN SDK |
| 46 | + VOLUME_MOUNTS="$VOLUME_MOUNTS -v $QNN_SDK_HOME:$QNN_SDK_DOCKER_PATH" |
| 47 | + |
| 48 | + # Use the Docker path in build command |
| 49 | + BUILD_DEPS_CMD="$BUILD_DEPS_CMD --qnn_sdk_path $QNN_SDK_DOCKER_PATH" |
| 50 | + |
| 51 | + echo "QNN SDK path detected, building with QNN support" |
| 52 | + echo "Mounting $QNN_SDK_HOME to $QNN_SDK_DOCKER_PATH in container" |
| 53 | +fi |
| 54 | + |
| 55 | +# Run the docker to build dependencies |
| 56 | +docker run --rm $VOLUME_MOUNTS \ |
| 57 | + -u $(id -u):$(id -g) -w `pwd` \ |
| 58 | + -w $HOME \ |
| 59 | + -it slm-engine-builder bash |
0 commit comments