blob: 96907073fefc7a24e1a57e85d108f8f10ce710ab [file] [log] [blame]
#!/bin/bash
# Copyright 2022 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# Cross-compile the IREE project towards Android with CMake. Designed for CI,
# but can be run manually.
#
# Requires pre-compiled IREE and TF integrations host tools. Also requires that
# ANDROID_ABI and ANDROID_NDK variables be set
set -xeuo pipefail
ROOT_DIR="${ROOT_DIR:-$(git rev-parse --show-toplevel)}"
cd "${ROOT_DIR}"
CMAKE_BIN="${CMAKE_BIN:-$(which cmake)}"
IREE_HOST_BINARY_ROOT="$(realpath ${IREE_HOST_BINARY_ROOT})"
BUILD_ANDROID_DIR="${BUILD_ANDROID_DIR:-$ROOT_DIR/build-android}"
if [[ -d "${BUILD_ANDROID_DIR}" ]]; then
echo "${BUILD_ANDROID_DIR} directory already exists. Will use cached results there."
else
echo "${BUILD_ANDROID_DIR} directory does not already exist. Creating a new one."
mkdir "${BUILD_ANDROID_DIR}"
fi
declare -a args=(
-G Ninja
-B "${BUILD_ANDROID_DIR}"
-DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake"
-DANDROID_ABI="${ANDROID_ABI}"
-DANDROID_PLATFORM=android-29
-DIREE_HOST_BINARY_ROOT="${IREE_HOST_BINARY_ROOT}"
-DIREE_ENABLE_ASSERTIONS=ON
-DIREE_BUILD_COMPILER=OFF
-DIREE_BUILD_TESTS=ON
-DIREE_BUILD_SAMPLES=OFF
)
# Configure towards 64-bit Android 10, then build.
"${CMAKE_BIN}" "${args[@]}"
echo "Building all for device"
echo "------------"
"${CMAKE_BIN}" --build "${BUILD_ANDROID_DIR}" -- -k 0
echo "Building test deps for device"
echo "------------------"
"${CMAKE_BIN}" --build "${BUILD_ANDROID_DIR}" --target iree-test-deps -- -k 0