From d07cff6f0d0e0a9d198fbd3a2c807b58bdc3320e Mon Sep 17 00:00:00 2001 From: neuropilot-captain Date: Mon, 4 Aug 2025 10:17:57 +0800 Subject: [PATCH 1/2] Refactor MTK build scripts Test building MTK examples and runners in ci --- .ci/scripts/build-mediatek-sdk.sh | 2 +- backends/mediatek/scripts/mtk_build.sh | 8 ++++--- examples/mediatek/mtk_build_examples.sh | 29 ++++++++----------------- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/.ci/scripts/build-mediatek-sdk.sh b/.ci/scripts/build-mediatek-sdk.sh index 81e64b241ce..e01e10d6009 100755 --- a/.ci/scripts/build-mediatek-sdk.sh +++ b/.ci/scripts/build-mediatek-sdk.sh @@ -14,9 +14,9 @@ build_neuron_backend() { export NEURON_BUFFER_ALLOCATOR_LIB=${MEDIATEK_SDK_ROOT}/libneuron_buffer_allocator.so export EXECUTORCH_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd)" - cd ${EXECUTORCH_ROOT} ./backends/mediatek/scripts/mtk_build.sh + ./examples/mediatek/mtk_build_examples.sh } build_neuron_backend diff --git a/backends/mediatek/scripts/mtk_build.sh b/backends/mediatek/scripts/mtk_build.sh index 2d9a2faa5c3..599f754d7bc 100755 --- a/backends/mediatek/scripts/mtk_build.sh +++ b/backends/mediatek/scripts/mtk_build.sh @@ -4,7 +4,8 @@ set -e # Define the directory where CMakeLists.txt is located -SOURCE_DIR=$(realpath "$(dirname "$0")/../../..") +EXECUTORCH_ROOT=$(realpath "$(dirname "$0")/../../..") +echo EXECUTORCH_ROOT=${EXECUTORCH_ROOT} # Check if the ANDROID_NDK environment variable is set if [ -z "$ANDROID_NDK" ]; then @@ -12,10 +13,11 @@ if [ -z "$ANDROID_NDK" ]; then exit 1 fi -# Create and enter the build directory +# Enter the build directory +cd "$EXECUTORCH_ROOT" + # Set build directory build_dir="cmake-android-out" -cd "$SOURCE_DIR" rm -rf "${build_dir}" # Configure the project with CMake diff --git a/examples/mediatek/mtk_build_examples.sh b/examples/mediatek/mtk_build_examples.sh index a46bdd3d1ce..afdd9f16d51 100755 --- a/examples/mediatek/mtk_build_examples.sh +++ b/examples/mediatek/mtk_build_examples.sh @@ -14,29 +14,18 @@ if [ -z "$ANDROID_NDK" ]; then fi main() { - # Set build directory - local build_dir="cmake-android-out" - - # Create and enter the build directory + # Enter the build directory cd "$EXECUTORCH_ROOT" - rm -rf "${build_dir}" - - # Configure the project with CMake - # Note: Add any additional configuration options you need here - cmake -DCMAKE_INSTALL_PREFIX="${build_dir}" \ - -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \ - -DANDROID_ABI=arm64-v8a \ - -DANDROID_NATIVE_API_LEVEL=26 \ - -DANDROID_PLATFORM=android-26 \ - -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \ - -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \ - -DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON \ - -DEXECUTORCH_BUILD_NEURON=ON \ - -B"${build_dir}" + # Set build directory + local build_dir="cmake-android-out" - # Build the project - cmake --build "${build_dir}" --target install --config Release -j5 + # Check if the build directory exists + if [ ! -d "$EXECUTORCH_ROOT/$build_dir" ]; then + echo "Error: Build directory '$build_dir' does not exist." + echo "Please build MTK backend before running this script." + exit 1 + fi ## Build example local example_dir=examples/mediatek From 0997aa1bdf89d476eb04afa9fb358ea1d2d4c234 Mon Sep 17 00:00:00 2001 From: neuropilot-captain Date: Mon, 4 Aug 2025 11:14:50 +0800 Subject: [PATCH 2/2] Update documents --- examples/mediatek/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/mediatek/README.md b/examples/mediatek/README.md index c63a522ffcc..876d40adf7e 100644 --- a/examples/mediatek/README.md +++ b/examples/mediatek/README.md @@ -28,6 +28,8 @@ examples/mediatek ## Environment Setup - Follow the instructions of **Prerequisites** and **Setup** in `backends/mediatek/scripts/README.md`. +- Build required libraries by `backends/mediatek/scripts/mtk_build.sh` before building examples. + ## Build MediaTek Examples 1. Build the backend and the examples by exedcuting the script: ```bash