Skip to content

Support tvOS build #24000

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 5 commits into from
Mar 14, 2025
Merged
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: 2 additions & 2 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1812,8 +1812,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 @@ -178,9 +178,9 @@ if (onnxruntime_CROSS_COMPILING)
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 @@ -217,7 +217,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 @@ -725,7 +725,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 @@ -1843,7 +1843,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
24 changes: 20 additions & 4 deletions tools/ci_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,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 @@ -452,6 +453,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 @@ -945,7 +951,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 @@ -1617,12 +1623,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 @@ -1682,6 +1688,16 @@ 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:
if not args.use_vcpkg:
Expand Down Expand Up @@ -3144,7 +3160,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=15.1"
],
"appletvsimulator": [
"--tvos",
"--use_xcode",
"--apple_deploy_target=15.1"
]
}
}
Loading