1#!/bin/bash 2 3# Exit immediately if a command exits with a non-zero status. 4set -e 5 6# Define the directory where CMakeLists.txt is located 7SOURCE_DIR=$(realpath "$(dirname "$0")/../../..") 8 9# Check if buck2 exists 10BUCK_PATH=${BUCK2:-buck2} 11if [ -z "$BUCK2" ]; then 12 echo "Info: BUCK2 environment variable is not set." >&2 13fi 14 15# Check if the ANDROID_NDK environment variable is set 16if [ -z "$ANDROID_NDK" ]; then 17 echo "Error: ANDROID_NDK environment variable is not set." >&2 18 exit 1 19fi 20 21# Check if the NEURON_BUFFER_ALLOCATOR_LIB environment variable is set 22if [ -z "$NEURON_BUFFER_ALLOCATOR_LIB" ]; then 23 echo "Error: NEURON_BUFFER_ALLOCATOR_LIB environment variable is not set." >&2 24 exit 1 25fi 26 27# Create and enter the build directory 28cd "$SOURCE_DIR" 29rm -rf cmake-android-out && mkdir cmake-android-out && cd cmake-android-out 30 31# Configure the project with CMake 32# Note: Add any additional configuration options you need here 33cmake -DBUCK2="$BUCK_PATH" \ 34 -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \ 35 -DANDROID_ABI=arm64-v8a \ 36 -DEXECUTORCH_BUILD_NEURON=ON \ 37 -DNEURON_BUFFER_ALLOCATOR_LIB="$NEURON_BUFFER_ALLOCATOR_LIB" \ 38 .. 39 40# Build the project 41cd .. 42cmake --build cmake-android-out -j4 43 44# Switch back to the original directory 45cd - > /dev/null 46 47# Print a success message 48echo "Build successfully completed." 49