blob: cc923a30b190afd898acc817050d96445e06f1c0 [file] [log] [blame]
Geoffrey Martin-Noble93c50892022-08-08 18:32:33 -07001#!/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-Noble971cd4b2022-11-29 14:02:31 -08009# Cross-compile the runtime using CMake targeting Android
Geoffrey Martin-Noble93c50892022-08-08 18:32:33 -070010#
Scott Todda92999e2023-01-13 10:13:12 -080011# The required IREE_HOST_BIN_DIR environment variable indicates the location
Jerry Wue4e23982023-04-19 18:16:03 +000012# 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-Noble971cd4b2022-11-29 14:02:31 -080016#
17# The desired build directory can be passed as the first argument. Otherwise, it
Jerry Wu85ff57f2022-12-12 21:39:26 +000018# uses the environment variable IREE_TARGET_BUILD_DIR, defaulting to
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -080019# "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 Wue4e23982023-04-19 18:16:03 +000022#
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-Noble971cd4b2022-11-29 14:02:31 -080026
Geoffrey Martin-Noble93c50892022-08-08 18:32:33 -070027
28set -xeuo pipefail
29
Jerry Wu85ff57f2022-12-12 21:39:26 +000030BUILD_DIR="${1:-${IREE_TARGET_BUILD_DIR:-build-android}}"
Jerry Wue4e23982023-04-19 18:16:03 +000031ANDROID_ABI="${IREE_ANDROID_ABI:-arm64-v8a}"
Scott Todda92999e2023-01-13 10:13:12 -080032IREE_HOST_BIN_DIR="$(realpath ${IREE_HOST_BIN_DIR})"
Jerry Wu94841422022-12-01 21:14:50 +000033E2E_TEST_ARTIFACTS_DIR="${E2E_TEST_ARTIFACTS_DIR:-build-e2e-test-artifacts/e2e_test_artifacts}"
CindyLiub593bbd2022-10-17 22:03:34 -070034BUILD_PRESET="${BUILD_PRESET:-test}"
Geoffrey Martin-Noble93c50892022-08-08 18:32:33 -070035
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -080036source build_tools/cmake/setup_build.sh
Geoffrey Martin-Noble46e47e32022-11-29 16:39:45 -080037source build_tools/cmake/setup_ccache.sh
Geoffrey Martin-Noble93c50892022-08-08 18:32:33 -070038
39declare -a args=(
40 -G Ninja
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -080041 -B "${BUILD_DIR}"
Jerry Wu56d65bf2023-01-04 20:44:09 -050042 -DPython3_EXECUTABLE="${IREE_PYTHON3_EXECUTABLE}"
43 -DPYTHON_EXECUTABLE="${IREE_PYTHON3_EXECUTABLE}"
Geoffrey Martin-Noble93c50892022-08-08 18:32:33 -070044 -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake"
45 -DANDROID_ABI="${ANDROID_ABI}"
46 -DANDROID_PLATFORM=android-29
Scott Todda92999e2023-01-13 10:13:12 -080047 -DIREE_HOST_BIN_DIR="${IREE_HOST_BIN_DIR}"
Geoffrey Martin-Noble93c50892022-08-08 18:32:33 -070048 -DIREE_BUILD_COMPILER=OFF
49 -DIREE_BUILD_TESTS=ON
50 -DIREE_BUILD_SAMPLES=OFF
51)
52
CindyLiub593bbd2022-10-17 22:03:34 -070053case "${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 Wu94841422022-12-01 21:14:50 +000073 E2E_TEST_ARTIFACTS_DIR="$(realpath ${E2E_TEST_ARTIFACTS_DIR})"
CindyLiub593bbd2022-10-17 22:03:34 -070074 args+=(
75 -DIREE_ENABLE_ASSERTIONS=ON
Jerry Wu94841422022-12-01 21:14:50 +000076 -DIREE_E2E_TEST_ARTIFACTS_DIR="${E2E_TEST_ARTIFACTS_DIR}"
CindyLiub593bbd2022-10-17 22:03:34 -070077 )
78 ;;
79 *)
80 echo "Unknown build preset: ${BUILD_PRESET}"
81 exit 1
82 ;;
83esac
84
Geoffrey Martin-Noble93c50892022-08-08 18:32:33 -070085# Configure towards 64-bit Android 10, then build.
86"${CMAKE_BIN}" "${args[@]}"
87
88
89echo "Building all for device"
90echo "------------"
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -080091"${CMAKE_BIN}" --build "${BUILD_DIR}" -- -k 0
Geoffrey Martin-Noble93c50892022-08-08 18:32:33 -070092
93echo "Building test deps for device"
94echo "------------------"
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -080095"${CMAKE_BIN}" --build "${BUILD_DIR}" --target iree-test-deps -- -k 0
Geoffrey Martin-Noble46e47e32022-11-29 16:39:45 -080096
Scott Toddfb16d602023-01-23 11:48:32 -080097if (( IREE_USE_CCACHE == 1 )); then
Geoffrey Martin-Noble46e47e32022-11-29 16:39:45 -080098 ccache --show-stats
99fi