blob: faab63c8dface1c0d2c5a217eb6a806740f237a4 [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}}"
25RISCV_PLATFORM="${IREE_TARGET_PLATFORM:-linux}"
26RISCV_ARCH="${IREE_TARGET_ARCH:-riscv_64}"
Cindy Liu49b844a2022-06-16 13:56:19 -070027RISCV_COMPILER_FLAGS="${RISCV_COMPILER_FLAGS:--O3}"
Scott Todda92999e2023-01-13 10:13:12 -080028IREE_HOST_BIN_DIR="$(realpath ${IREE_HOST_BIN_DIR})"
Jerry Wu94841422022-12-01 21:14:50 +000029E2E_TEST_ARTIFACTS_DIR="${E2E_TEST_ARTIFACTS_DIR:-build-e2e-test-artifacts/e2e_test_artifacts}"
Jerry Wu2b226442022-09-01 09:13:24 -070030BUILD_PRESET="${BUILD_PRESET:-test}"
CindyLiud1384dc2021-05-07 03:53:23 +000031
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -080032source build_tools/cmake/setup_build.sh
CindyLiud1384dc2021-05-07 03:53:23 +000033
Jerry Wu85ff57f2022-12-12 21:39:26 +000034RISCV_PLATFORM_ARCH="${RISCV_PLATFORM}-${RISCV_ARCH}"
35echo "Build riscv target with the config of ${RISCV_PLATFORM_ARCH}"
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -080036TOOLCHAIN_FILE="$(realpath build_tools/cmake/riscv.toolchain.cmake)"
CindyLiu134edde2021-06-30 01:59:52 +000037declare -a args
38args=(
39 "-G" "Ninja"
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -080040 "-B" "${BUILD_DIR}"
Jerry Wu56d65bf2023-01-04 20:44:09 -050041 "-DPython3_EXECUTABLE=${IREE_PYTHON3_EXECUTABLE}"
42 "-DPYTHON_EXECUTABLE=${IREE_PYTHON3_EXECUTABLE}"
43 "-DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN_FILE}"
Scott Todda92999e2023-01-13 10:13:12 -080044 "-DIREE_HOST_BIN_DIR=${IREE_HOST_BIN_DIR}"
Jerry Wu56d65bf2023-01-04 20:44:09 -050045 "-DRISCV_CPU=${RISCV_PLATFORM_ARCH}"
46 "-DRISCV_COMPILER_FLAGS=${RISCV_COMPILER_FLAGS}"
47 "-DIREE_BUILD_COMPILER=OFF"
Geoffrey Martin-Noblee3841872022-08-01 19:19:02 -070048 # CPU info doesn't work on RISCV
Jerry Wu56d65bf2023-01-04 20:44:09 -050049 "-DIREE_ENABLE_CPUINFO=OFF"
CindyLiu134edde2021-06-30 01:59:52 +000050)
51
Jerry Wu85ff57f2022-12-12 21:39:26 +000052if [[ "${RISCV_PLATFORM}" == "linux" ]]; then
CindyLiu134edde2021-06-30 01:59:52 +000053 args+=(
Geoffrey Martin-Noble53f31d12022-07-20 15:53:34 -070054 -DRISCV_TOOLCHAIN_ROOT="${RISCV_RV64_LINUX_TOOLCHAIN_ROOT}"
CindyLiu134edde2021-06-30 01:59:52 +000055 )
Jerry Wu85ff57f2022-12-12 21:39:26 +000056elif [[ "${RISCV_PLATFORM_ARCH}" == "generic-riscv_32" ]]; then
CindyLiu134edde2021-06-30 01:59:52 +000057 args+=(
Scott Toddf57ab752022-05-23 10:36:44 -070058 # TODO(#6353): Off until tools/ are refactored to support threadless config.
CindyLiu134edde2021-06-30 01:59:52 +000059 -DIREE_BUILD_TESTS=OFF
Geoffrey Martin-Noble53f31d12022-07-20 15:53:34 -070060 -DRISCV_TOOLCHAIN_ROOT="${RISCV_RV32_NEWLIB_TOOLCHAIN_ROOT}"
CindyLiu134edde2021-06-30 01:59:52 +000061 )
62else
Jerry Wu85ff57f2022-12-12 21:39:26 +000063 echo "riscv config for ${RISCV_PLATFORM_ARCH} not supported yet"
CindyLiu134edde2021-06-30 01:59:52 +000064 return -1
65fi
66
Jerry Wu2b226442022-09-01 09:13:24 -070067case "${BUILD_PRESET}" in
68 test)
69 args+=(
70 -DIREE_ENABLE_ASSERTIONS=ON
71 -DIREE_BUILD_SAMPLES=ON
72 )
73 ;;
74 benchmark)
75 args+=(
76 -DIREE_ENABLE_ASSERTIONS=OFF
77 -DIREE_BUILD_SAMPLES=OFF
78 -DIREE_BUILD_TESTS=OFF
79 )
80 ;;
81 benchmark-with-tracing)
82 args+=(
83 -DIREE_ENABLE_ASSERTIONS=OFF
84 -DIREE_BUILD_SAMPLES=OFF
85 -DIREE_BUILD_TESTS=OFF
86 -DIREE_ENABLE_RUNTIME_TRACING=ON
87 )
88 ;;
CindyLiu3e100f72022-10-06 09:24:49 -070089 benchmark-suite-test)
Jerry Wu94841422022-12-01 21:14:50 +000090 E2E_TEST_ARTIFACTS_DIR="$(realpath ${E2E_TEST_ARTIFACTS_DIR})"
CindyLiu3e100f72022-10-06 09:24:49 -070091 args+=(
Jerry Wu94841422022-12-01 21:14:50 +000092 -DIREE_E2E_TEST_ARTIFACTS_DIR="${E2E_TEST_ARTIFACTS_DIR}"
CindyLiu3e100f72022-10-06 09:24:49 -070093 )
94 ;;
Jerry Wu2b226442022-09-01 09:13:24 -070095 *)
96 echo "Unknown build preset: ${BUILD_PRESET}"
97 exit 1
98 ;;
99esac
100
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -0800101"${CMAKE_BIN}" "${args[@]}"
CindyLiud3d4ed02022-09-08 10:32:18 -0700102
Jerry Wu85ff57f2022-12-12 21:39:26 +0000103if [[ "${BUILD_PRESET}" == "benchmark-suite-test" ]]; then
104 if [[ "${RISCV_PLATFORM}" == "linux" ]]; then
105 echo "Building iree-run-module and run-module-test deps for RISC-V"
106 echo "------------------------------------------------------------"
107 "${CMAKE_BIN}" --build "${BUILD_DIR}" --target iree-run-module \
108 iree-run-module-test-deps -- -k 0
109 else
110 echo "benchmark-suite-test on ${RISCV_PLATFORM_ARCH} not supported yet"
111 return -1
112 fi
CindyLiu99373e02022-10-12 09:22:24 -0700113else
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -0800114 "${CMAKE_BIN}" --build "${BUILD_DIR}" -- -k 0
Jerry Wu85ff57f2022-12-12 21:39:26 +0000115 if [[ "${RISCV_PLATFORM}" == "linux" ]]; then
CindyLiu99373e02022-10-12 09:22:24 -0700116 echo "Building test deps for RISC-V"
117 echo "-----------------------------"
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -0800118 "${CMAKE_BIN}" --build "${BUILD_DIR}" --target iree-test-deps -- -k 0
Ben Vanikb4bf5f72022-12-05 19:28:57 -0800119 echo "Building sample deps for RISC-V"
120 echo "------------------"
121 "${CMAKE_BIN}" --build "${BUILD_DIR}" --target iree-sample-deps -- -k 0
CindyLiu99373e02022-10-12 09:22:24 -0700122 fi
CindyLiud3d4ed02022-09-08 10:32:18 -0700123fi