From 6d51bff6d163ac79061b45a7dc34e556222b2403 Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Tue, 4 Mar 2025 17:40:16 -0800 Subject: [PATCH 1/7] Update [ghstack-poisoned] --- CMakeLists.txt | 8 +++++++- backends/apple/coreml/CMakeLists.txt | 1 + backends/apple/mps/CMakeLists.txt | 1 + backends/mediatek/CMakeLists.txt | 2 +- backends/qualcomm/CMakeLists.txt | 2 +- backends/vulkan/CMakeLists.txt | 1 + backends/xnnpack/CMakeLists.txt | 17 +++++++++-------- backends/xnnpack/cmake/Dependencies.cmake | 2 ++ configurations/CMakeLists.txt | 2 +- extension/data_loader/CMakeLists.txt | 3 ++- extension/flat_tensor/CMakeLists.txt | 6 +++--- extension/llm/custom_ops/CMakeLists.txt | 9 +++++---- extension/llm/tokenizer/CMakeLists.txt | 1 + extension/module/CMakeLists.txt | 5 +++-- extension/runner_util/CMakeLists.txt | 3 ++- extension/tensor/CMakeLists.txt | 3 ++- extension/threadpool/CMakeLists.txt | 10 ++++++---- extension/training/CMakeLists.txt | 1 + kernels/optimized/CMakeLists.txt | 6 +++--- kernels/portable/CMakeLists.txt | 1 + kernels/quantized/CMakeLists.txt | 1 + schema/CMakeLists.txt | 11 ++++++++++- 22 files changed, 64 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index de941663a88..294c0e076a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -384,7 +384,7 @@ if(NOT "${_repo_dir_name}" STREQUAL "executorch") "fix for this restriction." ) endif() -set(_common_include_directories ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/runtime/core/portable_type/c10) +set(_common_include_directories $ $) # # The `__srcs` lists are defined by including ${EXECUTORCH_SRCS_FILE}. @@ -653,6 +653,7 @@ install(DIRECTORY extension/tensor/ DESTINATION include/executorch/extension/te install(DIRECTORY extension/threadpool/ DESTINATION include/executorch/extension/threadpool FILES_MATCHING PATTERN "*.h") install( TARGETS executorch executorch_core + EXPORT ExecuTorchTargets DESTINATION lib INCLUDES DESTINATION ${_common_include_directories} @@ -835,6 +836,7 @@ if(EXECUTORCH_BUILD_PYBIND) target_link_libraries(portable_lib PRIVATE ${_dep_libs}) install(TARGETS portable_lib + EXPORT ExecuTorchTargets LIBRARY DESTINATION executorch/extension/pybindings ) @@ -863,6 +865,7 @@ if(EXECUTORCH_BUILD_PYBIND) target_link_libraries(_training_lib PRIVATE ${_pybind_training_dep_libs}) install(TARGETS _training_lib + EXPORT ExecuTorchTargets LIBRARY DESTINATION executorch/extension/training/pybindings ) endif() @@ -921,5 +924,8 @@ endif() include(Test.cmake) +install(EXPORT ExecuTorchTargets + FILE ExecuTorchTargets.cmake + DESTINATION lib/cmake/ExecuTorch) # Print all summary executorch_print_configuration_summary() diff --git a/backends/apple/coreml/CMakeLists.txt b/backends/apple/coreml/CMakeLists.txt index 01fe9d0f59a..6947b4ee7ac 100644 --- a/backends/apple/coreml/CMakeLists.txt +++ b/backends/apple/coreml/CMakeLists.txt @@ -200,6 +200,7 @@ set(TARGET coremldelegate APPEND_STRING PROPERTY COMPILE_FLAGS install( TARGETS coremldelegate + EXPORT ExecuTorchTargets DESTINATION lib INCLUDES DESTINATION ${_common_include_directories} diff --git a/backends/apple/mps/CMakeLists.txt b/backends/apple/mps/CMakeLists.txt index 96aa007563b..b621db327cb 100644 --- a/backends/apple/mps/CMakeLists.txt +++ b/backends/apple/mps/CMakeLists.txt @@ -88,6 +88,7 @@ target_compile_options(mpsdelegate PRIVATE "-fno-objc-arc") install( TARGETS mpsdelegate + EXPORT ExecuTorchTargets DESTINATION lib INCLUDES DESTINATION ${_common_include_directories} diff --git a/backends/mediatek/CMakeLists.txt b/backends/mediatek/CMakeLists.txt index 45f4bcda7fe..033eb6ca599 100644 --- a/backends/mediatek/CMakeLists.txt +++ b/backends/mediatek/CMakeLists.txt @@ -46,4 +46,4 @@ target_sources( ) target_link_options_shared_lib(neuron_backend) -install(TARGETS neuron_backend DESTINATION lib) +install(TARGETS neuron_backend EXPORT ExecuTorchTargets DESTINATION lib) diff --git a/backends/qualcomm/CMakeLists.txt b/backends/qualcomm/CMakeLists.txt index aefa929ee9f..10aabd5fca6 100644 --- a/backends/qualcomm/CMakeLists.txt +++ b/backends/qualcomm/CMakeLists.txt @@ -220,7 +220,7 @@ add_subdirectory( ${QNN_EXECUTORCH_ROOT_DIR}/aot/ir ${CMAKE_CURRENT_BINARY_DIR}/qnn_executorch/ir ) -install(TARGETS qnn_executorch_backend DESTINATION lib) +install(TARGETS qnn_executorch_backend EXPORT ExecuTorchTargets DESTINATION lib) # QNN pybind if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64") diff --git a/backends/vulkan/CMakeLists.txt b/backends/vulkan/CMakeLists.txt index fca34fdf6a4..a471e7c2f43 100644 --- a/backends/vulkan/CMakeLists.txt +++ b/backends/vulkan/CMakeLists.txt @@ -148,6 +148,7 @@ endif() install( TARGETS vulkan_backend + EXPORT ExecuTorchTargets DESTINATION lib INCLUDES DESTINATION ${COMMON_INCLUDES} diff --git a/backends/xnnpack/CMakeLists.txt b/backends/xnnpack/CMakeLists.txt index dc42a52a234..2bbb061c697 100644 --- a/backends/xnnpack/CMakeLists.txt +++ b/backends/xnnpack/CMakeLists.txt @@ -48,7 +48,6 @@ if(EXECUTORCH_XNNPACK_ENABLE_KLEIDI) add_definitions(-DENABLE_XNNPACK_KLEIDI) endif() -set(_common_include_directories ${EXECUTORCH_ROOT}/..) set(_common_compile_options -Wno-deprecated-declarations -fPIC) set(_xnnpack_schema__include_dir "${CMAKE_BINARY_DIR}/schema/include") @@ -89,10 +88,9 @@ add_custom_command( add_library(xnnpack_schema INTERFACE ${_xnnpack_schema__outputs}) set_target_properties(xnnpack_schema PROPERTIES LINKER_LANGUAGE CXX) target_include_directories( - xnnpack_schema INTERFACE ${_xnnpack_schema__include_dir} - ${EXECUTORCH_ROOT}/third-party/flatbuffers/include + xnnpack_schema INTERFACE $ ) - +target_link_libraries(xnnpack_schema INTERFACE flatbuffers) set(xnnpack_third_party pthreadpool cpuinfo) include(cmake/Dependencies.cmake) @@ -106,14 +104,14 @@ target_link_libraries( target_include_directories( xnnpack_backend PUBLIC ${_common_include_directories} ) -target_include_directories(xnnpack_backend PUBLIC ${XNNPACK_INCLUDE_DIR}) +target_include_directories(xnnpack_backend PRIVATE ${XNNPACK_INCLUDE_DIR}) target_include_directories( xnnpack_backend - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/third-party/pthreadpool/include + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/third-party/pthreadpool/include ) target_include_directories( xnnpack_backend - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/third-party/cpuinfo/include + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/third-party/cpuinfo/include ) target_compile_options(xnnpack_backend PUBLIC ${_common_compile_options}) target_link_options_shared_lib(xnnpack_backend) @@ -155,7 +153,10 @@ if(NOT CMAKE_TOOLCHAIN_FILE MATCHES ".*(iOS|ios\.toolchain)\.cmake$") endif() install( - TARGETS xnnpack_backend + # XNNPACK doesn't export the XNNPACK and following targets, + # so we need to export them ourselves. + TARGETS xnnpack_backend xnnpack_schema XNNPACK fxdiv + EXPORT ExecuTorchTargets DESTINATION lib INCLUDES DESTINATION ${_common_include_directories} diff --git a/backends/xnnpack/cmake/Dependencies.cmake b/backends/xnnpack/cmake/Dependencies.cmake index fef63badf23..5aa6926674e 100644 --- a/backends/xnnpack/cmake/Dependencies.cmake +++ b/backends/xnnpack/cmake/Dependencies.cmake @@ -58,6 +58,7 @@ add_subdirectory("${XNNPACK_SOURCE_DIR}") include_directories(SYSTEM ${XNNPACK_INCLUDE_DIR}) list(APPEND xnnpack_third_party XNNPACK) install(TARGETS microkernels-prod + EXPORT ExecuTorchTargets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) @@ -65,6 +66,7 @@ install(TARGETS microkernels-prod if(EXECUTORCH_XNNPACK_ENABLE_KLEIDI) install(TARGETS kleidiai + EXPORT ExecuTorchTargets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) diff --git a/configurations/CMakeLists.txt b/configurations/CMakeLists.txt index 462124a6ea6..209c02453f1 100644 --- a/configurations/CMakeLists.txt +++ b/configurations/CMakeLists.txt @@ -57,5 +57,5 @@ if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED) executorch ) - install(TARGETS optimized_native_cpu_ops_lib DESTINATION lib) + install(TARGETS optimized_native_cpu_ops_lib EXPORT ExecuTorchTargets DESTINATION lib) endif() diff --git a/extension/data_loader/CMakeLists.txt b/extension/data_loader/CMakeLists.txt index 0af3fbcc161..4da2104dd91 100644 --- a/extension/data_loader/CMakeLists.txt +++ b/extension/data_loader/CMakeLists.txt @@ -19,12 +19,13 @@ endif() list(TRANSFORM _extension_data_loader__srcs PREPEND "${EXECUTORCH_ROOT}/") add_library(extension_data_loader ${_extension_data_loader__srcs}) target_link_libraries(extension_data_loader executorch) -target_include_directories(extension_data_loader PUBLIC ${EXECUTORCH_ROOT}/..) +target_include_directories(extension_data_loader PUBLIC ${_common_include_directories}) target_compile_options(extension_data_loader PUBLIC ${_common_compile_options}) # Install libraries install( TARGETS extension_data_loader + EXPORT ExecuTorchTargets DESTINATION lib INCLUDES DESTINATION ${_common_include_directories} diff --git a/extension/flat_tensor/CMakeLists.txt b/extension/flat_tensor/CMakeLists.txt index caacd96b557..be51ee6fddb 100644 --- a/extension/flat_tensor/CMakeLists.txt +++ b/extension/flat_tensor/CMakeLists.txt @@ -21,9 +21,8 @@ add_library(extension_flat_tensor ${_extension_flat_tensor__srcs}) target_link_libraries(extension_flat_tensor executorch extension_data_loader) target_include_directories( extension_flat_tensor - PUBLIC ${EXECUTORCH_ROOT}/.. - "${CMAKE_BINARY_DIR}/extension/flat_tensor/include" - "${EXECUTORCH_ROOT}/third-party/flatbuffers/include" + PUBLIC $ + $ ${_common_include_directories} ) target_compile_options(extension_flat_tensor PUBLIC ${_common_compile_options}) @@ -31,6 +30,7 @@ target_compile_options(extension_flat_tensor PUBLIC ${_common_compile_options}) # Install libraries install( TARGETS extension_flat_tensor + EXPORT ExecuTorchTargets DESTINATION lib INCLUDES DESTINATION ${_common_include_directories} diff --git a/extension/llm/custom_ops/CMakeLists.txt b/extension/llm/custom_ops/CMakeLists.txt index c3969e6f9bf..2a7c65c3988 100644 --- a/extension/llm/custom_ops/CMakeLists.txt +++ b/extension/llm/custom_ops/CMakeLists.txt @@ -37,7 +37,7 @@ extract_sources(${EXECUTORCH_SRCS_FILE}) include(${EXECUTORCH_SRCS_FILE}) # Let files say "include ". -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories $ $) # Custom op libraries set(custom_ops_libs pthreadpool) @@ -73,7 +73,7 @@ add_library(custom_ops ${_custom_ops__srcs}) target_include_directories(custom_ops PUBLIC "${_common_include_directories}") target_include_directories( - custom_ops PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../../../include" + custom_ops PRIVATE $ ) target_link_libraries(custom_ops PUBLIC ${custom_ops_libs} executorch_core) @@ -81,7 +81,7 @@ target_compile_options( custom_ops PUBLIC ${_common_compile_options} -DET_USE_THREADPOOL ) -install(TARGETS custom_ops DESTINATION lib) +install(TARGETS custom_ops EXPORT ExecuTorchTargets DESTINATION lib) if(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT) # Add a AOT library @@ -98,7 +98,7 @@ if(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT) custom_ops_aot_lib PUBLIC "${_common_include_directories}" ) target_include_directories( - custom_ops_aot_lib PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../../../include" + custom_ops_aot_lib PRIVATE $ ) # TODO: This only works if we install portable_lib.so to # /executorch/extension/pybindings/. @@ -134,6 +134,7 @@ if(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT) ) install(TARGETS custom_ops_aot_lib + EXPORT ExecuTorchTargets LIBRARY DESTINATION executorch/extension/llm/custom_ops ) endif() diff --git a/extension/llm/tokenizer/CMakeLists.txt b/extension/llm/tokenizer/CMakeLists.txt index 8745da6780a..ffef76eec91 100644 --- a/extension/llm/tokenizer/CMakeLists.txt +++ b/extension/llm/tokenizer/CMakeLists.txt @@ -45,6 +45,7 @@ target_compile_options( # Install libraries install( TARGETS extension_llm_tokenizer + EXPORT ExecuTorchTargets DESTINATION lib INCLUDES DESTINATION ${_common_include_directories} diff --git a/extension/module/CMakeLists.txt b/extension/module/CMakeLists.txt index d144ce95356..9d42b93cbb4 100644 --- a/extension/module/CMakeLists.txt +++ b/extension/module/CMakeLists.txt @@ -28,7 +28,7 @@ else() add_library(extension_module SHARED ${_extension_module__srcs}) endif() target_link_libraries(extension_module PRIVATE executorch extension_data_loader extension_flat_tensor) -target_include_directories(extension_module PUBLIC ${EXECUTORCH_ROOT}/..) +target_include_directories(extension_module PUBLIC ${_common_include_directories}) target_compile_options( extension_module PUBLIC -Wno-deprecated-declarations -fPIC ) @@ -39,7 +39,7 @@ add_library(extension_module_static STATIC ${_extension_module__srcs}) target_link_libraries( extension_module_static PRIVATE executorch extension_data_loader extension_flat_tensor ) -target_include_directories(extension_module_static PUBLIC ${EXECUTORCH_ROOT}/..) +target_include_directories(extension_module_static PUBLIC ${_common_include_directories}) target_compile_options( extension_module_static PUBLIC -Wno-deprecated-declarations -fPIC ) @@ -47,6 +47,7 @@ target_compile_options( # Install libraries install( TARGETS extension_module extension_module_static + EXPORT ExecuTorchTargets DESTINATION lib INCLUDES DESTINATION ${_common_include_directories} diff --git a/extension/runner_util/CMakeLists.txt b/extension/runner_util/CMakeLists.txt index 19aa884fd77..6efd8de736f 100644 --- a/extension/runner_util/CMakeLists.txt +++ b/extension/runner_util/CMakeLists.txt @@ -19,12 +19,13 @@ endif() list(TRANSFORM _extension_runner_util__srcs PREPEND "${EXECUTORCH_ROOT}/") add_library(extension_runner_util ${_extension_runner_util__srcs}) target_link_libraries(extension_runner_util executorch) -target_include_directories(extension_runner_util PUBLIC ${EXECUTORCH_ROOT}/..) +target_include_directories(extension_runner_util PUBLIC ${_common_include_directories}) target_compile_options(extension_runner_util PUBLIC ${_common_compile_options}) # Install libraries install( TARGETS extension_runner_util + EXPORT ExecuTorchTargets DESTINATION ${CMAKE_BINARY_DIR}/lib INCLUDES DESTINATION ${_common_include_directories} diff --git a/extension/tensor/CMakeLists.txt b/extension/tensor/CMakeLists.txt index 51f955570db..9547de5b056 100644 --- a/extension/tensor/CMakeLists.txt +++ b/extension/tensor/CMakeLists.txt @@ -19,12 +19,13 @@ endif() list(TRANSFORM _extension_tensor__srcs PREPEND "${EXECUTORCH_ROOT}/") add_library(extension_tensor ${_extension_tensor__srcs}) target_link_libraries(extension_tensor executorch_core) -target_include_directories(extension_tensor PUBLIC ${EXECUTORCH_ROOT}/..) +target_include_directories(extension_tensor PUBLIC ${_common_include_directories}) target_compile_options(extension_tensor PUBLIC ${_common_compile_options}) # Install libraries install( TARGETS extension_tensor + EXPORT ExecuTorchTargets DESTINATION lib INCLUDES DESTINATION ${_common_include_directories} diff --git a/extension/threadpool/CMakeLists.txt b/extension/threadpool/CMakeLists.txt index 90288656674..38ed8432a12 100644 --- a/extension/threadpool/CMakeLists.txt +++ b/extension/threadpool/CMakeLists.txt @@ -26,17 +26,19 @@ add_library( target_link_libraries( extension_threadpool PUBLIC executorch_core cpuinfo pthreadpool ) -target_include_directories(extension_threadpool PUBLIC ${EXECUTORCH_ROOT}/..) +target_include_directories(extension_threadpool PUBLIC ${_common_include_directories}) target_include_directories( extension_threadpool - PUBLIC ${EXECUTORCH_ROOT}/backends/xnnpack/third-party/cpuinfo/include - ${EXECUTORCH_ROOT}/backends/xnnpack/third-party/pthreadpool/include + PUBLIC $ + $ ) target_compile_options(extension_threadpool PUBLIC ${_common_compile_options}) # Install libraries install( - TARGETS extension_threadpool + # pthreadpool doesn't export itself, so we have to do our own install to export it. + TARGETS pthreadpool pthreadpool_interface extension_threadpool + EXPORT ExecuTorchTargets DESTINATION lib INCLUDES DESTINATION ${_common_include_directories} diff --git a/extension/training/CMakeLists.txt b/extension/training/CMakeLists.txt index 97e75955837..43028d09c0b 100644 --- a/extension/training/CMakeLists.txt +++ b/extension/training/CMakeLists.txt @@ -43,6 +43,7 @@ target_compile_options(train_xor PUBLIC ${_common_compile_options}) # Install libraries install( TARGETS extension_training + EXPORT ExecuTorchTargets DESTINATION lib INCLUDES DESTINATION ${_common_include_directories} diff --git a/kernels/optimized/CMakeLists.txt b/kernels/optimized/CMakeLists.txt index 235c6738d9a..756b204e7f2 100644 --- a/kernels/optimized/CMakeLists.txt +++ b/kernels/optimized/CMakeLists.txt @@ -74,9 +74,9 @@ gen_operators_lib( ) install( - TARGETS cpublas optimized_kernels optimized_ops_lib + # eigen_blas doesn't export itself, so we have to do our own install to export it. + TARGETS cpublas optimized_kernels optimized_ops_lib eigen_blas + EXPORT ExecuTorchTargets DESTINATION lib PUBLIC_HEADER DESTINATION include/executorch/kernels/optimized/ ) - -install(TARGETS cpublas DESTINATION lib) diff --git a/kernels/portable/CMakeLists.txt b/kernels/portable/CMakeLists.txt index 885c509246b..31da5883772 100644 --- a/kernels/portable/CMakeLists.txt +++ b/kernels/portable/CMakeLists.txt @@ -65,6 +65,7 @@ gen_operators_lib( install( TARGETS portable_kernels portable_ops_lib + EXPORT ExecuTorchTargets DESTINATION lib PUBLIC_HEADER DESTINATION include/executorch/kernels/portable/ ) diff --git a/kernels/quantized/CMakeLists.txt b/kernels/quantized/CMakeLists.txt index 6b01ba4fc27..d96d5062f50 100644 --- a/kernels/quantized/CMakeLists.txt +++ b/kernels/quantized/CMakeLists.txt @@ -153,6 +153,7 @@ gen_operators_lib( install( TARGETS quantized_kernels quantized_ops_lib + EXPORT ExecuTorchTargets DESTINATION lib PUBLIC_HEADER DESTINATION include/executorch/kernels/quantized/ ) diff --git a/schema/CMakeLists.txt b/schema/CMakeLists.txt index 64f8821da1e..b39a7eec557 100644 --- a/schema/CMakeLists.txt +++ b/schema/CMakeLists.txt @@ -55,8 +55,10 @@ function(generate_program_schema _schema_srcs _schema_name) target_include_directories( ${_schema_name} INTERFACE ${_program_schema__include_dir} - ${EXECUTORCH_ROOT}/third-party/flatbuffers/include + $ ) + target_link_libraries(${_schema_name} INTERFACE flatbuffers) + endfunction() # Generate common schema @@ -67,3 +69,10 @@ generate_program_schema("${common_schema_srcs}" "common_schema") set(program_schema_srcs program.fbs) generate_program_schema("${program_schema_srcs}" "program_schema") add_dependencies(program_schema common_schema) + +install( + TARGETS common_schema program_schema + EXPORT ExecuTorchTargets + DESTINATION lib + INCLUDES + DESTINATION ${_common_include_directories}) From 4ac87e35978412a0c29fdf7c249f605892a51b0a Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Wed, 16 Jul 2025 17:50:36 -0700 Subject: [PATCH 2/7] Update [ghstack-poisoned] --- CMakePresets.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index 8cb7fce482f..069f93374e9 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -12,7 +12,6 @@ "inherits": ["common"], "generator": "Xcode", "cacheVariables": { - "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/third-party/ios-cmake/ios.toolchain.cmake", "EXECUTORCH_BUILD_PRESET_FILE": "${sourceDir}/tools/cmake/preset/macos.cmake", "PLATFORM": "MAC_ARM64", "DEPLOYMENT_TARGET": "12.0" @@ -47,7 +46,7 @@ "generator": "Xcode", "cacheVariables": { "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/third-party/ios-cmake/ios.toolchain.cmake", - "EXECUTORCH_BUILD_PRESET_FILE": "${sourceDir}/tools/cmake/preset/ios.cmake", + "EXECUTORCH_BUILD_PREe SET_FILE": "${sourceDir}/tools/cmake/preset/ios.cmake", "PLATFORM": "SIMULATORARM64", "DEPLOYMENT_TARGET": "17.0" }, From 200b7dda5f86e42b41d6878c5448d41c3b97adc8 Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Wed, 16 Jul 2025 23:38:48 -0700 Subject: [PATCH 3/7] Update [ghstack-poisoned] --- devtools/CMakeLists.txt | 3 ++- devtools/etdump/CMakeLists.txt | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/devtools/CMakeLists.txt b/devtools/CMakeLists.txt index feae931da6d..85492075b8c 100644 --- a/devtools/CMakeLists.txt +++ b/devtools/CMakeLists.txt @@ -5,8 +5,9 @@ # LICENSE file in the root directory of this source tree. # The include directory that will contain the generated schema headers. +set(DEVTOOLS_INCLUDE_DIR_NO_BUILD_INTERFACE ${CMAKE_BINARY_DIR}/devtools/include) set(DEVTOOLS_INCLUDE_DIR - $ + $ ) add_subdirectory(etdump) diff --git a/devtools/etdump/CMakeLists.txt b/devtools/etdump/CMakeLists.txt index 847ac9914e9..f653f022f6e 100644 --- a/devtools/etdump/CMakeLists.txt +++ b/devtools/etdump/CMakeLists.txt @@ -21,7 +21,7 @@ foreach(schema_file ${_schema_files}) list(APPEND _schema_outputs "${DEVTOOLS_INCLUDE_DIR}/executorch/devtools/etdump/${generated_builder}") endforeach() -file(MAKE_DIRECTORY ${DEVTOOLS_INCLUDE_DIR}/executorch/devtools/etdump) +file(MAKE_DIRECTORY ${DEVTOOLS_INCLUDE_DIR_NO_BUILD_INTERFACE}/executorch/devtools/etdump) add_custom_command( OUTPUT ${_schema_outputs} COMMAND @@ -29,7 +29,7 @@ add_custom_command( # tree instead of under the binary directory, and there's no way to change # that behavior. flatcc_cli -cwr -o - ${DEVTOOLS_INCLUDE_DIR}/executorch/devtools/etdump + ${DEVTOOLS_INCLUDE_DIR_NO_BUILD_INTERFACE}/executorch/devtools/etdump ${_etdump_schema__srcs} DEPENDS flatcc_cli ${_etdump_schema__srcs} COMMENT "Generating etdump headers" From b85ed41c905b2650c2d312c41ae1c3cfabcf7596 Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Thu, 17 Jul 2025 09:02:56 -0700 Subject: [PATCH 4/7] Update [ghstack-poisoned] --- tools/cmake/executorch-config.cmake | 70 ++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 7 deletions(-) diff --git a/tools/cmake/executorch-config.cmake b/tools/cmake/executorch-config.cmake index ce68a9b8638..823a562d002 100644 --- a/tools/cmake/executorch-config.cmake +++ b/tools/cmake/executorch-config.cmake @@ -25,14 +25,33 @@ cmake_minimum_required(VERSION 3.24) include("${CMAKE_CURRENT_LIST_DIR}/Utils.cmake") -find_package(tokenizers REQUIRED) +find_package(tokenizers) # not REQUIRED because building it is optional set(_root "${CMAKE_CURRENT_LIST_DIR}/../../..") +set(required_lib_list executorch executorch_core portable_kernels) +set(EXECUTORCH_LIBRARIES) set(EXECUTORCH_INCLUDE_DIRS ${_root}/include ${_root}/include/executorch/runtime/core/portable_type/c10 ${_root}/lib ) -set(non_exported_lib_list XNNPACK xnnpack-microkernels-prod kleidiai pthreadpool cpuinfo) +foreach(lib ${required_lib_list}) + set(lib_var "LIB_${lib}") + find_library( + ${lib_var} ${lib} + HINTS "${_root}/lib" + CMAKE_FIND_ROOT_PATH_BOTH + ) + if(NOT ${lib_var}) + set(EXECUTORCH_FOUND OFF) + return() + endif() + list(APPEND EXECUTORCH_LIBRARIES ${lib}) +endforeach() +set(EXECUTORCH_FOUND ON) + +set(non_exported_lib_list XNNPACK xnnpack-microkernels-prod kleidiai + pthreadpool cpuinfo +) foreach(lib ${non_exported_lib_list}) # Name of the variable which stores result of the find_library search set(lib_var "LIB_${lib}") @@ -48,14 +67,51 @@ foreach(lib ${non_exported_lib_list}) else() add_library(${lib} STATIC IMPORTED) set_target_properties(${lib} PROPERTIES IMPORTED_LOCATION "${${lib_var}}") - target_include_directories( - ${lib} - INTERFACE ${EXECUTORCH_INCLUDE_DIRS} - ) + target_include_directories(${lib} INTERFACE ${EXECUTORCH_INCLUDE_DIRS}) list(APPEND EXECUTORCH_LIBRARIES ${lib}) endif() endforeach() include("${CMAKE_CURRENT_LIST_DIR}/ExecuTorchTargets.cmake") -# TODO: does ExecuTorchTargets.cmake set EXECUTORCH_FOUND? +set(optional_lib_list + flatccrt + etdump + bundled_program + extension_data_loader + extension_flat_tensor + coreml_util + coreml_inmemoryfs + coremldelegate + mpsdelegate + neuron_backend + qnn_executorch_backend + portable_ops_lib + custom_ops + extension_module + extension_module_static + extension_runner_util + extension_tensor + extension_threadpool + extension_training + xnnpack_backend + vulkan_backend + optimized_kernels + optimized_portable_kernels + cpublas + eigen_blas + optimized_ops_lib + optimized_native_cpu_ops_lib + quantized_kernels + quantized_ops_lib + quantized_ops_aot_lib +) +foreach(lib ${optional_lib_list}) + if(TARGET ${lib}) + list(APPEND EXECUTORCH_LIBRARIES ${lib}) + else() + message("${lib} library is not found. + If needed rebuild with the proper options in CMakeLists.txt" + ) + endif() +endforeach() From 9a5096c068071706b160e75dbb43357c4e242530 Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Fri, 18 Jul 2025 18:06:59 -0700 Subject: [PATCH 5/7] Update [ghstack-poisoned] --- CMakeLists.txt | 15 +++++++++++++++ extension/llm/runner/CMakeLists.txt | 6 ------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ee191eaba3..73f339ce908 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -587,7 +587,22 @@ if(EXECUTORCH_BUILD_EXTENSION_MODULE) endif() if(EXECUTORCH_BUILD_EXTENSION_LLM) + if(EXECUTORCH_BUILD_EXTENSION_LLM_RUNNER) + set(SUPPORT_REGEX_LOOKAHEAD ON) + # llama/runner/CMakeLists.txt builds a shared library libllama_runner.so + # that transitively depends on tokenizers. Need to build tokenizers with + # -fPIC. + set(ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG + ${CMAKE_POSITION_INDEPENDENT_CODE} + ) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + endif() add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/llm/tokenizers) + if(EXECUTORCH_BUILD_EXTENSION_LLM_RUNNER) + set(CMAKE_POSITION_INDEPENDENT_CODE + ${ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG} + ) + endif() endif() if(EXECUTORCH_BUILD_EXTENSION_LLM_RUNNER) diff --git a/extension/llm/runner/CMakeLists.txt b/extension/llm/runner/CMakeLists.txt index 6e1dcdc3b46..c0f3c81a4ea 100644 --- a/extension/llm/runner/CMakeLists.txt +++ b/extension/llm/runner/CMakeLists.txt @@ -39,12 +39,6 @@ list(TRANSFORM _extension_llm_runner__srcs PREPEND "${EXECUTORCH_ROOT}/") add_library(extension_llm_runner STATIC ${_extension_llm_runner__srcs}) -# add tokenizers -set(SUPPORT_REGEX_LOOKAHEAD ON) -# llama/runner/CMakeLists.txt builds a shared library libllama_runner.so that -# transitively depends on tokenizers. Need to build tokenizers with -fPIC. -set(CMAKE_POSITION_INDEPENDENT_CODE ON) - set(runner_deps executorch_core extension_module extension_tensor tokenizers) target_link_libraries(extension_llm_runner PUBLIC ${runner_deps}) From 5d1580930e424c64c802c11e4e3d6642a79a0fdd Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Sun, 20 Jul 2025 23:03:45 -0700 Subject: [PATCH 6/7] fix unittest, bump size test threshold to account for op registration now showing up in the test [ghstack-poisoned] --- .github/workflows/pull.yml | 4 ++-- backends/vulkan/CMakeLists.txt | 6 +++--- backends/vulkan/cmake/ShaderLibrary.cmake | 4 ++-- backends/vulkan/test/CMakeLists.txt | 6 +++--- backends/vulkan/test/op_tests/CMakeLists.txt | 6 +++--- examples/models/phi-3-mini/CMakeLists.txt | 2 -- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml index 9e621329049..3ca2eb06d65 100644 --- a/.github/workflows/pull.yml +++ b/.github/workflows/pull.yml @@ -371,7 +371,7 @@ jobs: size=${arr[4]} # threshold=48120 on devserver with gcc11.4 # todo(lfq): update once binary size is below 50kb. - threshold="55584" + threshold="63776" if [[ "$size" -le "$threshold" ]]; then echo "Success $size <= $threshold" else @@ -406,7 +406,7 @@ jobs: output=$(ls -la cmake-out/test/size_test) arr=($output) size=${arr[4]} - threshold="51728" + threshold="51744" if [[ "$size" -le "$threshold" ]]; then echo "Success $size <= $threshold" else diff --git a/backends/vulkan/CMakeLists.txt b/backends/vulkan/CMakeLists.txt index 58688f2fe6c..da0d6b7145d 100644 --- a/backends/vulkan/CMakeLists.txt +++ b/backends/vulkan/CMakeLists.txt @@ -24,8 +24,8 @@ if(NOT RUNTIME_PATH) set(RUNTIME_PATH ${CMAKE_CURRENT_SOURCE_DIR}/runtime) endif() -# Include this file to access target_link_options_shared_lib This is required to -# provide access to target_link_options_shared_lib which allows libraries to be +# Include this file to access executorch_target_link_options_shared_lib This is required to +# provide access to executorch_target_link_options_shared_lib which allows libraries to be # linked with the --whole-archive flag. This is required for libraries that # perform dynamic registration via static initialization. include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) @@ -113,7 +113,7 @@ target_include_directories( target_link_libraries(vulkan_backend PRIVATE vulkan_schema executorch_core) target_compile_options(vulkan_backend PRIVATE ${VULKAN_CXX_FLAGS}) # Link this library with --whole-archive due to dynamic backend registration -target_link_options_shared_lib(vulkan_backend) +executorch_target_link_options_shared_lib(vulkan_backend) set_property(TARGET vulkan_backend PROPERTY CXX_STANDARD 17) diff --git a/backends/vulkan/cmake/ShaderLibrary.cmake b/backends/vulkan/cmake/ShaderLibrary.cmake index 9d92de9114e..c06a9d7097c 100644 --- a/backends/vulkan/cmake/ShaderLibrary.cmake +++ b/backends/vulkan/cmake/ShaderLibrary.cmake @@ -81,7 +81,7 @@ function(vulkan_shader_lib library_name generated_spv_cpp) target_link_libraries(${library_name} vulkan_backend) target_compile_options(${library_name} PRIVATE ${VULKAN_CXX_FLAGS}) # Link this library with --whole-archive due to dynamic shader registrations - target_link_options_shared_lib(${library_name}) + executorch_target_link_options_shared_lib(${library_name}) endfunction() # Convenience macro to generate a SPIR-V shader library target. Given the path @@ -105,7 +105,7 @@ macro(vulkan_shader_library shaders_path library_name) target_link_libraries(${library_name} vulkan_backend) target_compile_options(${library_name} PRIVATE ${VULKAN_CXX_FLAGS}) # Link this library with --whole-archive due to dynamic shader registrations - target_link_options_shared_lib(${library_name}) + executorch_target_link_options_shared_lib(${library_name}) unset(VULKAN_SHADERGEN_ENV) unset(VULKAN_SHADERGEN_OUT_PATH) diff --git a/backends/vulkan/test/CMakeLists.txt b/backends/vulkan/test/CMakeLists.txt index 0b3f22875ad..da25b6e88d1 100644 --- a/backends/vulkan/test/CMakeLists.txt +++ b/backends/vulkan/test/CMakeLists.txt @@ -35,8 +35,8 @@ if(TARGET vulkan_backend) set(PYTHON_EXECUTABLE python3) endif() - # Include this file to access target_link_options_shared_lib This is required - # to provide access to target_link_options_shared_lib which allows libraries + # Include this file to access executorch_target_link_options_shared_lib This is required + # to provide access to executorch_target_link_options_shared_lib which allows libraries # to be linked with the --whole-archive flag. This is required for libraries # that perform dynamic registration via static initialization. include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) @@ -75,7 +75,7 @@ if(TARGET vulkan_backend) ${CMAKE_CURRENT_SOURCE_DIR}/vulkan_compute_api_test.cpp ) - target_link_options_shared_lib(vulkan_backend) + executorch_target_link_options_shared_lib(vulkan_backend) add_executable( vulkan_compute_api_test ${COMPUTE_API_TEST_CPP} ${TEST_UTILS_CPP} diff --git a/backends/vulkan/test/op_tests/CMakeLists.txt b/backends/vulkan/test/op_tests/CMakeLists.txt index 59baafe3cef..c19e818f63d 100644 --- a/backends/vulkan/test/op_tests/CMakeLists.txt +++ b/backends/vulkan/test/op_tests/CMakeLists.txt @@ -29,8 +29,8 @@ if(NOT EXECUTORCH_ROOT) set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../..) endif() -# Include this file to access target_link_options_shared_lib This is required to -# provide access to target_link_options_shared_lib which allows libraries to be +# Include this file to access executorch_target_link_options_shared_lib This is required to +# provide access to executorch_target_link_options_shared_lib which allows libraries to be # linked with the --whole-archive flag. This is required for libraries that # perform dynamic registration via static initialization. include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) @@ -66,7 +66,7 @@ set(COMMON_INCLUDES ${TORCH_BASE_PATH}/include/torch/csrc/api/include ) -target_link_options_shared_lib(vulkan_backend) +executorch_target_link_options_shared_lib(vulkan_backend) function(vulkan_op_test test_name test_src) set(extra_deps ${ARGN}) diff --git a/examples/models/phi-3-mini/CMakeLists.txt b/examples/models/phi-3-mini/CMakeLists.txt index 4c7ccbc8d5c..4e55d4f9cb0 100644 --- a/examples/models/phi-3-mini/CMakeLists.txt +++ b/examples/models/phi-3-mini/CMakeLists.txt @@ -27,8 +27,6 @@ set(_common_include_directories list(APPEND CMAKE_FIND_ROOT_PATH ${CMAKE_CURRENT_BINARY_DIR}/../../..) find_package(executorch CONFIG REQUIRED FIND_ROOT_PATH_BOTH) -executorch_target_link_options_shared_lib(executorch) - set(BUILD_TESTING OFF) if(NOT TARGET extension_llm_runner) message( From 980279b1c53b4e7857743e25e87784a261fec615 Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Mon, 21 Jul 2025 09:28:05 -0700 Subject: [PATCH 7/7] Update [ghstack-poisoned] --- CMakeLists.txt | 6 ++++++ backends/vulkan/CMakeLists.txt | 22 +++++++++++++--------- test/CMakeLists.txt | 7 +++---- test/build_size_test.sh | 4 ++-- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d0c246bdc0b..bb145da5836 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -570,6 +570,12 @@ endif() if(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/data_loader) + install( + DIRECTORY extension/data_loader/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/extension/data_loader + FILES_MATCHING + PATTERN "*.h" + ) endif() if(EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR) diff --git a/backends/vulkan/CMakeLists.txt b/backends/vulkan/CMakeLists.txt index da0d6b7145d..cb1b8a06afd 100644 --- a/backends/vulkan/CMakeLists.txt +++ b/backends/vulkan/CMakeLists.txt @@ -24,10 +24,10 @@ if(NOT RUNTIME_PATH) set(RUNTIME_PATH ${CMAKE_CURRENT_SOURCE_DIR}/runtime) endif() -# Include this file to access executorch_target_link_options_shared_lib This is required to -# provide access to executorch_target_link_options_shared_lib which allows libraries to be -# linked with the --whole-archive flag. This is required for libraries that -# perform dynamic registration via static initialization. +# Include this file to access executorch_target_link_options_shared_lib This is +# required to provide access to executorch_target_link_options_shared_lib which +# allows libraries to be linked with the --whole-archive flag. This is required +# for libraries that perform dynamic registration via static initialization. include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) include(cmake/ShaderLibrary.cmake) @@ -40,8 +40,10 @@ set(VULKAN_HEADERS_PATH ${VULKAN_THIRD_PARTY_PATH}/Vulkan-Headers) set(VOLK_PATH ${VULKAN_THIRD_PARTY_PATH}/volk) set(VMA_PATH ${VULKAN_THIRD_PARTY_PATH}/VulkanMemoryAllocator) -set(COMMON_INCLUDES ${EXECUTORCH_ROOT}/.. ${VULKAN_HEADERS_PATH}/include - ${VOLK_PATH} ${VMA_PATH} +set(COMMON_INCLUDES + $ + $ + $ $ ) # Compile settings @@ -96,8 +98,10 @@ add_library(vulkan_schema INTERFACE ${GENERATED_HEADER}) set_target_properties(vulkan_schema PROPERTIES LINKER_LANGUAGE CXX) target_include_directories( - vulkan_schema INTERFACE ${SCHEMA_INCLUDE_DIR} - ${EXECUTORCH_ROOT}/third-party/flatbuffers/include + vulkan_schema + INTERFACE + ${SCHEMA_INCLUDE_DIR} + $ ) # vulkan_backend @@ -134,7 +138,7 @@ endif() # Test targets install( - TARGETS vulkan_backend + TARGETS vulkan_backend vulkan_schema EXPORT ExecuTorchTargets DESTINATION lib INCLUDES diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0e2f94bde19..68a641e9f6f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -26,11 +26,12 @@ set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) # Find prebuilt executorch library -find_package(executorch CONFIG REQUIRED) + +list(APPEND CMAKE_FIND_ROOT_PATH ${CMAKE_CURRENT_BINARY_DIR}/../) +find_package(executorch CONFIG REQUIRED FIND_ROOT_PATH_BOTH) # Let files say "include ". set(_common_include_directories ${EXECUTORCH_ROOT}/..) -target_include_directories(executorch INTERFACE ${_common_include_directories}) # # The `__srcs` lists are defined by including ${EXECUTORCH_SRCS_FILE}. @@ -60,7 +61,6 @@ endif() # size_test_all_ops: binary with portable ops and no delegate backend # add_executable(size_test_all_ops ${_size_test__srcs}) -executorch_target_link_options_shared_lib(portable_ops_lib) target_link_libraries( size_test_all_ops executorch portable_ops_lib portable_kernels ) @@ -73,7 +73,6 @@ endif() # if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED) add_executable(size_test_all_optimized_ops ${_size_test__srcs}) - executorch_target_link_options_shared_lib(optimized_native_cpu_ops_lib) target_link_libraries( size_test_all_optimized_ops executorch optimized_native_cpu_ops_lib ) diff --git a/test/build_size_test.sh b/test/build_size_test.sh index cccd42431c7..37612b5154c 100644 --- a/test/build_size_test.sh +++ b/test/build_size_test.sh @@ -6,7 +6,7 @@ # LICENSE file in the root directory of this source tree. # Build size_test and show the size of it -set -e +set -ex # shellcheck source=/dev/null source "$(dirname "${BASH_SOURCE[0]}")/../.ci/scripts/utils.sh" @@ -28,6 +28,7 @@ cmake_install_executorch_lib() { -DCMAKE_INSTALL_PREFIX=cmake-out \ -DCMAKE_BUILD_TYPE=Release \ -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=OFF \ + -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \ -DEXECUTORCH_OPTIMIZE_SIZE=ON \ -DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \ ${EXTRA_BUILD_ARGS} \ @@ -37,7 +38,6 @@ cmake_install_executorch_lib() { test_cmake_size_test() { CXXFLAGS="$COMMON_CXXFLAGS" retry cmake -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_PREFIX_PATH=cmake-out \ -DCMAKE_INSTALL_PREFIX=cmake-out \ ${EXTRA_BUILD_ARGS} \ -Bcmake-out/test test