|
| 1 | +#!/bin/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 | + |
| 8 | +set -ex |
| 9 | + |
| 10 | +if ["${ANDROID_NDK}" == ""]; then |
| 11 | + echo "Please set ANDROID_NDK enviornment variable." |
| 12 | + echo "For example it can be /Users/guest/Desktop/android-ndk-r26." |
| 13 | + echo "You can download NDK from android website" |
| 14 | + exit 1 |
| 15 | +else |
| 16 | + echo "ANDROID_NDK set to ${ANDROID_NDK}" |
| 17 | +fi |
| 18 | + |
| 19 | +export CMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake |
| 20 | +export DANDROID_ABI=arm64-v8a |
| 21 | +export DANDROID_PLATFORM=android-23 |
| 22 | +export ET_BUILD_DIR="et-build-android" |
| 23 | +export CMAKE_OUT_DIR="cmake-out-android" |
| 24 | +# export DCMAKE_INSTALL_PREFIX=cmake-out-android |
| 25 | +# |
| 26 | + |
| 27 | +install_executorch() { |
| 28 | + echo "Cloning executorch to ${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/src" |
| 29 | + ET_BUILD_DIR="${TORCHCHAT_ROOT}/${ET_BUILD_DIR}" |
| 30 | + rm -rf ${ET_BUILD_DIR} |
| 31 | + mkdir -p ${ET_BUILD_DIR}/src |
| 32 | + pushd ${ET_BUILD_DIR}/src |
| 33 | + git clone https://github.com/pytorch/executorch.git |
| 34 | + cd executorch |
| 35 | + git checkout viable/strict |
| 36 | + echo "Install executorch: submodule update" |
| 37 | + git submodule sync |
| 38 | + git submodule update --init |
| 39 | + |
| 40 | + echo "Applying fixes" |
| 41 | + cp ${TORCHCHAT_ROOT}/scripts/fixes_et/module.cpp ${ET_BUILD_DIR}/src/executorch/extension/module/module.cpp # ET uses non-standard C++ that does not compile in GCC |
| 42 | + cp ${TORCHCHAT_ROOT}/scripts/fixes_et/managed_tensor.h ${ET_BUILD_DIR}/src/executorch/extension/runner_util/managed_tensor.h # ET is missing headers for vector/memory. This causes downstream issues when building runner-et. |
| 43 | + |
| 44 | + CMAKE_OUT_DIR="cmake-out-android" |
| 45 | + echo "Building and installing C++ libraries" |
| 46 | + echo "Inside: ${PWD}" |
| 47 | + mkdir ${CMAKE_OUT_DIR} |
| 48 | + cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-23 -DCMAKE_INSTALL_PREFIX=cmake-out-android -DEXECUTORCH_ENABLE_LOGGING=ON -DEXECUTORCH_LOG_LEVEL=Info -DEXECUTORCH_BUILD_OPTIMIZED=ON -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON -DEXECUTORCH_BUILD_XNNPACK=ON -S . -B ${CMAKE_OUT_DIR} -G Ninja |
| 49 | + cmake --build ${CMAKE_OUT_DIR} |
| 50 | + cmake --install ${CMAKE_OUT_DIR} --prefix ${ET_BUILD_DIR}/install |
| 51 | + popd |
| 52 | +} |
| 53 | + |
| 54 | +build_runner_et() { |
| 55 | + rm -rf build/cmake-out-android |
| 56 | + cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-23 -S ./runner-et -B build/cmake-out-android -G Ninja |
| 57 | + cmake --build build/cmake-out-android/ -j16 --config Release |
| 58 | +} |
| 59 | + |
| 60 | +# install_executorch |
| 61 | +build_runner_et |
0 commit comments