diff --git a/CMakeLists.txt b/CMakeLists.txt index cfae0f8b74b..2f59c259332 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,11 +79,6 @@ if(NOT PYTHON_EXECUTABLE) endif() announce_configured_options(PYTHON_EXECUTABLE) -if(NOT BUCK2) - resolve_buck2() -endif() -announce_configured_options(BUCK2) - announce_configured_options(CMAKE_CXX_COMPILER_ID) announce_configured_options(CMAKE_TOOLCHAIN_FILE) announce_configured_options(BUILD_TESTING) @@ -318,17 +313,6 @@ if(EXECUTORCH_SRCS_FILE) ) endif() executorch_load_build_variables() -if(NOT EXECUTORCH_SRCS_FILE) - # A file wasn't provided. Run a script to extract the source lists from the - # buck2 build system and write them to a file we can include. - # - # NOTE: This will only happen once during cmake setup, so it will not re-run - # if the buck2 targets change. - message(STATUS "executorch: Generating source lists") - set(EXECUTORCH_SRCS_FILE "${CMAKE_CURRENT_BINARY_DIR}/executorch_srcs.cmake") - extract_sources(${EXECUTORCH_SRCS_FILE}) - executorch_validate_build_variables() -endif() # Detect if an iOS toolchain is set. if(CMAKE_TOOLCHAIN_FILE MATCHES ".*(iOS|ios\.toolchain)\.cmake$") diff --git a/tools/cmake/Codegen.cmake b/tools/cmake/Codegen.cmake index 93ba0f890a8..aa9c2133851 100644 --- a/tools/cmake/Codegen.cmake +++ b/tools/cmake/Codegen.cmake @@ -378,139 +378,73 @@ function(executorch_append_filelist name outputvar) ) endfunction() -set(EXECUTORCH_BUILD_VARIABLES_FILELISTS - EXECUTORCH_SRCS - EXECUTORCH_CORE_SRCS - PORTABLE_KERNELS_SRCS - KERNELS_UTIL_ALL_DEPS_SRCS - OPTIMIZED_KERNELS_SRCS - QUANTIZED_KERNELS_SRCS - PROGRAM_SCHEMA_SRCS - OPTIMIZED_CPUBLAS_SRCS - OPTIMIZED_NATIVE_CPU_OPS_SRCS - TEST_BACKEND_COMPILER_LIB_SRCS - EXTENSION_DATA_LOADER_SRCS - EXTENSION_EVALUE_UTIL_SRCS - EXTENSION_FLAT_TENSOR_SRCS - EXTENSION_MODULE_SRCS - EXTENSION_RUNNER_UTIL_SRCS - EXTENSION_LLM_RUNNER_SRCS - EXTENSION_TENSOR_SRCS - EXTENSION_THREADPOOL_SRCS - EXTENSION_TRAINING_SRCS - TRAIN_XOR_SRCS - EXECUTOR_RUNNER_SRCS - SIZE_TEST_SRCS - MPS_EXECUTOR_RUNNER_SRCS - MPS_BACKEND_SRCS - MPS_SCHEMA_SRCS - XNN_EXECUTOR_RUNNER_SRCS - XNNPACK_BACKEND_SRCS - XNNPACK_SCHEMA_SRCS - VULKAN_SCHEMA_SRCS - CUSTOM_OPS_SRCS - LLAMA_RUNNER_SRCS -) -set(EXECUTORCH_BUILD_VARIABLES_VARNAMES - _executorch__srcs - _executorch_core__srcs - _portable_kernels__srcs - _kernels_util_all_deps__srcs - _optimized_kernels__srcs - _quantized_kernels__srcs - _program_schema__srcs - _optimized_cpublas__srcs - _optimized_native_cpu_ops__srcs - _test_backend_compiler_lib__srcs - _extension_data_loader__srcs - _extension_evalue_util__srcs - _extension_flat_tensor__srcs - _extension_module__srcs - _extension_runner_util__srcs - _extension_llm_runner__srcs - _extension_tensor__srcs - _extension_threadpool__srcs - _extension_training__srcs - _train_xor__srcs - _executor_runner__srcs - _size_test__srcs - _mps_executor_runner__srcs - _mps_backend__srcs - _mps_schema__srcs - _xnn_executor_runner__srcs - _xnnpack_backend__srcs - _xnnpack_schema__srcs - _vulkan_schema__srcs - _custom_ops__srcs - _llama_runner__srcs -) - -# Fail the build if the src lists in build_variables.bzl do not match the src -# lists extracted from Buck and placed into EXECUTORCH_SRCS_FILE. This is -# intended to be a safety mechanism while we are in the process of removing Buck -# from the CMake build and replacing it with build_variables.bzl; if you are -# seeing failures after you have intentionally changed Buck srcs, then simply -# update build_variables.bzl. If you are seeing failures after changing -# something about the build system, make sure your changes will work both before -# and after we finish replacing Buck with build_variables.bzl, which should -# involve getting these lists to match! -function(executorch_validate_build_variables) - include(${EXECUTORCH_SRCS_FILE}) - foreach(filelist_and_varname IN - ZIP_LISTS EXECUTORCH_BUILD_VARIABLES_FILELISTS - EXECUTORCH_BUILD_VARIABLES_VARNAMES - ) - executorch_append_filelist( - ${filelist_and_varname_0} - "${filelist_and_varname_1}_from_build_variables" - ) - # The Buck and CMake mechanisms for getting the default PAL set up are - # different. Prevent the Buck choice from flowing into CMake and causing - # validation to fail, just like we do in our CMakeLists.txt. - if("${filelist_and_varname_1}" STREQUAL "_executorch_core__srcs") - list(FILTER ${filelist_and_varname_1} EXCLUDE REGEX - "runtime/platform/default/[^/]*.cpp$" - ) - endif() - if(NOT ${filelist_and_varname_1} STREQUAL - ${filelist_and_varname_1}_from_build_variables - ) - set(generated_items_not_in_build_variables ${${filelist_and_varname_1}}) - list(REMOVE_ITEM generated_items_not_in_build_variables - ${${filelist_and_varname_1}_from_build_variables} - ) - - set(build_variables_items_not_in_generated - ${${filelist_and_varname_1}_from_build_variables} - ) - list(REMOVE_ITEM build_variables_items_not_in_generated - ${${filelist_and_varname_1}} - ) - - list(JOIN generated_items_not_in_build_variables "\n" - pretty_generated_items_not_in_build_variables - ) - list(JOIN build_variables_items_not_in_generated "\n" - pretty_build_variables_items_not_in_generated - ) - if(NOT pretty_generated_items_not_in_build_variables) - set(pretty_generated_items_not_in_build_variables "") - endif() - if(NOT pretty_build_variables_items_not_in_generated) - set(pretty_build_variables_items_not_in_generated "") - endif() - message( - FATAL_ERROR - "Buck-generated ${filelist_and_varname_1} does not match hardcoded " - "${filelist_and_varname_0} in build_variables.bzl. Buck-generated items not in build_variables.bzl: " - "${pretty_generated_items_not_in_build_variables}\n " - "build_variables.bzl items not in buck-generated list: ${pretty_build_variables_items_not_in_generated}" - ) - endif() - endforeach() -endfunction() - function(executorch_load_build_variables) + set(EXECUTORCH_BUILD_VARIABLES_FILELISTS + EXECUTORCH_SRCS + EXECUTORCH_CORE_SRCS + PORTABLE_KERNELS_SRCS + KERNELS_UTIL_ALL_DEPS_SRCS + OPTIMIZED_KERNELS_SRCS + QUANTIZED_KERNELS_SRCS + PROGRAM_SCHEMA_SRCS + OPTIMIZED_CPUBLAS_SRCS + OPTIMIZED_NATIVE_CPU_OPS_SRCS + TEST_BACKEND_COMPILER_LIB_SRCS + EXTENSION_DATA_LOADER_SRCS + EXTENSION_EVALUE_UTIL_SRCS + EXTENSION_FLAT_TENSOR_SRCS + EXTENSION_MODULE_SRCS + EXTENSION_RUNNER_UTIL_SRCS + EXTENSION_LLM_RUNNER_SRCS + EXTENSION_TENSOR_SRCS + EXTENSION_THREADPOOL_SRCS + EXTENSION_TRAINING_SRCS + TRAIN_XOR_SRCS + EXECUTOR_RUNNER_SRCS + SIZE_TEST_SRCS + MPS_EXECUTOR_RUNNER_SRCS + MPS_BACKEND_SRCS + MPS_SCHEMA_SRCS + XNN_EXECUTOR_RUNNER_SRCS + XNNPACK_BACKEND_SRCS + XNNPACK_SCHEMA_SRCS + VULKAN_SCHEMA_SRCS + CUSTOM_OPS_SRCS + LLAMA_RUNNER_SRCS + ) + set(EXECUTORCH_BUILD_VARIABLES_VARNAMES + _executorch__srcs + _executorch_core__srcs + _portable_kernels__srcs + _kernels_util_all_deps__srcs + _optimized_kernels__srcs + _quantized_kernels__srcs + _program_schema__srcs + _optimized_cpublas__srcs + _optimized_native_cpu_ops__srcs + _test_backend_compiler_lib__srcs + _extension_data_loader__srcs + _extension_evalue_util__srcs + _extension_flat_tensor__srcs + _extension_module__srcs + _extension_runner_util__srcs + _extension_llm_runner__srcs + _extension_tensor__srcs + _extension_threadpool__srcs + _extension_training__srcs + _train_xor__srcs + _executor_runner__srcs + _size_test__srcs + _mps_executor_runner__srcs + _mps_backend__srcs + _mps_schema__srcs + _xnn_executor_runner__srcs + _xnnpack_backend__srcs + _xnnpack_schema__srcs + _vulkan_schema__srcs + _custom_ops__srcs + _llama_runner__srcs + ) foreach(filelist_and_varname IN ZIP_LISTS EXECUTORCH_BUILD_VARIABLES_FILELISTS EXECUTORCH_BUILD_VARIABLES_VARNAMES diff --git a/tools/cmake/Utils.cmake b/tools/cmake/Utils.cmake index e567fa503d4..3b42fe659a5 100644 --- a/tools/cmake/Utils.cmake +++ b/tools/cmake/Utils.cmake @@ -119,74 +119,6 @@ function(extract_sources sources_file) endif() endfunction() -# Sets the value of the BUCK2 variable by searching for a buck2 binary with the -# correct version. -# -# The resolve_buck.py script uses the following logic to find buck2: 1) If BUCK2 -# argument is set explicitly, use it. Warn if the version is incorrect. 2) Look -# for a binary named buck2 on the system path. Take it if it is the correct -# version. 3) Check for a previously downloaded buck2 binary (from step 4). 4) -# Download and cache correct version of buck2. -function(resolve_buck2) - if(EXECUTORCH_ROOT) - set(executorch_root ${EXECUTORCH_ROOT}) - else() - set(executorch_root ${CMAKE_CURRENT_SOURCE_DIR}) - endif() - - set(resolve_buck2_command - ${PYTHON_EXECUTABLE} ${executorch_root}/tools/cmake/resolve_buck.py - --cache_dir=${executorch_root}/buck2-bin - ) - - if(NOT ${BUCK2} STREQUAL "") - list(APPEND resolve_buck2_command --buck2=${BUCK2}) - endif() - - execute_process( - COMMAND ${resolve_buck2_command} - OUTPUT_VARIABLE resolve_buck2_output - ERROR_VARIABLE resolve_buck2_error - RESULT_VARIABLE resolve_buck2_exit_code - WORKING_DIRECTORY ${executorch_root} - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - - # $BUCK2 is a copy of the var from the parent scope. This block will set - # $buck2 to the value we want to return. - if(resolve_buck2_exit_code EQUAL 0) - set(buck2 ${resolve_buck2_output}) - message(STATUS "Resolved buck2 as ${resolve_buck2_output}.") - elseif(resolve_buck2_exit_code EQUAL 2) - # Wrong buck version used. Stop here to ensure that the user sees the error. - message(FATAL_ERROR "Failed to resolve buck2.\n${resolve_buck2_error}") - else() - # Unexpected failure of the script. Warn. - message(WARNING "Failed to resolve buck2.") - message(WARNING "${resolve_buck2_error}") - - if("${BUCK2}" STREQUAL "") - set(buck2 "buck2") - endif() - endif() - - # Update the var in the parent scope. Note that this does not modify our local - # $BUCK2 value. - set(BUCK2 - "${buck2}" - PARENT_SCOPE - ) - - # The buck2 daemon can get stuck. Killing it can help. - message(STATUS "Killing buck2 daemon") - execute_process( - # Note that we need to use the local buck2 variable. BUCK2 is only set in - # the parent scope, and can still be empty in this scope. - COMMAND "${buck2} killall" - WORKING_DIRECTORY ${executorch_root} COMMAND_ECHO STDOUT - ) -endfunction() - # Sets the value of the PYTHON_EXECUTABLE variable to 'python' if in an active # (non-base) conda environment, and 'python3' otherwise. This maintains # backwards compatibility for non-conda users and avoids conda users needing to