Skip to content

Remove usage of external flatc in builds and scripts #9306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .ci/scripts/build_llama_android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 0 additions & 19 deletions .ci/scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 7 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 "")
Expand Down Expand Up @@ -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.
$<$<AND:$<BOOL:${CMAKE_TOOLCHAIN_IOS}>,$<BOOL:$<FILTER:${PLATFORM},EXCLUDE,^MAC>>>:-DCMAKE_OSX_SYSROOT=>
INSTALL_COMMAND ""
BUILD_BYPRODUCTS <BINARY_DIR>/flatc
)
Expand All @@ -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}/$<CONFIG>/flatc.exe)
elseif(CMAKE_GENERATOR STREQUAL "Xcode")
set(FLATC_EXECUTABLE ${BINARY_DIR}/$<CONFIG>/flatc)
else()
set(FLATC_EXECUTABLE ${BINARY_DIR}/flatc)
endif()
Expand All @@ -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()

Expand Down
1 change: 0 additions & 1 deletion backends/apple/coreml/scripts/build_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions backends/arm/scripts/build_executorch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand Down Expand Up @@ -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}"

Expand Down
4 changes: 0 additions & 4 deletions backends/cadence/build_cadence_fusionG3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 .

Expand All @@ -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 \
Expand All @@ -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 \
Expand Down
4 changes: 0 additions & 4 deletions backends/cadence/build_cadence_hifi4.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 \
Expand All @@ -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 \
Expand Down
Empty file modified build/build_android_library.sh
100644 → 100755
Empty file.
5 changes: 0 additions & 5 deletions build/build_apple_frameworks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ OUTPUT="cmake-out"
MODES=()
TOOLCHAIN=""
PYTHON=$(which python3)
FLATC=$(which flatc)
COREML=OFF
CUSTOM=OFF
MPS=OFF
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -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 ;;
Expand Down Expand Up @@ -168,7 +165,6 @@ check_command() {
check_command cmake
check_command rsync
check_command "$PYTHON"
check_command "$FLATC"
check_command "$BUCK2"

echo "Building libraries"
Expand All @@ -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 \
Expand Down
99 changes: 0 additions & 99 deletions build/install_flatc.sh

This file was deleted.

2 changes: 0 additions & 2 deletions build/test_ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
5 changes: 1 addition & 4 deletions docs/source/backends-cadence.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ cmake -DCMAKE_TOOLCHAIN_FILE=<path_to_executorch>/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<num_cores> --target install --config Debug
Expand All @@ -184,8 +182,7 @@ cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_TOOLCHAIN_FILE=<path_to_executorch>/examples/backends/cadence.cmake \
-DCMAKE_PREFIX_PATH=<path_to_executorch>/cmake-out \
-DMODEL_PATH=<path_to_program_file_generated_in_previous_step> \
-DNXP_SDK_ROOT_DIR=<path_to_nxp_sdk_root> -DEXECUTORCH_BUILD_FLATC=0 \
-DFLATC_EXECUTABLE="$(which flatc)" \
-DNXP_SDK_ROOT_DIR=<path_to_nxp_sdk_root> \
-DNN_LIB_BASE_DIR=<path_to_nnlib_cloned_in_step_2> \
-Bcmake-out/examples/cadence \
examples/cadence
Expand Down
3 changes: 1 addition & 2 deletions examples/apple/coreml/scripts/build_executor_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ 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 \
-DEXECUTORCH_BUILD_COREML=ON \
-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
Expand Down
Loading