Skip to content

Commit 36c21bd

Browse files
shoumikhinfacebook-github-bot
authored andcommitted
Build Apple extensions with CMake. (#2336)
Summary: Pull Request resolved: #2336 bypass-github-export-checks Reviewed By: cccclai Differential Revision: D54711005 fbshipit-source-id: 88dbcba890080d584d0c3f23f2be2e235d2956e9
1 parent 7f30119 commit 36c21bd

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,10 @@ if(EXECUTORCH_BUILD_SDK)
340340
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/sdk)
341341
endif()
342342

343+
if(EXECUTORCH_BUILD_EXTENSION_APPLE)
344+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/apple)
345+
endif()
346+
343347
if(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER)
344348
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/data_loader)
345349
endif()

build/build_apple_frameworks.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ MPS=OFF
2222
PORTABLE=OFF
2323
XNNPACK=OFF
2424
HEADERS_PATH="include"
25-
EXECUTORCH_FRAMEWORK="executorch:libexecutorch.a,libextension_data_loader.a,libextension_module.a:$HEADERS_PATH"
25+
EXECUTORCH_FRAMEWORK="executorch:libexecutorch.a,libextension_apple.a,libextension_data_loader.a,libextension_module.a:$HEADERS_PATH"
2626
COREML_FRAMEWORK="coreml_backend:libcoremldelegate.a:"
2727
MPS_FRAMEWORK="mps_backend:libmpsdelegate.a:"
2828
PORTABLE_FRAMEWORK="portable_backend:libportable_kernels.a,libportable_ops_lib.a:"
@@ -115,6 +115,7 @@ cmake_build() {
115115
-DBUCK2="$BUCK2" \
116116
-DPYTHON_EXECUTABLE="$PYTHON" \
117117
-DFLATC_EXECUTABLE="$FLATC" \
118+
-DEXECUTORCH_BUILD_EXTENSION_APPLE=ON \
118119
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
119120
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
120121
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY="$(pwd)" \
@@ -139,6 +140,8 @@ mkdir -p "$HEADERS_PATH"
139140
//extension/module: \
140141
| rsync -av --files-from=- "$SOURCE_ROOT_DIR" "$HEADERS_PATH/executorch"
141142

143+
cp "$SOURCE_ROOT_DIR/extension/apple/ExecuTorch/Exported/"{*.h,*.modulemap} "$HEADERS_PATH"
144+
142145
echo "Creating frameworks"
143146

144147
for platform in "${PLATFORMS[@]}"; do

extension/apple/CMakeLists.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
# Please this file formatted by running:
8+
# ~~~
9+
# cmake-format --first-comment-is-literal=True CMakeLists.txt
10+
# ~~~
11+
12+
cmake_minimum_required(VERSION 3.19)
13+
14+
# Source root directory for executorch.
15+
if(NOT EXECUTORCH_ROOT)
16+
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
17+
endif()
18+
19+
add_library(extension_apple)
20+
21+
set(EXPORTED_SOURCES
22+
ExecuTorch/Exported/ExecuTorchLog.mm
23+
)
24+
25+
target_sources(
26+
extension_apple PRIVATE
27+
${EXPORTED_SOURCES}
28+
)
29+
30+
target_include_directories(
31+
extension_apple PUBLIC
32+
ExecuTorch/Exported
33+
)
34+
35+
find_library(FOUNDATION_FRAMEWORK Foundation)
36+
target_link_libraries(extension_apple
37+
PRIVATE
38+
executorch
39+
${FOUNDATION_FRAMEWORK}
40+
)
41+
42+
target_compile_options(extension_apple PUBLIC ${_common_compile_options})
43+
target_compile_options(extension_apple PRIVATE "-fobjc-arc")
44+
target_compile_options(extension_apple PRIVATE "-fno-exceptions")
45+
target_compile_options(extension_apple PRIVATE "-fno-rtti")
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module ExecuTorch {
2+
umbrella header "ExecuTorch.h"
3+
4+
export *
5+
module * { export * }
6+
}

0 commit comments

Comments
 (0)