|
| 1 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 | +# All rights reserved. |
| 3 | +# |
| 4 | +# This source code is licensed under the BSD-style license found in the |
| 5 | +# LICENSE file in the root directory of this source tree. |
| 6 | + |
| 7 | +cmake_minimum_required(VERSION 3.26) |
| 8 | +project(executorch_native_wheel LANGUAGES C CXX) |
| 9 | + |
| 10 | +if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux") |
| 11 | + message(FATAL_ERROR "The Native SDK wheel currently supports Linux only") |
| 12 | +endif() |
| 13 | + |
| 14 | +get_filename_component( |
| 15 | + EXECUTORCH_ROOT "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE |
| 16 | +) |
| 17 | +set(BUILD_SHARED_LIBS OFF) |
| 18 | +set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
| 19 | +set(CMAKE_INSTALL_LIBDIR lib) |
| 20 | +set(EXECUTORCH_OPTIMIZE_SIZE OFF) |
| 21 | +set(EXECUTORCH_BUILD_NATIVE ON) |
| 22 | +set(EXECUTORCH_BUILD_NATIVE_VULKAN ON) |
| 23 | +set(EXECUTORCH_BUILD_NATIVE_GGML ON) |
| 24 | +set(EXECUTORCH_BUILD_NATIVE_VISION_RUNNER OFF) |
| 25 | +set(EXECUTORCH_BUILD_SHARED OFF) |
| 26 | +set(EXECUTORCH_BUILD_XNNPACK OFF) |
| 27 | +set(EXECUTORCH_BUILD_VULKAN OFF) |
| 28 | +set(EXECUTORCH_BUILD_EXECUTOR_RUNNER OFF) |
| 29 | +set(EXECUTORCH_BUILD_PYBIND OFF) |
| 30 | +set(EXECUTORCH_BUILD_TESTS OFF) |
| 31 | +set(EXECUTORCH_BUILD_CPUINFO OFF) |
| 32 | +set(EXECUTORCH_BUILD_PTHREADPOOL OFF) |
| 33 | +set(EXECUTORCH_BUILD_PORTABLE_OPS OFF) |
| 34 | +set(BUILD_TESTING OFF) |
| 35 | +foreach( |
| 36 | + feature |
| 37 | + NATIVE |
| 38 | + AVX |
| 39 | + AVX2 |
| 40 | + AVX_VNNI |
| 41 | + BMI2 |
| 42 | + FMA |
| 43 | + F16C |
| 44 | + AVX512 |
| 45 | + AVX512_VBMI |
| 46 | + AVX512_VNNI |
| 47 | + AVX512_BF16 |
| 48 | + AMX_TILE |
| 49 | + AMX_INT8 |
| 50 | + AMX_BF16 |
| 51 | +) |
| 52 | + set(GGML_${feature} |
| 53 | + OFF |
| 54 | + CACHE BOOL "Portable wheel CPU baseline" FORCE |
| 55 | + ) |
| 56 | +endforeach() |
| 57 | + |
| 58 | +set(GGML_BACKEND_DL OFF) |
| 59 | +set(GGML_CPU ON) |
| 60 | +set(GGML_OPENMP OFF) |
| 61 | + |
| 62 | +add_subdirectory("${EXECUTORCH_ROOT}" executorch EXCLUDE_FROM_ALL) |
| 63 | + |
| 64 | +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/sdk.cpp" "") |
| 65 | +add_library(executorch_native_sdk SHARED "${CMAKE_CURRENT_BINARY_DIR}/sdk.cpp") |
| 66 | +target_link_libraries( |
| 67 | + executorch_native_sdk |
| 68 | + PRIVATE |
| 69 | + "$<LINK_LIBRARY:WHOLE_ARCHIVE,native_api,native_engine,native_runtime,native_package,native_graph,native_vulkan_engine,native_ggml_engine>" |
| 70 | +) |
| 71 | +target_compile_features(executorch_native_sdk INTERFACE cxx_std_20) |
| 72 | +target_include_directories( |
| 73 | + executorch_native_sdk INTERFACE $<INSTALL_INTERFACE:include> |
| 74 | +) |
| 75 | +target_link_options( |
| 76 | + executorch_native_sdk PRIVATE |
| 77 | + "LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports.map" |
| 78 | + "LINKER:--no-undefined" "LINKER:--gc-sections" |
| 79 | +) |
| 80 | +set_target_properties( |
| 81 | + executorch_native_sdk |
| 82 | + PROPERTIES |
| 83 | + OUTPUT_NAME executorch_native |
| 84 | + EXPORT_NAME runtime |
| 85 | + INSTALL_RPATH "$ORIGIN" |
| 86 | + LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/exports.map" |
| 87 | + LINK_LIBRARY_OVERRIDE |
| 88 | + "WHOLE_ARCHIVE,native_api,native_engine,native_runtime,native_package,native_graph,native_vulkan_engine,native_ggml_engine" |
| 89 | +) |
| 90 | + |
| 91 | +add_subdirectory(../pybindings pybindings) |
| 92 | + |
| 93 | +install( |
| 94 | + TARGETS executorch_native_sdk |
| 95 | + EXPORT ExecuTorchNativeTargets |
| 96 | + LIBRARY DESTINATION lib COMPONENT executorch_native |
| 97 | +) |
| 98 | +install( |
| 99 | + EXPORT ExecuTorchNativeTargets |
| 100 | + NAMESPACE executorch_native:: |
| 101 | + DESTINATION lib/cmake/executorch_native |
| 102 | + COMPONENT executorch_native |
| 103 | +) |
| 104 | +install( |
| 105 | + FILES executorch_native-config.cmake |
| 106 | + DESTINATION lib/cmake/executorch_native |
| 107 | + COMPONENT executorch_native |
| 108 | +) |
| 109 | +install( |
| 110 | + DIRECTORY ../runtime/ |
| 111 | + DESTINATION include/executorch/backends/native/runtime |
| 112 | + COMPONENT executorch_native |
| 113 | + FILES_MATCHING |
| 114 | + PATTERN "*.h" |
| 115 | + PATTERN "test" EXCLUDE |
| 116 | + PATTERN "vulkan" EXCLUDE |
| 117 | + PATTERN "ggml" EXCLUDE |
| 118 | + PATTERN "Json.h" EXCLUDE |
| 119 | +) |
| 120 | +install( |
| 121 | + FILES ../runtime/vulkan/VulkanEngine.h |
| 122 | + DESTINATION include/executorch/backends/native/runtime/vulkan |
| 123 | + COMPONENT executorch_native |
| 124 | +) |
| 125 | +install( |
| 126 | + FILES ../runtime/engine/ggml/GgmlEngine.h |
| 127 | + DESTINATION include/executorch/backends/native/runtime/engine/ggml |
| 128 | + COMPONENT executorch_native |
| 129 | +) |
| 130 | +install( |
| 131 | + DIRECTORY ../examples/vision ../examples/runner_utils |
| 132 | + DESTINATION share/examples |
| 133 | + COMPONENT executorch_native |
| 134 | + FILES_MATCHING |
| 135 | + PATTERN "CMakeLists.txt" |
| 136 | + PATTERN "run_classification.cpp" |
| 137 | + PATTERN "runner_utils.cpp" |
| 138 | + PATTERN "runner_utils.h" |
| 139 | +) |
| 140 | +install( |
| 141 | + FILES ../examples/runner_utils/runner_utils.h |
| 142 | + DESTINATION include/executorch/backends/native/examples/runner_utils |
| 143 | + COMPONENT executorch_native |
| 144 | +) |
| 145 | +install( |
| 146 | + FILES "${EXECUTORCH_ROOT}/LICENSE" |
| 147 | + DESTINATION share/licenses |
| 148 | + COMPONENT executorch_native |
| 149 | +) |
| 150 | +install( |
| 151 | + FILES "${EXECUTORCH_ROOT}/backends/native/third-party/llama.cpp/LICENSE" |
| 152 | + DESTINATION share/licenses/ggml |
| 153 | + COMPONENT executorch_native |
| 154 | +) |
| 155 | +foreach( |
| 156 | + license |
| 157 | + third-party/flatbuffers/LICENSE |
| 158 | + third-party/json/LICENSE.MIT |
| 159 | + backends/vulkan/third-party/volk/LICENSE.md |
| 160 | + backends/vulkan/third-party/Vulkan-Headers/LICENSE.md |
| 161 | + backends/vulkan/third-party/VulkanMemoryAllocator/LICENSE.txt |
| 162 | +) |
| 163 | + get_filename_component(dependency "${license}" DIRECTORY) |
| 164 | + install( |
| 165 | + FILES "${EXECUTORCH_ROOT}/${license}" |
| 166 | + DESTINATION "share/licenses/${dependency}" |
| 167 | + COMPONENT executorch_native |
| 168 | + ) |
| 169 | +endforeach() |
| 170 | + |
| 171 | +set(EXECUTORCH_NATIVE_EXTRA_LICENSES |
| 172 | + "" |
| 173 | + CACHE STRING "License files for external libraries bundled into the wheel" |
| 174 | +) |
| 175 | +foreach(license IN LISTS EXECUTORCH_NATIVE_EXTRA_LICENSES) |
| 176 | + get_filename_component(dependency "${license}" DIRECTORY) |
| 177 | + get_filename_component(dependency "${dependency}" NAME) |
| 178 | + install( |
| 179 | + FILES "${license}" |
| 180 | + DESTINATION "share/licenses/dependencies/${dependency}" |
| 181 | + COMPONENT executorch_native |
| 182 | + ) |
| 183 | +endforeach() |
0 commit comments