Skip to content

Add top-level CMake extensions target #12696

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 24 commits into from
Jul 29, 2025
Merged
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
30 changes: 20 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,9 @@ add_library(executorch_no_prim_ops ALIAS executorch_core)
# A list of all configured backends.
set(_executorch_backends "")

# A list of all configured extensions.
set(_executorch_extensions "")

target_link_libraries(executorch_core PRIVATE program_schema)
if(ANDROID)
target_link_libraries(executorch_core PUBLIC log)
Expand Down Expand Up @@ -579,6 +582,7 @@ endif()

if(EXECUTORCH_BUILD_EXTENSION_APPLE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/apple)
list(APPEND _executorch_extensions apple_extension)
endif()

if(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER)
Expand All @@ -589,6 +593,7 @@ if(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER)
FILES_MATCHING
PATTERN "*.h"
)
list(APPEND _executorch_extensions extension_data_loader)
endif()

if(EXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL)
Expand All @@ -603,6 +608,7 @@ endif()

if(EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/flat_tensor)
list(APPEND _executorch_extensions extension_flat_tensor)
endif()

if(EXECUTORCH_BUILD_EXTENSION_MODULE)
Expand All @@ -613,6 +619,7 @@ if(EXECUTORCH_BUILD_EXTENSION_MODULE)
FILES_MATCHING
PATTERN "*.h"
)
list(APPEND _executorch_extensions extension_module_static)
endif()

if(EXECUTORCH_BUILD_EXTENSION_LLM)
Expand All @@ -632,14 +639,17 @@ if(EXECUTORCH_BUILD_EXTENSION_LLM)
${ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG}
)
endif()
list(APPEND _executorch_extensions tokenizers)
endif()

if(EXECUTORCH_BUILD_EXTENSION_LLM_RUNNER)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/llm/runner)
list(APPEND _executorch_extensions extension_llm_runner)
endif()

if(EXECUTORCH_BUILD_EXTENSION_LLM_APPLE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/llm/apple)
list(APPEND _executorch_extensions extension_llm_apple)
endif()

if(EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL)
Expand All @@ -650,10 +660,12 @@ if(EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL)
FILES_MATCHING
PATTERN "*.h"
)
list(APPEND _executorch_extensions extension_runner_util)
endif()

if(EXECUTORCH_BUILD_EXTENSION_TENSOR)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/tensor)
list(APPEND _executorch_extensions extension_tensor)
endif()

if(EXECUTORCH_BUILD_PTHREADPOOL AND EXECUTORCH_BUILD_CPUINFO)
Expand Down Expand Up @@ -756,6 +768,7 @@ endif()

if(EXECUTORCH_BUILD_EXTENSION_TRAINING)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/training)
list(APPEND _executorch_extensions extension_training)
endif()

if(EXECUTORCH_BUILD_KERNELS_LLM)
Expand All @@ -778,25 +791,22 @@ if(EXECUTORCH_BUILD_VGF)
list(APPEND _executorch_backends vgf_backend)
endif()


# Top-level interface targets.
add_library(executorch_backends INTERFACE)
add_library(executorch::backends ALIAS executorch_backends)

# A target containing all configured backends.
add_library(executorch_backends INTERFACE)
add_library(executorch::backends ALIAS executorch_backends)
target_link_libraries(executorch_backends INTERFACE ${_executorch_backends})

install(
TARGETS executorch_backends
INCLUDES
DESTINATION ${_common_include_directories}
)
# A target containing all configured extensions.
add_library(executorch_extensions INTERFACE)
Copy link
Contributor

@swolchok swolchok Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please include executorch_backends and executorch_extensions in the install() call alongside executorch and executorch_core so that we don't have to coordinate with the EXPORT PR? that should be enough to get it to work no matter which one lands first

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated to install these targets. Because of the order of declarations in the file, I can't directly add to the existing executorch / executorch_core install, as it is above many of the backend declarations. To avoid causing a bunch of merge conflicts by rearranging it, I've added an install for these new targets alone. I can add the export directive once #8954 is merged.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you change an example to use these targets, CI will prevent us from messing it up in the future and give this diff coverage

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated executor_runner to use the top-level backends and extensions targets. I'll update examples with the export changes, as well.

add_library(executorch::extensions ALIAS executorch_extensions)
target_link_libraries(executorch_extensions INTERFACE ${_executorch_extensions})

if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)
# Baseline libraries that executor_runner will link against.
set(_executor_runner_libs executorch extension_evalue_util
extension_runner_util gflags
executorch_backends
extension_runner_util gflags executorch_backends
)

if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
Expand Down
Loading