Skip to content
Closed
Show file tree
Hide file tree
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
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
25 changes: 16 additions & 9 deletions build/build_apple_frameworks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@ PLATFORMS=("iphoneos" "iphonesimulator")
PLATFORM_FLAGS=("OS" "SIMULATOR")
SOURCE_ROOT_DIR=""
OUTPUT="cmake-out"
MODE="Debug"
MODE="Release"
TOOLCHAIN=""
BUCK2="/tmp/buck2"
PYTHON=$(which python3)
FLATC=""
IOS_DEPLOYMENT_TARGET="17.0"
COREML=OFF
MPS=OFF
PORTABLE=OFF
XNNPACK=OFF
HEADERS_PATH="include"
EXECUTORCH_FRAMEWORK="executorch:libexecutorch.a,libextension_data_loader.a,libextension_module.a:$HEADERS_PATH"
PORTABLE_FRAMEWORK="portable_backend:libportable_kernels.a,libportable_ops_lib.a:"
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:"
XNNPACK_FRAMEWORK="xnnpack_backend:libXNNPACK.a,libcpuinfo.a,libpthreadpool.a,libxnnpack_backend.a:"

usage() {
Expand All @@ -34,14 +35,15 @@ usage() {
echo
echo "Options:"
echo " --output=DIR Output directory. Default: 'cmake-out'"
echo " --Release Use Release build mode. Default: 'Debug'"
echo " --Debug Use Debug build mode. Default: 'Release'"
echo " --toolchain=FILE Cmake toolchain file. Default: '\$SOURCE_ROOT_DIR/third-party/pytorch/cmake/iOS.cmake'"
echo " --buck2=FILE Buck2 executable path. Default: '/tmp/buck2'"
echo " --python=FILE Python executable path. Default: Path of python3 found in the current \$PATH"
echo " --flatc=FILE FlatBuffers Compiler executable path. Default: '\$SOURCE_ROOT_DIR/third-party/flatbuffers/cmake-out/flatc'"
echo " --coreml Include this flag to build Core ML backend."
echo " --mps Include this flag to build Metal Performance Shaders backend."
echo " --xnnpack Include this flag to build XNNPACK backend."
echo " --coreml Include this flag to build the Core ML backend."
echo " --mps Include this flag to build the Metal Performance Shaders backend."
echo " --portable Include this flag to build the Portable backend."
echo " --xnnpack Include this flag to build the XNNPACK backend."
echo
echo "Example:"
echo " $0 /path/to/source/root --output=cmake-out --Release --toolchain=/path/to/cmake/toolchain --buck2=/path/to/buck2 --python=/path/to/python3 --coreml --mps --xnnpack"
Expand All @@ -52,13 +54,14 @@ for arg in "$@"; do
case $arg in
-h|--help) usage ;;
--output=*) OUTPUT="${arg#*=}" ;;
--Release) MODE="Release" ;;
--Debug) MODE="Debug" ;;
--toolchain=*) TOOLCHAIN="${arg#*=}" ;;
--buck2=*) BUCK2="${arg#*=}" ;;
--python=*) PYTHON="${arg#*=}" ;;
--flatc=*) FLATC="${arg#*=}" ;;
--ios-deployment-target=*) IOS_DEPLOYMENT_TARGET="${arg#*=}" ;;
--coreml) COREML=ON ;;
--portable) PORTABLE=ON ;;
--mps) MPS=ON ;;
--xnnpack) XNNPACK=ON ;;
*)
Expand Down Expand Up @@ -105,12 +108,14 @@ cmake_build() {
echo "Building for $platform with flag $platform_flag"
mkdir "$platform" && cd "$platform" || exit 1
cmake "$SOURCE_ROOT_DIR" -G Xcode \
-DCMAKE_BUILD_TYPE="$MODE" \
-DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN" \
-DCMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD="c++17" \
-DCMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY="libc++" \
-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 @@ -135,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 All @@ -152,7 +159,7 @@ append_framework_flag() {
}

append_framework_flag "ON" "$EXECUTORCH_FRAMEWORK"
append_framework_flag "ON" "$PORTABLE_FRAMEWORK"
append_framework_flag "$PORTABLE" "$PORTABLE_FRAMEWORK"
append_framework_flag "$COREML" "$COREML_FRAMEWORK"
append_framework_flag "$MPS" "$MPS_FRAMEWORK"
append_framework_flag "$XNNPACK" "$XNNPACK_FRAMEWORK"
Expand Down
2 changes: 1 addition & 1 deletion build/test_ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ curl https://github.com/raw/pytorch/hub/master/imagenet_classes.txt \

say "Building Frameworks"

./build/build_apple_frameworks.sh --buck2="$(realpath $BUCK2)" --Release --coreml --mps --xnnpack
./build/build_apple_frameworks.sh --buck2="$(realpath $BUCK2)" --coreml --mps --portable --xnnpack
mv cmake-out "$APP_PATH/Frameworks"

say "Creating Simulator"
Expand Down
2 changes: 1 addition & 1 deletion build/test_ios_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ curl https://github.com/raw/pytorch/hub/master/imagenet_classes.txt \

say "Building Frameworks"

./build/build_apple_frameworks.sh --buck2="$(which buck2)" --flatc="$(which flatc)" --coreml --mps --xnnpack
./build/build_apple_frameworks.sh --buck2="$(which buck2)" --flatc="$(which flatc)" --coreml --mps --portable --xnnpack
mv cmake-out "$APP_PATH/Frameworks"

say "Creating Simulator"
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 * }
}