xref: /aosp_15_r20/external/executorch/backends/cadence/build_cadence_xtensa.sh (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1#!/bin/bash
2# Copyright (c) Meta Platforms, Inc. and affiliates.
3# All rights reserved.
4#
5# This source code is licensed under the BSD-style license found in the
6# LICENSE file in the root directory of this source tree.
7
8set -euo pipefail
9
10unset CMAKE_PREFIX_PATH
11git submodule sync
12git submodule update --init
13./install_requirements.sh
14
15rm -rf cmake-out
16
17STEPWISE_BUILD=false
18
19if $STEPWISE_BUILD; then
20    echo "Building ExecuTorch"
21    cmake -DCMAKE_INSTALL_PREFIX=cmake-out \
22        -DCMAKE_TOOLCHAIN_FILE=./backends/cadence/cadence.cmake  \
23        -DCMAKE_BUILD_TYPE=Release \
24        -DEXECUTORCH_ENABLE_EVENT_TRACER=OFF \
25        -DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \
26        -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=OFF \
27        -DEXECUTORCH_BUILD_PTHREADPOOL=OFF \
28        -DEXECUTORCH_BUILD_CPUINFO=OFF \
29        -DEXECUTORCH_ENABLE_LOGGING=ON \
30        -DEXECUTORCH_USE_DL=OFF \
31        -DEXECUTORCH_BUILD_CADENCE=OFF \
32        -DFLATC_EXECUTABLE="$(which flatc)" \
33        -Bcmake-out .
34
35    echo "Building any Cadence-specific binaries on top"
36    cmake -DBUCK2="$BUCK" \
37        -DCMAKE_TOOLCHAIN_FILE=./backends/cadence/cadence.cmake \
38        -DCMAKE_INSTALL_PREFIX=cmake-out \
39        -DCMAKE_BUILD_TYPE=Release \
40        -DEXECUTORCH_BUILD_HOST_TARGETS=ON \
41        -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON \
42        -DEXECUTORCH_BUILD_PTHREADPOOL=OFF \
43        -DEXECUTORCH_BUILD_CADENCE=ON \
44        -DFLATC_EXECUTABLE="$(which flatc)" \
45        -DEXECUTORCH_ENABLE_LOGGING=ON \
46        -DEXECUTORCH_ENABLE_PROGRAM_VERIFICATION=ON \
47        -DEXECUTORCH_USE_DL=OFF \
48        -DBUILD_EXECUTORCH_PORTABLE_OPS=ON \
49        -DEXECUTORCH_BUILD_KERNELS_CUSTOM=OFF \
50        -DPYTHON_EXECUTABLE=python3 \
51        -DEXECUTORCH_NNLIB_OPT=ON \
52        -DEXECUTORCH_BUILD_GFLAGS=ON \
53        -DHAVE_FNMATCH_H=OFF \
54        -Bcmake-out/backends/cadence \
55        backends/cadence
56    cmake --build cmake-out/backends/cadence  -j16
57else
58    echo "Building Cadence toolchain with ExecuTorch packages"
59    cmake_prefix_path="${PWD}/cmake-out/lib/cmake/ExecuTorch;${PWD}/cmake-out/third-party/gflags"
60    cmake -DBUCK2="$BUCK" \
61        -DCMAKE_PREFIX_PATH="${cmake_prefix_path}" \
62        -DCMAKE_TOOLCHAIN_FILE=./backends/cadence/cadence.cmake \
63        -DCMAKE_INSTALL_PREFIX=cmake-out \
64        -DCMAKE_BUILD_TYPE=Release \
65        -DEXECUTORCH_BUILD_HOST_TARGETS=ON \
66        -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON \
67        -DEXECUTORCH_BUILD_PTHREADPOOL=OFF \
68        -DEXECUTORCH_BUILD_CPUINFO=OFF \
69        -DEXECUTORCH_BUILD_FLATC=OFF \
70        -DEXECUTORCH_BUILD_CADENCE=ON \
71        -DFLATC_EXECUTABLE="$(which flatc)" \
72        -DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \
73        -DEXECUTORCH_ENABLE_LOGGING=ON \
74        -DEXECUTORCH_ENABLE_PROGRAM_VERIFICATION=ON \
75        -DEXECUTORCH_USE_DL=OFF \
76        -DBUILD_EXECUTORCH_PORTABLE_OPS=ON \
77        -DEXECUTORCH_BUILD_KERNELS_CUSTOM=OFF \
78        -DPYTHON_EXECUTABLE=python3 \
79        -DEXECUTORCH_NNLIB_OPT=ON \
80        -DHAVE_FNMATCH_H=OFF \
81        -Bcmake-out
82    cmake --build cmake-out --target install --config Release -j16
83fi
84
85echo "Run simple model to verify cmake build"
86python3 -m examples.portable.scripts.export --model_name="add"
87xt-run --turbo cmake-out/executor_runner  --model_path=add.pte
88