blob: d3f49780d8deefe0887d3fcf87135c415dc8ba8b [file] [log] [blame]
CindyLiud1384dc2021-05-07 03:53:23 +00001#!/bin/bash
2
Geoffrey Martin-Noble552d3f82021-05-25 17:56:09 -07003# Copyright 2021 The IREE Authors
CindyLiud1384dc2021-05-07 03:53:23 +00004#
Geoffrey Martin-Noble552d3f82021-05-25 17:56:09 -07005# 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
CindyLiud1384dc2021-05-07 03:53:23 +00008
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -08009# Cross-compile the runtime using CMake targeting RISC-V
CindyLiud1384dc2021-05-07 03:53:23 +000010#
Scott Todda92999e2023-01-13 10:13:12 -080011# The required IREE_HOST_BIN_DIR environment variable indicates the location
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -080012# of the precompiled IREE binaries. The BUILD_PRESET environment variable
13# indicates how the project should be configured: "test", "benchmark",
14# "benchmark-with-tracing", or "benchmark-suite-test". Defaults to "test".
Jerry Wu2b226442022-09-01 09:13:24 -070015#
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -080016# The desired build directory can be passed as the first argument. Otherwise, it
Jerry Wu85ff57f2022-12-12 21:39:26 +000017# uses the environment variable IREE_TARGET_BUILD_DIR, defaulting to
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -080018# "build-riscv". Designed for CI, but can be run manually. It reuses the build
19# directory if it already exists. Expects to be run from the root of the IREE
20# repository.
CindyLiud1384dc2021-05-07 03:53:23 +000021
Geoffrey Martin-Noble53f31d12022-07-20 15:53:34 -070022set -xeuo pipefail
CindyLiud1384dc2021-05-07 03:53:23 +000023
Jerry Wu85ff57f2022-12-12 21:39:26 +000024BUILD_DIR="${1:-${IREE_TARGET_BUILD_DIR:-build-riscv}}"
Diego Caballero431ef022023-02-17 09:54:11 -080025BUILD_TYPE="${IREE_BUILD_TYPE:-RelWithDebInfo}"
Jerry Wu85ff57f2022-12-12 21:39:26 +000026RISCV_PLATFORM="${IREE_TARGET_PLATFORM:-linux}"
27RISCV_ARCH="${IREE_TARGET_ARCH:-riscv_64}"
Cindy Liu49b844a2022-06-16 13:56:19 -070028RISCV_COMPILER_FLAGS="${RISCV_COMPILER_FLAGS:--O3}"
Scott Todda92999e2023-01-13 10:13:12 -080029IREE_HOST_BIN_DIR="$(realpath ${IREE_HOST_BIN_DIR})"
Jerry Wu94841422022-12-01 21:14:50 +000030E2E_TEST_ARTIFACTS_DIR="${E2E_TEST_ARTIFACTS_DIR:-build-e2e-test-artifacts/e2e_test_artifacts}"
Jerry Wu2b226442022-09-01 09:13:24 -070031BUILD_PRESET="${BUILD_PRESET:-test}"
CindyLiud1384dc2021-05-07 03:53:23 +000032
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -080033source build_tools/cmake/setup_build.sh
CindyLiud1384dc2021-05-07 03:53:23 +000034
Jerry Wu85ff57f2022-12-12 21:39:26 +000035RISCV_PLATFORM_ARCH="${RISCV_PLATFORM}-${RISCV_ARCH}"
36echo "Build riscv target with the config of ${RISCV_PLATFORM_ARCH}"
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -080037TOOLCHAIN_FILE="$(realpath build_tools/cmake/riscv.toolchain.cmake)"
CindyLiu134edde2021-06-30 01:59:52 +000038declare -a args
39args=(
40 "-G" "Ninja"
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -080041 "-B" "${BUILD_DIR}"
Diego Caballero431ef022023-02-17 09:54:11 -080042 "-DCMAKE_BUILD_TYPE=${BUILD_TYPE}"
Jerry Wu56d65bf2023-01-04 20:44:09 -050043 "-DPython3_EXECUTABLE=${IREE_PYTHON3_EXECUTABLE}"
44 "-DPYTHON_EXECUTABLE=${IREE_PYTHON3_EXECUTABLE}"
45 "-DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN_FILE}"
Scott Todda92999e2023-01-13 10:13:12 -080046 "-DIREE_HOST_BIN_DIR=${IREE_HOST_BIN_DIR}"
Jerry Wu56d65bf2023-01-04 20:44:09 -050047 "-DRISCV_CPU=${RISCV_PLATFORM_ARCH}"
48 "-DRISCV_COMPILER_FLAGS=${RISCV_COMPILER_FLAGS}"
49 "-DIREE_BUILD_COMPILER=OFF"
Geoffrey Martin-Noblee3841872022-08-01 19:19:02 -070050 # CPU info doesn't work on RISCV
Jerry Wu56d65bf2023-01-04 20:44:09 -050051 "-DIREE_ENABLE_CPUINFO=OFF"
CindyLiu134edde2021-06-30 01:59:52 +000052)
53
Jerry Wu85ff57f2022-12-12 21:39:26 +000054if [[ "${RISCV_PLATFORM}" == "linux" ]]; then
CindyLiu134edde2021-06-30 01:59:52 +000055 args+=(
Geoffrey Martin-Noble53f31d12022-07-20 15:53:34 -070056 -DRISCV_TOOLCHAIN_ROOT="${RISCV_RV64_LINUX_TOOLCHAIN_ROOT}"
CindyLiu134edde2021-06-30 01:59:52 +000057 )
Jerry Wu85ff57f2022-12-12 21:39:26 +000058elif [[ "${RISCV_PLATFORM_ARCH}" == "generic-riscv_32" ]]; then
CindyLiu134edde2021-06-30 01:59:52 +000059 args+=(
Scott Toddf57ab752022-05-23 10:36:44 -070060 # TODO(#6353): Off until tools/ are refactored to support threadless config.
CindyLiu134edde2021-06-30 01:59:52 +000061 -DIREE_BUILD_TESTS=OFF
Geoffrey Martin-Noble53f31d12022-07-20 15:53:34 -070062 -DRISCV_TOOLCHAIN_ROOT="${RISCV_RV32_NEWLIB_TOOLCHAIN_ROOT}"
CindyLiu134edde2021-06-30 01:59:52 +000063 )
64else
Jerry Wu85ff57f2022-12-12 21:39:26 +000065 echo "riscv config for ${RISCV_PLATFORM_ARCH} not supported yet"
CindyLiu134edde2021-06-30 01:59:52 +000066 return -1
67fi
68
Jerry Wu2b226442022-09-01 09:13:24 -070069case "${BUILD_PRESET}" in
70 test)
71 args+=(
72 -DIREE_ENABLE_ASSERTIONS=ON
73 -DIREE_BUILD_SAMPLES=ON
74 )
75 ;;
76 benchmark)
77 args+=(
78 -DIREE_ENABLE_ASSERTIONS=OFF
79 -DIREE_BUILD_SAMPLES=OFF
80 -DIREE_BUILD_TESTS=OFF
81 )
82 ;;
83 benchmark-with-tracing)
84 args+=(
85 -DIREE_ENABLE_ASSERTIONS=OFF
86 -DIREE_BUILD_SAMPLES=OFF
87 -DIREE_BUILD_TESTS=OFF
88 -DIREE_ENABLE_RUNTIME_TRACING=ON
89 )
90 ;;
CindyLiu3e100f72022-10-06 09:24:49 -070091 benchmark-suite-test)
Jerry Wu94841422022-12-01 21:14:50 +000092 E2E_TEST_ARTIFACTS_DIR="$(realpath ${E2E_TEST_ARTIFACTS_DIR})"
CindyLiu3e100f72022-10-06 09:24:49 -070093 args+=(
Jerry Wu94841422022-12-01 21:14:50 +000094 -DIREE_E2E_TEST_ARTIFACTS_DIR="${E2E_TEST_ARTIFACTS_DIR}"
CindyLiu3e100f72022-10-06 09:24:49 -070095 )
96 ;;
Jerry Wu2b226442022-09-01 09:13:24 -070097 *)
98 echo "Unknown build preset: ${BUILD_PRESET}"
99 exit 1
100 ;;
101esac
102
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -0800103"${CMAKE_BIN}" "${args[@]}"
CindyLiud3d4ed02022-09-08 10:32:18 -0700104
Jerry Wu85ff57f2022-12-12 21:39:26 +0000105if [[ "${BUILD_PRESET}" == "benchmark-suite-test" ]]; then
106 if [[ "${RISCV_PLATFORM}" == "linux" ]]; then
107 echo "Building iree-run-module and run-module-test deps for RISC-V"
108 echo "------------------------------------------------------------"
109 "${CMAKE_BIN}" --build "${BUILD_DIR}" --target iree-run-module \
110 iree-run-module-test-deps -- -k 0
111 else
112 echo "benchmark-suite-test on ${RISCV_PLATFORM_ARCH} not supported yet"
113 return -1
114 fi
CindyLiu99373e02022-10-12 09:22:24 -0700115else
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -0800116 "${CMAKE_BIN}" --build "${BUILD_DIR}" -- -k 0
Jerry Wu85ff57f2022-12-12 21:39:26 +0000117 if [[ "${RISCV_PLATFORM}" == "linux" ]]; then
CindyLiu99373e02022-10-12 09:22:24 -0700118 echo "Building test deps for RISC-V"
119 echo "-----------------------------"
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -0800120 "${CMAKE_BIN}" --build "${BUILD_DIR}" --target iree-test-deps -- -k 0
CindyLiu99373e02022-10-12 09:22:24 -0700121 fi
CindyLiud3d4ed02022-09-08 10:32:18 -0700122fi