1#!/usr/bin/env bash 2# Copyright (c) Meta Platforms, Inc. and affiliates. 3# All rights reserved. 4# 5# This source code is licensed under the BSD-style license found in the 6# LICENSE file in the root directory of this source tree. 7 8set -eu 9 10CMAKE_OUT="${CMAKE_OUT:-cmake-out-android}" 11# Note: Set up ANDROID_NDK and ANDROID_ABI 12cmake . -DCMAKE_INSTALL_PREFIX="${CMAKE_OUT}" \ 13 -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \ 14 -DANDROID_ABI="${ANDROID_ABI}" \ 15 -DEXECUTORCH_BUILD_XNNPACK=ON \ 16 -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \ 17 -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \ 18 -DEXECUTORCH_BUILD_EXTENSION_TESNOR=ON \ 19 -DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \ 20 -DCMAKE_BUILD_TYPE=Release \ 21 -B"${CMAKE_OUT}" 22 23if [ "$(uname)" == "Darwin" ]; then 24 CMAKE_JOBS=$(( $(sysctl -n hw.ncpu) - 1 )) 25else 26 CMAKE_JOBS=$(( $(nproc) - 1 )) 27fi 28cmake --build "${CMAKE_OUT}" -j "${CMAKE_JOBS}" --target install --config Release 29 30cmake extension/android \ 31 -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake \ 32 -DANDROID_ABI="${ANDROID_ABI}" \ 33 -DCMAKE_INSTALL_PREFIX="${CMAKE_OUT}" \ 34 -DCMAKE_BUILD_TYPE=Release \ 35 -B"${CMAKE_OUT}"/extension/android 36 37cmake --build "${CMAKE_OUT}"/extension/android -j "${CMAKE_JOBS}" --config Release 38 39JNI_LIBS_PATH="examples/demo-apps/android/ExecuTorchDemo/app/src/main/jniLibs" 40mkdir -p "${JNI_LIBS_PATH}/${ANDROID_ABI}" 41cp "${CMAKE_OUT}"/extension/android/libexecutorch_jni.so "${JNI_LIBS_PATH}/${ANDROID_ABI}/" 42