Skip to content

Commit

Permalink
Support tvOS
Browse files Browse the repository at this point in the history
  • Loading branch information
hans00 committed Aug 20, 2024
1 parent c048b30 commit dc73bc9
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1710,8 +1710,8 @@ if (onnxruntime_USE_WINML)
endif() # if (onnxruntime_USE_WINML)

if (onnxruntime_BUILD_SHARED_LIB OR onnxruntime_BUILD_APPLE_FRAMEWORK)
if (onnxruntime_BUILD_APPLE_FRAMEWORK AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS|visionOS")
message(FATAL_ERROR "onnxruntime_BUILD_APPLE_FRAMEWORK can only be enabled for macOS or iOS or visionOS.")
if (onnxruntime_BUILD_APPLE_FRAMEWORK AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS|visionOS|tvOS")
message(FATAL_ERROR "onnxruntime_BUILD_APPLE_FRAMEWORK can only be enabled for macOS or iOS or visionOS or tvOS.")
endif()
list(APPEND ONNXRUNTIME_CMAKE_FILES onnxruntime)
endif()
Expand Down
4 changes: 2 additions & 2 deletions cmake/adjust_global_compile_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
endif()
endif()

# Mark symbols to be invisible, for macOS/iOS/visionOS target only
# Mark symbols to be invisible, for macOS/iOS/visionOS/tvOS target only
# Due to many dependencies have different symbol visibility settings, set global compile flags here.
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS|visionOS")
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS|visionOS|tvOS")
foreach(flags CMAKE_CXX_FLAGS CMAKE_OBJC_FLAGS CMAKE_OBJCXX_FLAGS)
string(APPEND ${flags} " -fvisibility=hidden -fvisibility-inlines-hidden")
endforeach()
Expand Down
2 changes: 1 addition & 1 deletion cmake/onnxruntime_providers_cpu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ set_target_properties(onnxruntime_providers PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(onnxruntime_providers PROPERTIES FOLDER "ONNXRuntime")

if (NOT onnxruntime_MINIMAL_BUILD AND NOT onnxruntime_EXTENDED_MINIMAL_BUILD
AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS|visionOS"
AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS|visionOS|tvOS"
AND NOT CMAKE_SYSTEM_NAME STREQUAL "Android"
AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
file(GLOB onnxruntime_providers_shared_cc_srcs CONFIGURE_DEPENDS
Expand Down
2 changes: 1 addition & 1 deletion cmake/onnxruntime_python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ if (onnxruntime_ENABLE_EXTERNAL_CUSTOM_OP_SCHEMAS)
endif()

if (NOT onnxruntime_MINIMAL_BUILD AND NOT onnxruntime_EXTENDED_MINIMAL_BUILD
AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS|visionOS"
AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS|visionOS|tvOS"
AND NOT CMAKE_SYSTEM_NAME STREQUAL "Android"
AND NOT onnxruntime_USE_ROCM
AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
Expand Down
12 changes: 12 additions & 0 deletions cmake/onnxruntime_tvos.toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

set(CMAKE_SYSTEM_NAME tvOS)
set(CMAKE_SYSTEM_PROCESSOR arm64)

if (NOT DEFINED CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM AND NOT DEFINED CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY)
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED NO)
endif()

SET(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_MODULES "YES")
SET(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC "YES")
2 changes: 1 addition & 1 deletion cmake/onnxruntime_unittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1747,7 +1747,7 @@ endif()

# limit to only test on windows first, due to a runtime path issue on linux
if (NOT onnxruntime_MINIMAL_BUILD AND NOT onnxruntime_EXTENDED_MINIMAL_BUILD
AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS|visionOS"
AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS|visionOS|tvOS"
AND NOT CMAKE_SYSTEM_NAME STREQUAL "Android"
AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten"
AND NOT onnxruntime_USE_ROCM)
Expand Down
20 changes: 16 additions & 4 deletions tools/ci_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ def convert_arg_line_to_args(self, arg_line):
platform_group = parser.add_mutually_exclusive_group()
platform_group.add_argument("--ios", action="store_true", help="build for ios")
platform_group.add_argument("--visionos", action="store_true", help="build for visionOS")
platform_group.add_argument("--tvos", action="store_true", help="build for tvOS")
platform_group.add_argument(
"--macos",
choices=["MacOSX", "Catalyst"],
Expand All @@ -421,6 +422,11 @@ def convert_arg_line_to_args(self, arg_line):
default="",
help="Path to visionos toolchain file, or cmake/onnxruntime_visionos.toolchain.cmake will be used",
)
parser.add_argument(
"--tvos_toolchain_file",
default="",
help="Path to tvos toolchain file, or cmake/onnxruntime_tvos.toolchain.cmake will be used",
)
parser.add_argument(
"--xcode_code_signing_team_id", default="", help="The development team ID used for code signing in Xcode"
)
Expand Down Expand Up @@ -898,7 +904,7 @@ def use_dev_mode(args):
return False
if args.use_armnn:
return False
if (args.ios or args.visionos) and is_macOS():
if (args.ios or args.visionos or args.tvos) and is_macOS():
return False
SYSTEM_COLLECTIONURI = os.getenv("SYSTEM_COLLECTIONURI") # noqa: N806
if SYSTEM_COLLECTIONURI and SYSTEM_COLLECTIONURI != "https://dev.azure.com/onnxruntime/":
Expand Down Expand Up @@ -1313,12 +1319,12 @@ def generate_build_tree(
if args.use_snpe:
cmake_args += ["-Donnxruntime_USE_SNPE=ON"]

if args.macos or args.ios or args.visionos:
if args.macos or args.ios or args.visionos or args.tvos:
# Note: Xcode CMake generator doesn't have a good support for Mac Catalyst yet.
if args.macos == "Catalyst" and args.cmake_generator == "Xcode":
raise BuildError("Xcode CMake generator ('--cmake_generator Xcode') doesn't support Mac Catalyst build.")

if (args.ios or args.visionos or args.macos == "MacOSX") and not args.cmake_generator == "Xcode":
if (args.ios or args.visionos or args.tvos or args.macos == "MacOSX") and not args.cmake_generator == "Xcode":
raise BuildError(
"iOS/MacOS framework build requires use of the Xcode CMake generator ('--cmake_generator Xcode')."
)
Expand Down Expand Up @@ -1378,6 +1384,12 @@ def generate_build_tree(
),
"-Donnxruntime_ENABLE_CPUINFO=OFF",
]
if args.tvos:
cmake_args += [
"-DCMAKE_SYSTEM_NAME=tvOS",
"-DCMAKE_TOOLCHAIN_FILE="
+ (args.tvos_toolchain_file if args.tvos_toolchain_file else "../cmake/onnxruntime_tvos.toolchain.cmake"),
]

if args.build_wasm:
emsdk_dir = os.path.join(cmake_dir, "external", "emsdk")
Expand Down Expand Up @@ -2788,7 +2800,7 @@ def main():

if is_macOS():
if (
not (args.ios or args.visionos)
not (args.ios or args.visionos or args.tvos)
and args.macos != "Catalyst"
and not args.android
and args.osx_arch == "arm64"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"build_osx_archs": {
"appletvos": [
"arm64"
],
"appletvsimulator": [
"arm64",
"x86_64"
]
},
"build_params": {
"base": [
"--parallel",
"--build_apple_framework",
"--use_coreml",
"--skip_tests",
"--cmake_extra_defines=onnxruntime_BUILD_UNIT_TESTS=OFF"
],
"appletvos": [
"--tvos",
"--use_xcode",
"--apple_deploy_target=13.0"
],
"appletvsimulator": [
"--tvos",
"--use_xcode",
"--apple_deploy_target=13.0"
]
}
}

0 comments on commit dc73bc9

Please sign in to comment.