Geoffrey Martin-Noble | 93c5089 | 2022-08-08 18:32:33 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright 2022 The IREE Authors |
| 4 | # |
| 5 | # Licensed under the Apache License v2.0 with LLVM Exceptions. |
| 6 | # See https://llvm.org/LICENSE.txt for license information. |
| 7 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 8 | |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 9 | # Cross-compile the runtime using CMake targeting Android |
Geoffrey Martin-Noble | 93c5089 | 2022-08-08 18:32:33 -0700 | [diff] [blame] | 10 | # |
Scott Todd | a92999e | 2023-01-13 10:13:12 -0800 | [diff] [blame] | 11 | # The required IREE_HOST_BIN_DIR environment variable indicates the location |
Jerry Wu | e4e2398 | 2023-04-19 18:16:03 +0000 | [diff] [blame] | 12 | # of the precompiled IREE binaries. Also requires that ANDROID_NDK variables be |
| 13 | # set. The BUILD_PRESET environment variable indicates how the project should be |
| 14 | # configured: "test", "benchmark", "benchmark-with-tracing", or |
| 15 | # "benchmark-suite-test". Defaults to "test". |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 16 | # |
| 17 | # The desired build directory can be passed as the first argument. Otherwise, it |
Jerry Wu | 85ff57f | 2022-12-12 21:39:26 +0000 | [diff] [blame] | 18 | # uses the environment variable IREE_TARGET_BUILD_DIR, defaulting to |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 19 | # "build-android". Designed for CI, but can be run manually. It reuses the build |
| 20 | # directory if it already exists. Expects to be run from the root of the IREE |
| 21 | # repository. |
Jerry Wu | e4e2398 | 2023-04-19 18:16:03 +0000 | [diff] [blame] | 22 | # |
| 23 | # The default Android ABI is arm64-v8a, you can specify it with the variable |
| 24 | # IREE_ANDROID_ABI. See https://developer.android.com/ndk/guides/abis for the |
| 25 | # supported ABIs. |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 26 | |
Geoffrey Martin-Noble | 93c5089 | 2022-08-08 18:32:33 -0700 | [diff] [blame] | 27 | |
| 28 | set -xeuo pipefail |
| 29 | |
Jerry Wu | 85ff57f | 2022-12-12 21:39:26 +0000 | [diff] [blame] | 30 | BUILD_DIR="${1:-${IREE_TARGET_BUILD_DIR:-build-android}}" |
Jerry Wu | e4e2398 | 2023-04-19 18:16:03 +0000 | [diff] [blame] | 31 | ANDROID_ABI="${IREE_ANDROID_ABI:-arm64-v8a}" |
Scott Todd | a92999e | 2023-01-13 10:13:12 -0800 | [diff] [blame] | 32 | IREE_HOST_BIN_DIR="$(realpath ${IREE_HOST_BIN_DIR})" |
Jerry Wu | 9484142 | 2022-12-01 21:14:50 +0000 | [diff] [blame] | 33 | E2E_TEST_ARTIFACTS_DIR="${E2E_TEST_ARTIFACTS_DIR:-build-e2e-test-artifacts/e2e_test_artifacts}" |
CindyLiu | b593bbd | 2022-10-17 22:03:34 -0700 | [diff] [blame] | 34 | BUILD_PRESET="${BUILD_PRESET:-test}" |
Geoffrey Martin-Noble | 93c5089 | 2022-08-08 18:32:33 -0700 | [diff] [blame] | 35 | |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 36 | source build_tools/cmake/setup_build.sh |
Geoffrey Martin-Noble | 46e47e3 | 2022-11-29 16:39:45 -0800 | [diff] [blame] | 37 | source build_tools/cmake/setup_ccache.sh |
Geoffrey Martin-Noble | 93c5089 | 2022-08-08 18:32:33 -0700 | [diff] [blame] | 38 | |
| 39 | declare -a args=( |
| 40 | -G Ninja |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 41 | -B "${BUILD_DIR}" |
Jerry Wu | 56d65bf | 2023-01-04 20:44:09 -0500 | [diff] [blame] | 42 | -DPython3_EXECUTABLE="${IREE_PYTHON3_EXECUTABLE}" |
| 43 | -DPYTHON_EXECUTABLE="${IREE_PYTHON3_EXECUTABLE}" |
Geoffrey Martin-Noble | 93c5089 | 2022-08-08 18:32:33 -0700 | [diff] [blame] | 44 | -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" |
| 45 | -DANDROID_ABI="${ANDROID_ABI}" |
| 46 | -DANDROID_PLATFORM=android-29 |
Scott Todd | a92999e | 2023-01-13 10:13:12 -0800 | [diff] [blame] | 47 | -DIREE_HOST_BIN_DIR="${IREE_HOST_BIN_DIR}" |
Geoffrey Martin-Noble | 93c5089 | 2022-08-08 18:32:33 -0700 | [diff] [blame] | 48 | -DIREE_BUILD_COMPILER=OFF |
| 49 | -DIREE_BUILD_TESTS=ON |
| 50 | -DIREE_BUILD_SAMPLES=OFF |
| 51 | ) |
| 52 | |
CindyLiu | b593bbd | 2022-10-17 22:03:34 -0700 | [diff] [blame] | 53 | case "${BUILD_PRESET}" in |
| 54 | test) |
| 55 | args+=( |
| 56 | -DIREE_ENABLE_ASSERTIONS=ON |
| 57 | ) |
| 58 | ;; |
| 59 | benchmark) |
| 60 | args+=( |
| 61 | -DIREE_ENABLE_ASSERTIONS=OFF |
| 62 | -DIREE_BUILD_TESTS=OFF |
| 63 | ) |
| 64 | ;; |
| 65 | benchmark-with-tracing) |
| 66 | args+=( |
| 67 | -DIREE_ENABLE_ASSERTIONS=OFF |
| 68 | -DIREE_BUILD_TESTS=OFF |
| 69 | -DIREE_ENABLE_RUNTIME_TRACING=ON |
| 70 | ) |
| 71 | ;; |
| 72 | benchmark-suite-test) |
Jerry Wu | 9484142 | 2022-12-01 21:14:50 +0000 | [diff] [blame] | 73 | E2E_TEST_ARTIFACTS_DIR="$(realpath ${E2E_TEST_ARTIFACTS_DIR})" |
CindyLiu | b593bbd | 2022-10-17 22:03:34 -0700 | [diff] [blame] | 74 | args+=( |
| 75 | -DIREE_ENABLE_ASSERTIONS=ON |
Jerry Wu | 9484142 | 2022-12-01 21:14:50 +0000 | [diff] [blame] | 76 | -DIREE_E2E_TEST_ARTIFACTS_DIR="${E2E_TEST_ARTIFACTS_DIR}" |
CindyLiu | b593bbd | 2022-10-17 22:03:34 -0700 | [diff] [blame] | 77 | ) |
| 78 | ;; |
| 79 | *) |
| 80 | echo "Unknown build preset: ${BUILD_PRESET}" |
| 81 | exit 1 |
| 82 | ;; |
| 83 | esac |
| 84 | |
Geoffrey Martin-Noble | 93c5089 | 2022-08-08 18:32:33 -0700 | [diff] [blame] | 85 | # Configure towards 64-bit Android 10, then build. |
| 86 | "${CMAKE_BIN}" "${args[@]}" |
| 87 | |
| 88 | |
| 89 | echo "Building all for device" |
| 90 | echo "------------" |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 91 | "${CMAKE_BIN}" --build "${BUILD_DIR}" -- -k 0 |
Geoffrey Martin-Noble | 93c5089 | 2022-08-08 18:32:33 -0700 | [diff] [blame] | 92 | |
| 93 | echo "Building test deps for device" |
| 94 | echo "------------------" |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 95 | "${CMAKE_BIN}" --build "${BUILD_DIR}" --target iree-test-deps -- -k 0 |
Geoffrey Martin-Noble | 46e47e3 | 2022-11-29 16:39:45 -0800 | [diff] [blame] | 96 | |
Scott Todd | fb16d60 | 2023-01-23 11:48:32 -0800 | [diff] [blame] | 97 | if (( IREE_USE_CCACHE == 1 )); then |
Geoffrey Martin-Noble | 46e47e3 | 2022-11-29 16:39:45 -0800 | [diff] [blame] | 98 | ccache --show-stats |
| 99 | fi |