Skip to content

Commit

Permalink
Build Apple extensions with CMake. (pytorch#2336)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#2336
bypass-github-export-checks

Reviewed By: cccclai

Differential Revision: D54711005

fbshipit-source-id: 88dbcba890080d584d0c3f23f2be2e235d2956e9
  • Loading branch information
shoumikhin authored and facebook-github-bot committed Mar 9, 2024
1 parent 7f30119 commit 36c21bd
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ if(EXECUTORCH_BUILD_SDK)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/sdk)
endif()

if(EXECUTORCH_BUILD_EXTENSION_APPLE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/apple)
endif()

if(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/data_loader)
endif()
Expand Down
5 changes: 4 additions & 1 deletion build/build_apple_frameworks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ MPS=OFF
PORTABLE=OFF
XNNPACK=OFF
HEADERS_PATH="include"
EXECUTORCH_FRAMEWORK="executorch:libexecutorch.a,libextension_data_loader.a,libextension_module.a:$HEADERS_PATH"
EXECUTORCH_FRAMEWORK="executorch:libexecutorch.a,libextension_apple.a,libextension_data_loader.a,libextension_module.a:$HEADERS_PATH"
COREML_FRAMEWORK="coreml_backend:libcoremldelegate.a:"
MPS_FRAMEWORK="mps_backend:libmpsdelegate.a:"
PORTABLE_FRAMEWORK="portable_backend:libportable_kernels.a,libportable_ops_lib.a:"
Expand Down Expand Up @@ -115,6 +115,7 @@ cmake_build() {
-DBUCK2="$BUCK2" \
-DPYTHON_EXECUTABLE="$PYTHON" \
-DFLATC_EXECUTABLE="$FLATC" \
-DEXECUTORCH_BUILD_EXTENSION_APPLE=ON \
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY="$(pwd)" \
Expand All @@ -139,6 +140,8 @@ mkdir -p "$HEADERS_PATH"
//extension/module: \
| rsync -av --files-from=- "$SOURCE_ROOT_DIR" "$HEADERS_PATH/executorch"

cp "$SOURCE_ROOT_DIR/extension/apple/ExecuTorch/Exported/"{*.h,*.modulemap} "$HEADERS_PATH"

echo "Creating frameworks"

for platform in "${PLATFORMS[@]}"; do
Expand Down
45 changes: 45 additions & 0 deletions extension/apple/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

# Please this file formatted by running:
# ~~~
# cmake-format --first-comment-is-literal=True CMakeLists.txt
# ~~~

cmake_minimum_required(VERSION 3.19)

# Source root directory for executorch.
if(NOT EXECUTORCH_ROOT)
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
endif()

add_library(extension_apple)

set(EXPORTED_SOURCES
ExecuTorch/Exported/ExecuTorchLog.mm
)

target_sources(
extension_apple PRIVATE
${EXPORTED_SOURCES}
)

target_include_directories(
extension_apple PUBLIC
ExecuTorch/Exported
)

find_library(FOUNDATION_FRAMEWORK Foundation)
target_link_libraries(extension_apple
PRIVATE
executorch
${FOUNDATION_FRAMEWORK}
)

target_compile_options(extension_apple PUBLIC ${_common_compile_options})
target_compile_options(extension_apple PRIVATE "-fobjc-arc")
target_compile_options(extension_apple PRIVATE "-fno-exceptions")
target_compile_options(extension_apple PRIVATE "-fno-rtti")
6 changes: 6 additions & 0 deletions extension/apple/ExecuTorch/Exported/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module ExecuTorch {
umbrella header "ExecuTorch.h"

export *
module * { export * }
}

0 comments on commit 36c21bd

Please sign in to comment.