Skip to content

Commit 14fcf0a

Browse files
YUNQIUGUOrachguorachguo
authored
Support visionos build (#20365)
### Description <!-- Describe your changes. --> This PR supports a build of onnxruntime.xcframework for xros/xrsimulator for visionos via the build command of `python3 tools/ci_build/github/apple/build_apple_framework.py --config Release/Debug tools/ci_build/github/apple/default_vision_os_framework_build_settings.json`. For officially include visionos in ios cocoapods package and testing in CI, would require separate work for upgrading the Xcode version & upgrade macOS CI agent to macos-13-arm64 or higher. ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. --> visionos support: #19313 --------- Co-authored-by: rachguo <[email protected]> Co-authored-by: rachguo <[email protected]>
1 parent 4ce7bbf commit 14fcf0a

10 files changed

+74
-16
lines changed

cmake/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,8 +1680,8 @@ if (onnxruntime_USE_WINML)
16801680
endif() # if (onnxruntime_USE_WINML)
16811681

16821682
if (onnxruntime_BUILD_SHARED_LIB OR onnxruntime_BUILD_APPLE_FRAMEWORK)
1683-
if (onnxruntime_BUILD_APPLE_FRAMEWORK AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS")
1684-
message(FATAL_ERROR "onnxruntime_BUILD_APPLE_FRAMEWORK can only be enabled for macOS or iOS.")
1683+
if (onnxruntime_BUILD_APPLE_FRAMEWORK AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS|visionOS")
1684+
message(FATAL_ERROR "onnxruntime_BUILD_APPLE_FRAMEWORK can only be enabled for macOS or iOS or visionOS.")
16851685
endif()
16861686
list(APPEND ONNXRUNTIME_CMAKE_FILES onnxruntime)
16871687
endif()

cmake/adjust_global_compile_flags.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
204204
endif()
205205
endif()
206206

207-
# Mark symbols to be invisible, for macOS/iOS target only
207+
# Mark symbols to be invisible, for macOS/iOS/visionOS target only
208208
# Due to many dependencies have different symbol visibility settings, set global compile flags here.
209-
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS")
209+
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS|visionOS")
210210
foreach(flags CMAKE_CXX_FLAGS CMAKE_OBJC_FLAGS CMAKE_OBJCXX_FLAGS)
211211
string(APPEND ${flags} " -fvisibility=hidden -fvisibility-inlines-hidden")
212212
endforeach()

cmake/onnxruntime_ios.toolchain.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Licensed under the MIT License.
33

44
set(CMAKE_SYSTEM_NAME iOS)
5+
56
if (NOT DEFINED CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM AND NOT DEFINED CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY)
67
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED NO)
78
endif()

cmake/onnxruntime_providers_cpu.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ set_target_properties(onnxruntime_providers PROPERTIES LINKER_LANGUAGE CXX)
223223
set_target_properties(onnxruntime_providers PROPERTIES FOLDER "ONNXRuntime")
224224

225225
if (NOT onnxruntime_MINIMAL_BUILD AND NOT onnxruntime_EXTENDED_MINIMAL_BUILD
226-
AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS"
226+
AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS|visionOS"
227227
AND NOT CMAKE_SYSTEM_NAME STREQUAL "Android"
228228
AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
229229
file(GLOB onnxruntime_providers_shared_cc_srcs CONFIGURE_DEPENDS
@@ -273,4 +273,4 @@ if (NOT onnxruntime_BUILD_SHARED_LIB)
273273
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
274274
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
275275
FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR})
276-
endif()
276+
endif()

cmake/onnxruntime_python.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ if (onnxruntime_ENABLE_EXTERNAL_CUSTOM_OP_SCHEMAS)
693693
endif()
694694

695695
if (NOT onnxruntime_MINIMAL_BUILD AND NOT onnxruntime_EXTENDED_MINIMAL_BUILD
696-
AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS"
696+
AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS|visionOS"
697697
AND NOT CMAKE_SYSTEM_NAME STREQUAL "Android"
698698
AND NOT onnxruntime_USE_ROCM
699699
AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")

cmake/onnxruntime_unittests.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1727,7 +1727,7 @@ endif()
17271727

17281728
# limit to only test on windows first, due to a runtime path issue on linux
17291729
if (NOT onnxruntime_MINIMAL_BUILD AND NOT onnxruntime_EXTENDED_MINIMAL_BUILD
1730-
AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS"
1730+
AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS|visionOS"
17311731
AND NOT CMAKE_SYSTEM_NAME STREQUAL "Android"
17321732
AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten"
17331733
AND NOT onnxruntime_USE_ROCM)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
set(CMAKE_SYSTEM_NAME visionOS)
5+
set(CMAKE_SYSTEM_PROCESSOR arm64)
6+
7+
if (NOT DEFINED CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM AND NOT DEFINED CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY)
8+
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED NO)
9+
endif()
10+
11+
SET(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_MODULES "YES")
12+
SET(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC "YES")

onnxruntime/core/common/cpuid_info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class CPUIDInfo {
123123
void X86Init();
124124
#elif defined(CPUIDINFO_ARCH_ARM)
125125
// Now the following var is only used in ARM build, but later one we may expand the usage.
126-
bool pytorch_cpuinfo_init_{false};
126+
[[maybe_unused]] bool pytorch_cpuinfo_init_{false};
127127
#endif
128128

129129
#ifdef __linux__

tools/ci_build/build.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,10 @@ def convert_arg_line_to_args(self, arg_line):
397397
)
398398
parser.add_argument("--gdk_platform", default="Scarlett", help="Sets the GDK target platform.")
399399

400-
parser.add_argument("--ios", action="store_true", help="build for ios")
401-
402-
parser.add_argument(
400+
platform_group = parser.add_mutually_exclusive_group()
401+
platform_group.add_argument("--ios", action="store_true", help="build for ios")
402+
platform_group.add_argument("--visionos", action="store_true", help="build for visionOS")
403+
platform_group.add_argument(
403404
"--macos",
404405
choices=["MacOSX", "Catalyst"],
405406
help="Specify the target platform for macOS build. Only specify this argument when --build_apple_framework is present.",
@@ -413,6 +414,11 @@ def convert_arg_line_to_args(self, arg_line):
413414
default="",
414415
help="Path to ios toolchain file, or cmake/onnxruntime_ios.toolchain.cmake will be used",
415416
)
417+
parser.add_argument(
418+
"--visionos_toolchain_file",
419+
default="",
420+
help="Path to visionos toolchain file, or cmake/onnxruntime_visionos.toolchain.cmake will be used",
421+
)
416422
parser.add_argument(
417423
"--xcode_code_signing_team_id", default="", help="The development team ID used for code signing in Xcode"
418424
)
@@ -902,7 +908,7 @@ def use_dev_mode(args):
902908
return False
903909
if args.use_armnn:
904910
return False
905-
if args.ios and is_macOS():
911+
if (args.ios or args.visionos) and is_macOS():
906912
return False
907913
SYSTEM_COLLECTIONURI = os.getenv("SYSTEM_COLLECTIONURI") # noqa: N806
908914
if SYSTEM_COLLECTIONURI and SYSTEM_COLLECTIONURI != "https://dev.azure.com/onnxruntime/":
@@ -1327,12 +1333,12 @@ def generate_build_tree(
13271333
if args.use_snpe:
13281334
cmake_args += ["-Donnxruntime_USE_SNPE=ON"]
13291335

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

1335-
if (args.ios or args.macos == "MacOSX") and not args.cmake_generator == "Xcode":
1341+
if (args.ios or args.visionos or args.macos == "MacOSX") and not args.cmake_generator == "Xcode":
13361342
raise BuildError(
13371343
"iOS/MacOS framework build requires use of the Xcode CMake generator ('--cmake_generator Xcode')."
13381344
)
@@ -1381,6 +1387,17 @@ def generate_build_tree(
13811387
f"-DCMAKE_CC_FLAGS=--target={macabi_target}",
13821388
f"-DCMAKE_CC_FLAGS_RELEASE=-O3 -DNDEBUG --target={macabi_target}",
13831389
]
1390+
if args.visionos:
1391+
cmake_args += [
1392+
"-DCMAKE_SYSTEM_NAME=visionOS",
1393+
"-DCMAKE_TOOLCHAIN_FILE="
1394+
+ (
1395+
args.visionos_toolchain_file
1396+
if args.visionos_toolchain_file
1397+
else "../cmake/onnxruntime_visionos.toolchain.cmake"
1398+
),
1399+
"-Donnxruntime_ENABLE_CPUINFO=OFF",
1400+
]
13841401

13851402
if args.build_wasm:
13861403
emsdk_dir = os.path.join(cmake_dir, "external", "emsdk")
@@ -2766,7 +2783,7 @@ def main():
27662783

27672784
if is_macOS():
27682785
if (
2769-
not args.ios
2786+
not (args.ios or args.visionos)
27702787
and args.macos != "Catalyst"
27712788
and not args.android
27722789
and args.osx_arch == "arm64"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"build_osx_archs": {
3+
"xros": [
4+
"arm64"
5+
],
6+
"xrsimulator": [
7+
"arm64"
8+
]
9+
},
10+
"build_params": {
11+
"base": [
12+
"--parallel",
13+
"--build_apple_framework",
14+
"--use_xcode",
15+
"--use_coreml",
16+
"--skip_tests",
17+
"--cmake_extra_defines=onnxruntime_BUILD_UNIT_TESTS=OFF"
18+
],
19+
"xros": [
20+
"--visionos",
21+
"--apple_deploy_target=1.0"
22+
],
23+
"xrsimulator": [
24+
"--visionos",
25+
"--apple_deploy_target=1.0"
26+
]
27+
}
28+
}

0 commit comments

Comments
 (0)