diff --git a/.ci/scripts/build_llama_android.sh b/.ci/scripts/build_llama_android.sh index 18c22baf9c7..2460f5483d9 100644 --- a/.ci/scripts/build_llama_android.sh +++ b/.ci/scripts/build_llama_android.sh @@ -60,6 +60,5 @@ build_llama_runner() { cmake --build cmake-android-out/examples/models/llama -j4 --config Release } -install_flatc_from_source install_executorch_and_backend_lib build_llama_runner diff --git a/.ci/scripts/utils.sh b/.ci/scripts/utils.sh index c710196d896..9c8a3f94f96 100644 --- a/.ci/scripts/utils.sh +++ b/.ci/scripts/utils.sh @@ -80,25 +80,6 @@ install_pytorch_and_domains() { sccache --show-stats || true } -install_flatc_from_source() { - # NB: This function could be used to install flatbuffer from source - pushd third-party/flatbuffers || return - - cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release - if [ "$(uname)" == "Darwin" ]; then - CMAKE_JOBS=$(( $(sysctl -n hw.ncpu) - 1 )) - else - CMAKE_JOBS=$(( $(nproc) - 1 )) - fi - cmake --build . -j "${CMAKE_JOBS}" - - # Copy the flatc binary to conda path - EXEC_PATH=$(dirname "$(which python)") - cp flatc "${EXEC_PATH}" - - popd || return -} - build_executorch_runner_buck2() { # Build executorch runtime with retry as this step is flaky on macos CI retry buck2 build //examples/portable/executor_runner:executor_runner diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a53b8a6e2a..6509d4adeef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -460,7 +460,7 @@ endif() # tools like `flatc`, along with example executables like `executor_runner` and # libraries that it uses, like `gflags`. Disabling this can be helpful when # cross-compiling, but some required tools that would have been built need to be -# provided directly (via, for example, FLATC_EXECUTABLE). +# provided directly. cmake_dependent_option( EXECUTORCH_BUILD_HOST_TARGETS "Build host-only targets." ON "NOT CMAKE_TOOLCHAIN_IOS" OFF @@ -471,10 +471,9 @@ cmake_dependent_option( # cmake_dependent_option( EXECUTORCH_BUILD_FLATC "Build the flatc executable." ON - "NOT FLATC_EXECUTABLE;EXECUTORCH_BUILD_HOST_TARGETS" OFF + "NOT FLATC_EXECUTABLE" OFF ) - set(FLATBUFFERS_BUILD_FLATC OFF CACHE BOOL "") set(FLATBUFFERS_BUILD_FLATHASH OFF CACHE BOOL "") set(FLATBUFFERS_BUILD_FLATLIB OFF CACHE BOOL "") @@ -507,6 +506,8 @@ if(EXECUTORCH_BUILD_FLATC) -DFLATBUFFERS_BUILD_TESTS=${FLATBUFFERS_BUILD_TESTS} -DFLATBUFFERS_INSTALL=${FLATBUFFERS_INSTALL} -DCMAKE_CXX_FLAGS="-DFLATBUFFERS_MAX_ALIGNMENT=${FLATBUFFERS_MAX_ALIGNMENT}" + # If building for iOS, "unset" these variables to rely on the host (macOS) defaults. + $<$,$>>:-DCMAKE_OSX_SYSROOT=> INSTALL_COMMAND "" BUILD_BYPRODUCTS /flatc ) @@ -515,6 +516,8 @@ if(EXECUTORCH_BUILD_FLATC) # flatbuffers does not use CMAKE_BUILD_TYPE. Internally, the build forces Release # config, but from CMake's perspective the build type is always Debug. set(FLATC_EXECUTABLE ${BINARY_DIR}/$/flatc.exe) + elseif(CMAKE_GENERATOR STREQUAL "Xcode") + set(FLATC_EXECUTABLE ${BINARY_DIR}/$/flatc) else() set(FLATC_EXECUTABLE ${BINARY_DIR}/flatc) endif() @@ -528,12 +531,7 @@ if(NOT FLATC_EXECUTABLE) find_program(FLATC_EXECUTABLE flatc) if(NOT FLATC_EXECUTABLE) - message( - FATAL_ERROR - "FLATC_EXECUTABLE must be set when EXECUTORCH_BUILD_FLATC is disabled. " - "Note that EXECUTORCH_BUILD_FLATC may be disabled implicitly when " - "cross-compiling or when EXECUTORCH_BUILD_HOST_TARGETS is disabled." - ) + message(FATAL_ERROR "FLATC_EXECUTABLE must be set when EXECUTORCH_BUILD_FLATC is disabled.") endif() endif() diff --git a/backends/apple/coreml/scripts/build_tests.sh b/backends/apple/coreml/scripts/build_tests.sh index 5fbde6ac66f..890385d5e24 100755 --- a/backends/apple/coreml/scripts/build_tests.sh +++ b/backends/apple/coreml/scripts/build_tests.sh @@ -32,7 +32,6 @@ cmake "$EXECUTORCH_ROOT_PATH" -B"$CMAKE_EXECUTORCH_BUILD_DIR_PATH" \ -DCMAKE_TOOLCHAIN_FILE="$IOS_TOOLCHAIN_PATH" \ -DPLATFORM=MAC_UNIVERSAL \ -DDEPLOYMENT_TARGET=13.0 \ --DFLATC_EXECUTABLE="$(which flatc)" \ -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=OFF \ -DEXECUTORCH_BUILD_XNNPACK=OFF \ -DEXECUTORCH_BUILD_GFLAGS=OFF diff --git a/backends/arm/scripts/build_executorch.sh b/backends/arm/scripts/build_executorch.sh index 3096a3975af..f3359e10787 100755 --- a/backends/arm/scripts/build_executorch.sh +++ b/backends/arm/scripts/build_executorch.sh @@ -84,7 +84,6 @@ if [ "$build_with_etdump" = true ] ; then -DEXECUTORCH_ENABLE_EVENT_TRACER=ON \ -DEXECUTORCH_SEPARATE_FLATCC_HOST_PROJECT=ON \ -DFLATCC_ALLOW_WERROR=OFF \ - -DFLATC_EXECUTABLE="$(which flatc)" \ -B"${et_build_host_dir}" \ "${et_root_dir}" @@ -133,7 +132,6 @@ cmake \ -DEXECUTORCH_ENABLE_LOGGING=ON \ ${build_devtools_flags} \ ${build_with_etdump_flags} \ - -DFLATC_EXECUTABLE="$(which flatc)" \ -B"${et_build_dir}" \ "${et_root_dir}" diff --git a/backends/cadence/build_cadence_fusionG3.sh b/backends/cadence/build_cadence_fusionG3.sh index b0e1e777065..081226bcd94 100644 --- a/backends/cadence/build_cadence_fusionG3.sh +++ b/backends/cadence/build_cadence_fusionG3.sh @@ -32,7 +32,6 @@ if $STEPWISE_BUILD; then -DEXECUTORCH_ENABLE_LOGGING=ON \ -DEXECUTORCH_USE_DL=OFF \ -DEXECUTORCH_BUILD_CADENCE=OFF \ - -DFLATC_EXECUTABLE="$(which flatc)" \ -DHAVE_FNMATCH_H=OFF \ -Bcmake-out . @@ -45,7 +44,6 @@ if $STEPWISE_BUILD; then -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON \ -DEXECUTORCH_BUILD_PTHREADPOOL=OFF \ -DEXECUTORCH_BUILD_CADENCE=ON \ - -DFLATC_EXECUTABLE="$(which flatc)" \ -DEXECUTORCH_ENABLE_LOGGING=ON \ -DEXECUTORCH_ENABLE_PROGRAM_VERIFICATION=ON \ -DEXECUTORCH_USE_DL=OFF \ @@ -71,9 +69,7 @@ else -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON \ -DEXECUTORCH_BUILD_PTHREADPOOL=OFF \ -DEXECUTORCH_BUILD_CPUINFO=OFF \ - -DEXECUTORCH_BUILD_FLATC=OFF \ -DEXECUTORCH_BUILD_CADENCE=ON \ - -DFLATC_EXECUTABLE="$(which flatc)" \ -DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \ -DEXECUTORCH_ENABLE_LOGGING=ON \ -DEXECUTORCH_ENABLE_PROGRAM_VERIFICATION=ON \ diff --git a/backends/cadence/build_cadence_hifi4.sh b/backends/cadence/build_cadence_hifi4.sh index 50fd5f032ab..ac1e03ba78e 100644 --- a/backends/cadence/build_cadence_hifi4.sh +++ b/backends/cadence/build_cadence_hifi4.sh @@ -32,7 +32,6 @@ if $STEPWISE_BUILD; then -DEXECUTORCH_ENABLE_LOGGING=ON \ -DEXECUTORCH_USE_DL=OFF \ -DEXECUTORCH_BUILD_CADENCE=OFF \ - -DFLATC_EXECUTABLE="$(which flatc)" \ -Bcmake-out . echo "Building any Cadence-specific binaries on top" @@ -44,7 +43,6 @@ if $STEPWISE_BUILD; then -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON \ -DEXECUTORCH_BUILD_PTHREADPOOL=OFF \ -DEXECUTORCH_BUILD_CADENCE=ON \ - -DFLATC_EXECUTABLE="$(which flatc)" \ -DEXECUTORCH_ENABLE_LOGGING=ON \ -DEXECUTORCH_ENABLE_PROGRAM_VERIFICATION=ON \ -DEXECUTORCH_USE_DL=OFF \ @@ -69,9 +67,7 @@ else -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON \ -DEXECUTORCH_BUILD_PTHREADPOOL=OFF \ -DEXECUTORCH_BUILD_CPUINFO=OFF \ - -DEXECUTORCH_BUILD_FLATC=OFF \ -DEXECUTORCH_BUILD_CADENCE=ON \ - -DFLATC_EXECUTABLE="$(which flatc)" \ -DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \ -DEXECUTORCH_ENABLE_LOGGING=ON \ -DEXECUTORCH_ENABLE_PROGRAM_VERIFICATION=ON \ diff --git a/build/build_android_library.sh b/build/build_android_library.sh old mode 100644 new mode 100755 diff --git a/build/build_apple_frameworks.sh b/build/build_apple_frameworks.sh index 9ca55c183a9..858ff477919 100755 --- a/build/build_apple_frameworks.sh +++ b/build/build_apple_frameworks.sh @@ -12,7 +12,6 @@ OUTPUT="cmake-out" MODES=() TOOLCHAIN="" PYTHON=$(which python3) -FLATC=$(which flatc) COREML=OFF CUSTOM=OFF MPS=OFF @@ -83,7 +82,6 @@ usage() { echo " --Release Build Release version." echo " --toolchain=FILE CMake toolchain file. Default: '\$SOURCE_ROOT_DIR/third-party/ios-cmake/ios.toolchain.cmake'" echo " --python=FILE Python executable path. Default: Path of python3 in \$PATH" - echo " --flatc=FILE FlatBuffers Compiler executable path. Default: Path of flatc in \$PATH" echo " --coreml Build the Core ML backend." echo " --custom Build the Custom kernels." echo " --mps Build the Metal Performance Shaders backend." @@ -113,7 +111,6 @@ for arg in "$@"; do ;; --toolchain=*) TOOLCHAIN="${arg#*=}" ;; --python=*) PYTHON="${arg#*=}" ;; - --flatc=*) FLATC="${arg#*=}" ;; --coreml) COREML=ON ;; --custom) CUSTOM=ON ;; --mps) MPS=ON ;; @@ -168,7 +165,6 @@ check_command() { check_command cmake check_command rsync check_command "$PYTHON" -check_command "$FLATC" check_command "$BUCK2" echo "Building libraries" @@ -190,7 +186,6 @@ cmake_build() { -DCMAKE_C_FLAGS="-ffile-prefix-map=$SOURCE_ROOT_DIR=/executorch -fdebug-prefix-map=$SOURCE_ROOT_DIR=/executorch" \ -DCMAKE_CXX_FLAGS="-ffile-prefix-map=$SOURCE_ROOT_DIR=/executorch -fdebug-prefix-map=$SOURCE_ROOT_DIR=/executorch" \ -DPYTHON_EXECUTABLE="$PYTHON" \ - -DFLATC_EXECUTABLE="$FLATC" \ -DEXECUTORCH_BUILD_COREML=$COREML \ -DEXECUTORCH_BUILD_MPS=$MPS \ -DEXECUTORCH_BUILD_XNNPACK=$XNNPACK \ diff --git a/build/install_flatc.sh b/build/install_flatc.sh deleted file mode 100755 index 75b4e418836..00000000000 --- a/build/install_flatc.sh +++ /dev/null @@ -1,99 +0,0 @@ -#!/bin/bash -# Copyright (c) Meta Platforms, Inc. and affiliates. -# All rights reserved. -# -# This source code is licensed under the BSD-style license found in the -# LICENSE file in the root directory of this source tree. - -# This file builds the `flatc` commandline tool from the -# `third-party/flatbuffers` directory and help users install it correctly. - -set -o errexit -set -o nounset -set -o pipefail - -EXECUTORCH_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)" -readonly EXECUTORCH_ROOT - -readonly FLATBUFFERS_PATH="${EXECUTORCH_ROOT}/third-party/flatbuffers" -readonly BUILD_DIR="${FLATBUFFERS_PATH}/cmake-out" -readonly BUILT_FLATC="${BUILD_DIR}/flatc" - -# Must use "echo -e" to expand these escape sequences. -readonly GREEN="\033[0;32m" # GREEN Color -readonly RED="\033[0;31m" # Red Color -readonly NC="\033[0m" # No Color - -# Prints the flatbuffers version of the git submodule. -print_flatbuffers_version(){ - local version_file="${FLATBUFFERS_PATH}/package.json" - local version - # Extract the version from the first line like `"version": "23.5.26",` - # First remove the final double quote, then remove everything - # before the now-final double quote. - version="$( - grep '"version"\s*:' "${version_file}" \ - | head -1 \ - | sed -e 's/"[^"]*$//' \ - | sed -e 's/.*"//' - )" - if [[ ${version} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "${version}" - else - echo "ERROR: Bad version '${version}'; could not find version in ${version_file}" >&2 - exit 1 - fi -} - -main() { - local flatbuffers_version - flatbuffers_version="$(print_flatbuffers_version)" - echo "Version of ${FLATBUFFERS_PATH} is ${flatbuffers_version}" - - local flatc_path - flatc_path="$(which flatc 2>/dev/null || echo '')" - if [[ -f "${flatc_path}" ]]; then - # A flatc is already on the PATH. - if { "${flatc_path}" --version | grep -q "${flatbuffers_version}"; }; then - echo -e "${GREEN}A compatible version of flatc is on the PATH" \ - "and ready to use.${NC}" - return 0 - else - echo -e "${RED}WARNING: An incompatible version of flatc" \ - "is on the PATH at ${flatc_path}." - echo -e " Required version: flatc version ${flatbuffers_version}" - echo -e " Actual version: $("${flatc_path}" --version)${NC}" - - if [[ "${flatc_path}" == *miniconda* ]]; then - echo -e "${RED}ERROR: ${flatc_path} appears to be installed" \ - "with conda, which can cause consistency problems." - echo -e "Please run the following command to remove it: " - echo -e " conda uninstall flatbuffers${NC}" - return 1 - fi - - # Continue to build a compatible version. - fi - fi - - if [[ -f "${BUILT_FLATC}" ]]; then - echo -e "${BUILT_FLATC} is already built." - else - # Build the tool if not already built. - echo "Building flatc under ${FLATBUFFERS_PATH}..." - # Generate cache. - (rm -rf "${BUILD_DIR}" && mkdir "${BUILD_DIR}" && cd "${BUILD_DIR}" && cmake -DCMAKE_BUILD_TYPE=Release ..) - # Build. - (cd "${FLATBUFFERS_PATH}" && cmake --build "${BUILD_DIR}" --target flatc -j9) - - echo -e "Finished building ${BUILT_FLATC}." - fi - - echo -e "" - echo -e "***** Run the following commands to add a compatible flatc"\ - "to the PATH and re-run this script:" - echo -e " ${RED}export PATH=\"${BUILD_DIR}:\${PATH}\"" - echo -e " bash ${EXECUTORCH_ROOT}/build/install_flatc.sh${NC}" -} - -main "$@" diff --git a/build/test_ios.sh b/build/test_ios.sh index cdc02098cee..2619c52ea24 100755 --- a/build/test_ios.sh +++ b/build/test_ios.sh @@ -64,8 +64,6 @@ say "Installing Requirements" pip install --upgrade cmake pip setuptools wheel zstd ./install_executorch.sh --pybind coreml mps xnnpack -export PATH="$(realpath third-party/flatbuffers/cmake-out):$PATH" -./build/install_flatc.sh say "Installing CoreML Backend Requirements" diff --git a/docs/source/backends-cadence.md b/docs/source/backends-cadence.md index 278a2f9ec2b..6dfb097c805 100644 --- a/docs/source/backends-cadence.md +++ b/docs/source/backends-cadence.md @@ -174,8 +174,6 @@ cmake -DCMAKE_TOOLCHAIN_FILE=/backends/cadence/cadence.cmake -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=OFF \ -DEXECUTORCH_BUILD_PTHREADPOOL=OFF \ -DEXECUTORCH_BUILD_CPUINFO=OFF \ - -DEXECUTORCH_BUILD_FLATC=OFF \ - -DFLATC_EXECUTABLE="$(which flatc)" \ -Bcmake-out . cmake --build cmake-out -j --target install --config Debug @@ -184,8 +182,7 @@ cmake -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_TOOLCHAIN_FILE=/examples/backends/cadence.cmake \ -DCMAKE_PREFIX_PATH=/cmake-out \ -DMODEL_PATH= \ - -DNXP_SDK_ROOT_DIR= -DEXECUTORCH_BUILD_FLATC=0 \ - -DFLATC_EXECUTABLE="$(which flatc)" \ + -DNXP_SDK_ROOT_DIR= \ -DNN_LIB_BASE_DIR= \ -Bcmake-out/examples/cadence \ examples/cadence diff --git a/examples/apple/coreml/scripts/build_executor_runner.sh b/examples/apple/coreml/scripts/build_executor_runner.sh index 9d20f289bf6..08cc844d6f9 100755 --- a/examples/apple/coreml/scripts/build_executor_runner.sh +++ b/examples/apple/coreml/scripts/build_executor_runner.sh @@ -33,7 +33,6 @@ cmake "$EXECUTORCH_ROOT_PATH" -B"$CMAKE_BUILD_DIR_PATH" \ -DCMAKE_TOOLCHAIN_FILE="$IOS_TOOLCHAIN_PATH" \ -DPLATFORM=MAC_UNIVERSAL \ -DDEPLOYMENT_TARGET=13.0 \ --DFLATC_EXECUTABLE="$(which flatc)" \ -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=OFF \ -DEXECUTORCH_BUILD_XNNPACK=OFF \ -DEXECUTORCH_BUILD_DEVTOOLS=ON \ @@ -41,7 +40,7 @@ cmake "$EXECUTORCH_ROOT_PATH" -B"$CMAKE_BUILD_DIR_PATH" \ -Dprotobuf_BUILD_TESTS=OFF \ -Dprotobuf_BUILD_EXAMPLES=OFF \ -DCOREML_BUILD_EXECUTOR_RUNNER=ON \ --DCMAKE_MACOSX_BUNDLE=OFF \ +-DCMAKE_MACOSX_BUNDLE=OFF cmake --build "$CMAKE_BUILD_DIR_PATH" -j9 -t coremldelegate cmake --build "$CMAKE_BUILD_DIR_PATH" -j9 -t etdump -t flatccrt