|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Copyright 2026 Arm Limited and/or its affiliates. |
| 3 | +# |
| 4 | +# This source code is licensed under the BSD-style license found in the |
| 5 | +# LICENSE file in the root directory of this source tree. |
| 6 | + |
| 7 | +# Build the executor_runner application for the Arm VGF backend for |
| 8 | +# deployment on an Android device. |
| 9 | +# |
| 10 | +# Usage: |
| 11 | +# export ANDROID_HOME=/path/to/Android/sdk |
| 12 | +# export ANDROID_NDK_HOME=$ANDROID_HOME/ndk/<version> |
| 13 | +# ./backends/arm/scripts/build_executor_runner_vgf_android.sh |
| 14 | +# |
| 15 | + |
| 16 | +set -eu |
| 17 | + |
| 18 | +script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) |
| 19 | +source "${script_dir}/utils.sh" |
| 20 | + |
| 21 | +et_root_dir=$(cd "${script_dir}/../../.." && pwd) |
| 22 | +mlsdk_dir="${et_root_dir}/examples/arm/arm-scratch/ml-sdk-for-vulkan-manifest" |
| 23 | +output_dir="${et_root_dir}/cmake-out-vgf-android" |
| 24 | +build_type=Release |
| 25 | +android_abi=arm64-v8a |
| 26 | +android_platform=android-28 |
| 27 | +build_with_etdump=false |
| 28 | +build_devtools=OFF |
| 29 | +build_event_tracer=OFF |
| 30 | + |
| 31 | +help() { |
| 32 | + echo "Usage: $(basename "$0") [options]" |
| 33 | + echo "Note: this developer build script is not a stable public API." |
| 34 | + echo "Options:" |
| 35 | + echo " --output=<DIR> Build directory (default: ${output_dir})" |
| 36 | + echo " --build-type=<TYPE> CMake build type (default: ${build_type})" |
| 37 | + echo " --android-abi=<ABI> Android ABI (default: ${android_abi})" |
| 38 | + echo " --android-platform=<API> Android platform (default: ${android_platform})" |
| 39 | + echo " --etdump Build with ETDump profiling support" |
| 40 | +} |
| 41 | + |
| 42 | +for arg in "$@"; do |
| 43 | + case ${arg} in |
| 44 | + -h | --help) |
| 45 | + help |
| 46 | + exit 0 |
| 47 | + ;; |
| 48 | + --output=*) output_dir="${arg#*=}" ;; |
| 49 | + --build-type=*) build_type="${arg#*=}" ;; |
| 50 | + --android-abi=*) android_abi="${arg#*=}" ;; |
| 51 | + --android-platform=*) android_platform="${arg#*=}" ;; |
| 52 | + --etdump) build_with_etdump=true ;; |
| 53 | + *) |
| 54 | + echo "Unknown option: ${arg}" >&2 |
| 55 | + help >&2 |
| 56 | + exit 1 |
| 57 | + ;; |
| 58 | + esac |
| 59 | +done |
| 60 | + |
| 61 | +android_ndk=${ANDROID_NDK_HOME:-${ANDROID_NDK:-}} |
| 62 | +if [[ -z ${android_ndk} ]]; then |
| 63 | + echo "Set ANDROID_NDK_HOME or ANDROID_NDK to the Android NDK directory." >&2 |
| 64 | + exit 1 |
| 65 | +fi |
| 66 | + |
| 67 | +toolchain_file="${android_ndk}/build/cmake/android.toolchain.cmake" |
| 68 | +vgf_source_dir="${mlsdk_dir}/sw/vgf-lib" |
| 69 | +flatbuffers_dir="${mlsdk_dir}/dependencies/flatbuffers" |
| 70 | +vgf_build_dir="${output_dir}/vgf-lib" |
| 71 | +vgf_install_dir="${output_dir}/vgf-install" |
| 72 | +executorch_build_dir="${output_dir}/executorch" |
| 73 | + |
| 74 | +[[ -f ${toolchain_file} ]] || { |
| 75 | + echo "Android CMake toolchain not found: ${toolchain_file}" >&2 |
| 76 | + exit 1 |
| 77 | +} |
| 78 | +[[ -f ${vgf_source_dir}/CMakeLists.txt ]] || { |
| 79 | + echo "VGF source not found: ${vgf_source_dir}" >&2 |
| 80 | + echo "Install the MLSDK source tree with examples/arm/setup.sh first." >&2 |
| 81 | + exit 1 |
| 82 | +} |
| 83 | +[[ -f ${flatbuffers_dir}/CMakeLists.txt ]] || { |
| 84 | + echo "MLSDK FlatBuffers source not found: ${flatbuffers_dir}" >&2 |
| 85 | + exit 1 |
| 86 | +} |
| 87 | + |
| 88 | +mkdir -p "${output_dir}" |
| 89 | + |
| 90 | +if [[ ${build_with_etdump} == true ]]; then |
| 91 | + build_devtools=ON |
| 92 | + build_event_tracer=ON |
| 93 | +fi |
| 94 | + |
| 95 | +# Cross-compile the VGF library for Android |
| 96 | +cmake \ |
| 97 | + -S "${vgf_source_dir}" \ |
| 98 | + -B "${vgf_build_dir}" \ |
| 99 | + -DCMAKE_TOOLCHAIN_FILE="${toolchain_file}" \ |
| 100 | + -DANDROID_ABI="${android_abi}" \ |
| 101 | + -DANDROID_PLATFORM="${android_platform}" \ |
| 102 | + -DCMAKE_BUILD_TYPE="${build_type}" \ |
| 103 | + -DCMAKE_INSTALL_PREFIX="${vgf_install_dir}" \ |
| 104 | + -DCMAKE_INSTALL_LIBDIR=lib \ |
| 105 | + -DFLATBUFFERS_PATH="${flatbuffers_dir}" \ |
| 106 | + -DML_SDK_VGF_LIB_BUILD_TOOLS=OFF \ |
| 107 | + -DML_SDK_VGF_LIB_BUILD_TESTS=OFF \ |
| 108 | + -DML_SDK_VGF_LIB_BUILD_PYLIB=OFF \ |
| 109 | + -DML_SDK_VGF_LIB_BUILD_SHARED=OFF |
| 110 | + |
| 111 | +parallel_jobs="$(get_parallel_jobs)" |
| 112 | + |
| 113 | +cmake --build "${vgf_build_dir}" --target vgf --parallel "${parallel_jobs}" |
| 114 | +cmake --install "${vgf_build_dir}" |
| 115 | + |
| 116 | +# Cross-compile ExecuTorch for Android and link against the Android build of the libvgf.a |
| 117 | +cmake \ |
| 118 | + -S "${et_root_dir}" \ |
| 119 | + -B "${executorch_build_dir}" \ |
| 120 | + -DCMAKE_TOOLCHAIN_FILE="${toolchain_file}" \ |
| 121 | + -DANDROID_ABI="${android_abi}" \ |
| 122 | + -DANDROID_PLATFORM="${android_platform}" \ |
| 123 | + -DCMAKE_BUILD_TYPE="${build_type}" \ |
| 124 | + -DEXECUTORCH_PAL_DEFAULT=android \ |
| 125 | + -DEXECUTORCH_VGF_ROOT="${vgf_install_dir}" \ |
| 126 | + -DEXECUTORCH_BUILD_VGF=ON \ |
| 127 | + -DEXECUTORCH_BUILD_VULKAN=OFF \ |
| 128 | + -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON \ |
| 129 | + -DEXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL=ON \ |
| 130 | + -DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \ |
| 131 | + -DEXECUTORCH_BUILD_XNNPACK=OFF \ |
| 132 | + -DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=OFF \ |
| 133 | + -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \ |
| 134 | + -DEXECUTORCH_ENABLE_LOGGING=ON \ |
| 135 | + -DEXECUTORCH_BUILD_DEVTOOLS="${build_devtools}" \ |
| 136 | + -DEXECUTORCH_ENABLE_EVENT_TRACER="${build_event_tracer}" |
| 137 | + |
| 138 | +cmake --build "${executorch_build_dir}" \ |
| 139 | + --target executor_runner \ |
| 140 | + --parallel "${parallel_jobs}" |
| 141 | + |
| 142 | +echo "Android VGF executor runner: ${executorch_build_dir}/executor_runner" |
0 commit comments