diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 1795052953..56bcce28ef 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -1680,8 +1680,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") - message(FATAL_ERROR "onnxruntime_BUILD_APPLE_FRAMEWORK can only be enabled for macOS or iOS.") + 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.") endif() list(APPEND ONNXRUNTIME_CMAKE_FILES onnxruntime) endif() diff --git a/cmake/adjust_global_compile_flags.cmake b/cmake/adjust_global_compile_flags.cmake index 9a3bc3302c..690b6d4e66 100644 --- a/cmake/adjust_global_compile_flags.cmake +++ b/cmake/adjust_global_compile_flags.cmake @@ -204,9 +204,9 @@ if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0) endif() endif() -# Mark symbols to be invisible, for macOS/iOS target only +# Mark symbols to be invisible, for macOS/iOS/visionOS target only # Due to many dependencies have different symbol visibility settings, set global compile flags here. -if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS") +if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS|visionOS") foreach(flags CMAKE_CXX_FLAGS CMAKE_OBJC_FLAGS CMAKE_OBJCXX_FLAGS) string(APPEND ${flags} " -fvisibility=hidden -fvisibility-inlines-hidden") endforeach() diff --git a/cmake/onnxruntime_ios.toolchain.cmake b/cmake/onnxruntime_ios.toolchain.cmake index 750e4118ca..f2106f2423 100644 --- a/cmake/onnxruntime_ios.toolchain.cmake +++ b/cmake/onnxruntime_ios.toolchain.cmake @@ -2,6 +2,7 @@ # Licensed under the MIT License. set(CMAKE_SYSTEM_NAME iOS) + 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() diff --git a/cmake/onnxruntime_providers_cpu.cmake b/cmake/onnxruntime_providers_cpu.cmake index b81a5c79ac..b211c02f71 100644 --- a/cmake/onnxruntime_providers_cpu.cmake +++ b/cmake/onnxruntime_providers_cpu.cmake @@ -223,7 +223,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" + AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS|visionOS" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Android" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") file(GLOB onnxruntime_providers_shared_cc_srcs CONFIGURE_DEPENDS @@ -273,4 +273,4 @@ if (NOT onnxruntime_BUILD_SHARED_LIB) LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR}) -endif() \ No newline at end of file +endif() diff --git a/cmake/onnxruntime_python.cmake b/cmake/onnxruntime_python.cmake index fcddda8f3e..56c422da4f 100644 --- a/cmake/onnxruntime_python.cmake +++ b/cmake/onnxruntime_python.cmake @@ -693,7 +693,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" + AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS|visionOS" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Android" AND NOT onnxruntime_USE_ROCM AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") diff --git a/cmake/onnxruntime_unittests.cmake b/cmake/onnxruntime_unittests.cmake index 4b4d5df47f..346f7a1c9a 100644 --- a/cmake/onnxruntime_unittests.cmake +++ b/cmake/onnxruntime_unittests.cmake @@ -1727,7 +1727,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" + AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS|visionOS" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Android" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten" AND NOT onnxruntime_USE_ROCM) diff --git a/cmake/onnxruntime_visionos.toolchain.cmake b/cmake/onnxruntime_visionos.toolchain.cmake new file mode 100644 index 0000000000..7343fe43c7 --- /dev/null +++ b/cmake/onnxruntime_visionos.toolchain.cmake @@ -0,0 +1,12 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +set(CMAKE_SYSTEM_NAME visionOS) +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") diff --git a/onnxruntime/core/common/cpuid_info.h b/onnxruntime/core/common/cpuid_info.h index a3936b4bd1..83bc3e9c69 100644 --- a/onnxruntime/core/common/cpuid_info.h +++ b/onnxruntime/core/common/cpuid_info.h @@ -123,7 +123,7 @@ class CPUIDInfo { void X86Init(); #elif defined(CPUIDINFO_ARCH_ARM) // Now the following var is only used in ARM build, but later one we may expand the usage. - bool pytorch_cpuinfo_init_{false}; + [[maybe_unused]] bool pytorch_cpuinfo_init_{false}; #endif #ifdef __linux__ diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index d77fef481b..2cc06fca07 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -397,9 +397,10 @@ def parse_arguments(): ) parser.add_argument("--gdk_platform", default="Scarlett", help="Sets the GDK target platform.") - parser.add_argument("--ios", action="store_true", help="build for ios") - - parser.add_argument( + 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( "--macos", choices=["MacOSX", "Catalyst"], help="Specify the target platform for macOS build. Only specify this argument when --build_apple_framework is present.", @@ -413,6 +414,11 @@ def parse_arguments(): default="", help="Path to ios toolchain file, or cmake/onnxruntime_ios.toolchain.cmake will be used", ) + parser.add_argument( + "--visionos_toolchain_file", + default="", + help="Path to visionos toolchain file, or cmake/onnxruntime_visionos.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" ) @@ -902,7 +908,7 @@ def use_dev_mode(args): return False if args.use_armnn: return False - if args.ios and is_macOS(): + if (args.ios or args.visionos) and is_macOS(): return False SYSTEM_COLLECTIONURI = os.getenv("SYSTEM_COLLECTIONURI") # noqa: N806 if SYSTEM_COLLECTIONURI and SYSTEM_COLLECTIONURI != "https://dev.azure.com/onnxruntime/": @@ -1327,12 +1333,12 @@ def generate_build_tree( if args.use_snpe: cmake_args += ["-Donnxruntime_USE_SNPE=ON"] - if args.macos or args.ios: + if args.macos or args.ios or args.visionos: # 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.macos == "MacOSX") and not args.cmake_generator == "Xcode": + if (args.ios or args.visionos 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')." ) @@ -1381,6 +1387,17 @@ def generate_build_tree( f"-DCMAKE_CC_FLAGS=--target={macabi_target}", f"-DCMAKE_CC_FLAGS_RELEASE=-O3 -DNDEBUG --target={macabi_target}", ] + if args.visionos: + cmake_args += [ + "-DCMAKE_SYSTEM_NAME=visionOS", + "-DCMAKE_TOOLCHAIN_FILE=" + + ( + args.visionos_toolchain_file + if args.visionos_toolchain_file + else "../cmake/onnxruntime_visionos.toolchain.cmake" + ), + "-Donnxruntime_ENABLE_CPUINFO=OFF", + ] if args.build_wasm: emsdk_dir = os.path.join(cmake_dir, "external", "emsdk") @@ -2766,7 +2783,7 @@ def main(): if is_macOS(): if ( - not args.ios + not (args.ios or args.visionos) and args.macos != "Catalyst" and not args.android and args.osx_arch == "arm64" diff --git a/tools/ci_build/github/apple/default_vision_os_framework_build_settings.json b/tools/ci_build/github/apple/default_vision_os_framework_build_settings.json new file mode 100644 index 0000000000..5749a111fc --- /dev/null +++ b/tools/ci_build/github/apple/default_vision_os_framework_build_settings.json @@ -0,0 +1,28 @@ +{ + "build_osx_archs": { + "xros": [ + "arm64" + ], + "xrsimulator": [ + "arm64" + ] + }, + "build_params": { + "base": [ + "--parallel", + "--build_apple_framework", + "--use_xcode", + "--use_coreml", + "--skip_tests", + "--cmake_extra_defines=onnxruntime_BUILD_UNIT_TESTS=OFF" + ], + "xros": [ + "--visionos", + "--apple_deploy_target=1.0" + ], + "xrsimulator": [ + "--visionos", + "--apple_deploy_target=1.0" + ] + } +}