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 8# Builds example_runner and prints its path. 9 10set -euo pipefail 11 12SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" 13readonly SCRIPT_DIR 14 15readonly EXECUTORCH_ROOT="${SCRIPT_DIR}/../.." 16 17# Allow overriding the number of build jobs. Default to 9. 18export CMAKE_BUILD_PARALLEL_LEVEL="${CMAKE_BUILD_PARALLEL_LEVEL:-9}" 19 20BUILD_COREML=OFF 21 22usage() { 23 echo "Builds example runner." 24 echo "Options:" 25 echo " --coreml Include this flag to enable Core ML backend when building the Developer Tools." 26 exit 0 27} 28 29for arg in "$@"; do 30 case $arg in 31 -h|--help) usage ;; 32 --coreml) BUILD_COREML=ON ;; 33 *) 34 esac 35done 36 37main() { 38 cd "${EXECUTORCH_ROOT}" 39 40 rm -rf cmake-out 41 42 if [[ "${BUILD_COREML}" == "ON" ]]; then 43 cmake -DCMAKE_INSTALL_PREFIX=cmake-out \ 44 -DCMAKE_BUILD_TYPE=Release \ 45 -DEXECUTORCH_BUILD_DEVTOOLS=ON \ 46 -DEXECUTORCH_ENABLE_EVENT_TRACER=ON \ 47 -DEXECUTORCH_BUILD_COREML=ON \ 48 -Dprotobuf_BUILD_TESTS=OFF \ 49 -Dprotobuf_BUILD_EXAMPLES=OFF \ 50 -DEXECUTORCH_ENABLE_LOGGING=ON \ 51 -Bcmake-out . 52 else 53 cmake -DCMAKE_INSTALL_PREFIX=cmake-out \ 54 -DCMAKE_BUILD_TYPE=Release \ 55 -DEXECUTORCH_BUILD_DEVTOOLS=ON \ 56 -DEXECUTORCH_ENABLE_EVENT_TRACER=ON \ 57 -Bcmake-out . 58 fi 59 60 cmake --build cmake-out --target install --config Release 61 62 local example_dir=examples/devtools 63 local build_dir="cmake-out/${example_dir}" 64 local cmake_prefix_path="${PWD}/cmake-out/lib/cmake/ExecuTorch;${PWD}/cmake-out/third-party/gflags" 65 rm -rf ${build_dir} 66 cmake -DCMAKE_PREFIX_PATH="${cmake_prefix_path}" \ 67 -DCMAKE_BUILD_TYPE=Release \ 68 -DEXECUTORCH_BUILD_COREML=$BUILD_COREML \ 69 -B"${build_dir}" \ 70 "${example_dir}" 71 cmake --build "${build_dir}" --config Release 72 73 local runner="${PWD}/${build_dir}/example_runner" 74 if [[ ! -f "${runner}" ]]; then 75 echo "ERROR: Failed to build ${build_dir}/example_runner" >&2 76 exit 1 77 else 78 echo "Built ${build_dir}/example_runner" 79 fi 80} 81 82main "$@" 83