From 288b80d363bc120c8d3c0ca3c2fe4252e16f4c56 Mon Sep 17 00:00:00 2001 From: Rachel Guo <35738743+YUNQIUGUO@users.noreply.github.com> Date: Tue, 28 Nov 2023 10:11:53 -0800 Subject: [PATCH] Add MacOS build to ORT C Pod (#18550) ### Description As title. 1. Add macos build as an optionally enabled arch for pod and changes to exsiting build_ios_framework/assemble_c_pod scripts. 2. Enable macos build arch in ios packaging pipeline (currently for variants other than Mobile) and check the output artifacts are correct. 3. Write MacOS Test Target scheme in the test app and integrate into ios packaging CI testing pipeline. Currently the changes only apply to onnxruntime-c pod. as the original request was from ORT SPM which consumes the onnxruntime-c pod only as the binary target. TODO: could look into adding macos platform to objc pod as well. ### Motivation and Context Enable macos platform support in cocoapods. and also potentially produce binary target for enabling macos platform in SPM as well. Replace https://github.com/microsoft/onnxruntime/pull/18334 --------- Co-authored-by: rachguo Co-authored-by: rachguo Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com> --- cmake/onnxruntime.cmake | 6 +- js/README.md | 4 +- .../apple_package_test}/.gitignore | 0 .../apple_package_test}/Podfile.template | 22 +- .../apple_package_test}/README.md | 0 .../project.pbxproj | 312 +++++++- .../contents.xcworkspacedata | 0 .../xcshareddata/IDEWorkspaceChecks.plist | 0 .../xcshareddata/WorkspaceSettings.xcsettings | 5 + .../ios_package_test/AppDelegate.h | 0 .../ios_package_test/AppDelegate.m | 0 .../Base.lproj/LaunchScreen.storyboard | 0 .../Base.lproj/Main.storyboard | 0 .../ios_package_test/Info.plist | 0 .../ios_package_test/main.m | 0 .../ios_package_uitest_cpp_api.mm | 0 .../macos_package_test/AppDelegate.h | 12 + .../macos_package_test/AppDelegate.m | 28 + .../Base.lproj/Main.storyboard | 719 ++++++++++++++++++ .../macos_package_test.entitlements | 10 + .../macos_package_test/main.m | 15 + .../macos_package_uitest_cpp_api.mm | 108 +++ .../apple_package_test}/models/sigmoid.ort | Bin tools/ci_build/build.py | 36 +- ... => assemble_apple_packaging_artifacts.sh} | 0 ...ds.py => build_and_assemble_apple_pods.py} | 36 +- ..._framework.py => build_apple_framework.py} | 61 +- .../github/apple/c/assemble_c_pod_package.py | 12 +- .../github/apple/c/c.podspec.template | 8 +- .../apple/c/onnxruntime-test-c.config.json | 5 - ...t_full_apple_framework_build_settings.json | 37 + ...ult_full_ios_framework_build_settings.json | 22 - ...t_mobile_ios_framework_build_settings.json | 38 +- ...training_ios_framework_build_settings.json | 39 +- .../github/apple/framework_info.json.template | 8 +- .../objectivec/assemble_objc_pod_package.py | 6 +- .../github/apple/package_assembly_utils.py | 1 - ...ios_packages.py => test_apple_packages.py} | 32 +- .../apple/use_ios_pods_with_custom_build.md | 6 +- .../azure-pipelines/mac-ios-ci-pipeline.yml | 2 +- .../azure-pipelines/post-merge-jobs.yml | 9 +- .../azure-pipelines/templates/c-api-cpu.yml | 26 +- .../templates/react-native-ci.yml | 4 +- .../stages/mac-ios-packaging-build-stage.yml | 26 +- ...e2e_full_ios_framework_build_settings.json | 22 +- ...e_mobile_ios_framework_build_settings.json | 32 +- 46 files changed, 1512 insertions(+), 197 deletions(-) rename onnxruntime/test/platform/{ios/ios_package_test => apple/apple_package_test}/.gitignore (100%) rename onnxruntime/test/platform/{ios/ios_package_test => apple/apple_package_test}/Podfile.template (52%) rename onnxruntime/test/platform/{ios/ios_package_test => apple/apple_package_test}/README.md (100%) rename onnxruntime/test/platform/{ios/ios_package_test/ios_package_test.xcodeproj => apple/apple_package_test/apple_package_test.xcodeproj}/project.pbxproj (57%) rename onnxruntime/test/platform/{ios/ios_package_test/ios_package_test.xcodeproj => apple/apple_package_test/apple_package_test.xcodeproj}/project.xcworkspace/contents.xcworkspacedata (100%) rename onnxruntime/test/platform/{ios/ios_package_test/ios_package_test.xcodeproj => apple/apple_package_test/apple_package_test.xcodeproj}/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist (100%) create mode 100644 onnxruntime/test/platform/apple/apple_package_test/apple_package_test.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings rename onnxruntime/test/platform/{ios/ios_package_test => apple/apple_package_test}/ios_package_test/AppDelegate.h (100%) rename onnxruntime/test/platform/{ios/ios_package_test => apple/apple_package_test}/ios_package_test/AppDelegate.m (100%) rename onnxruntime/test/platform/{ios/ios_package_test => apple/apple_package_test}/ios_package_test/Base.lproj/LaunchScreen.storyboard (100%) rename onnxruntime/test/platform/{ios/ios_package_test => apple/apple_package_test}/ios_package_test/Base.lproj/Main.storyboard (100%) rename onnxruntime/test/platform/{ios/ios_package_test => apple/apple_package_test}/ios_package_test/Info.plist (100%) rename onnxruntime/test/platform/{ios/ios_package_test => apple/apple_package_test}/ios_package_test/main.m (100%) rename onnxruntime/test/platform/{ios/ios_package_test => apple/apple_package_test}/ios_package_testUITests/ios_package_uitest_cpp_api.mm (100%) create mode 100644 onnxruntime/test/platform/apple/apple_package_test/macos_package_test/AppDelegate.h create mode 100644 onnxruntime/test/platform/apple/apple_package_test/macos_package_test/AppDelegate.m create mode 100644 onnxruntime/test/platform/apple/apple_package_test/macos_package_test/Base.lproj/Main.storyboard create mode 100644 onnxruntime/test/platform/apple/apple_package_test/macos_package_test/macos_package_test.entitlements create mode 100644 onnxruntime/test/platform/apple/apple_package_test/macos_package_test/main.m create mode 100644 onnxruntime/test/platform/apple/apple_package_test/macos_package_testUITests/macos_package_uitest_cpp_api.mm rename onnxruntime/test/platform/{ios/ios_package_test => apple/apple_package_test}/models/sigmoid.ort (100%) rename tools/ci_build/github/apple/{assemble_ios_packaging_artifacts.sh => assemble_apple_packaging_artifacts.sh} (100%) rename tools/ci_build/github/apple/{build_and_assemble_ios_pods.py => build_and_assemble_apple_pods.py} (82%) rename tools/ci_build/github/apple/{build_ios_framework.py => build_apple_framework.py} (81%) delete mode 100644 tools/ci_build/github/apple/c/onnxruntime-test-c.config.json create mode 100644 tools/ci_build/github/apple/default_full_apple_framework_build_settings.json delete mode 100644 tools/ci_build/github/apple/default_full_ios_framework_build_settings.json rename tools/ci_build/github/apple/{test_ios_packages.py => test_apple_packages.py} (87%) diff --git a/cmake/onnxruntime.cmake b/cmake/onnxruntime.cmake index 9d9b006c59..c900f4d4b0 100644 --- a/cmake/onnxruntime.cmake +++ b/cmake/onnxruntime.cmake @@ -282,11 +282,7 @@ endif() # Assemble the Apple static framework (iOS and macOS) if(onnxruntime_BUILD_APPLE_FRAMEWORK) - if(${CMAKE_SYSTEM_NAME} STREQUAL "iOS") - set(STATIC_FRAMEWORK_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}-${CMAKE_OSX_SYSROOT}) - else() # macOS - set(STATIC_FRAMEWORK_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}) - endif() + set(STATIC_FRAMEWORK_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}-${CMAKE_OSX_SYSROOT}) # Setup the various directories required. Remove any existing ones so we start with a clean directory. set(STATIC_LIB_DIR ${CMAKE_CURRENT_BINARY_DIR}/static_libraries) diff --git a/js/README.md b/js/README.md index 7e6681e6bd..1662de6d4a 100644 --- a/js/README.md +++ b/js/README.md @@ -344,13 +344,13 @@ From ORT v1.13 onwards the 'full' ONNX Runtime package is used. It supports both Full build: ```sh - python tools/ci_build/github/apple/build_ios_framework.py tools/ci_build/github/apple/default_full_ios_framework_build_settings.json --config Release + python tools/ci_build/github/apple/build_apple_framework.py tools/ci_build/github/apple/default_full_apple_framework_build_settings.json --config Release ``` Reduced size build: ```sh - python tools/ci_build/github/apple/build_ios_framework.py tools/ci_build/github/apple/default_mobile_ios_framework_build_settings.json --config MinSizeRel --include_ops_by_config --enable_reduced_operator_type_support + python tools/ci_build/github/apple/build_apple_framework.py tools/ci_build/github/apple/default_mobile_ios_framework_build_settings.json --config MinSizeRel --include_ops_by_config --enable_reduced_operator_type_support ``` The build creates `Headers`, `LICENSE`, and `onnxruntime.xcframework` in `build/iOS_framework/framework_out` directory. From `framework_out` directory, create an archive file named `onnxruntime-c.zip` for a full build or `onnxruntime-mobile-c.zip` for a reduced size build and copy to `/js/react_native/local_pods` directory. diff --git a/onnxruntime/test/platform/ios/ios_package_test/.gitignore b/onnxruntime/test/platform/apple/apple_package_test/.gitignore similarity index 100% rename from onnxruntime/test/platform/ios/ios_package_test/.gitignore rename to onnxruntime/test/platform/apple/apple_package_test/.gitignore diff --git a/onnxruntime/test/platform/ios/ios_package_test/Podfile.template b/onnxruntime/test/platform/apple/apple_package_test/Podfile.template similarity index 52% rename from onnxruntime/test/platform/ios/ios_package_test/Podfile.template rename to onnxruntime/test/platform/apple/apple_package_test/Podfile.template index d2155660d7..3d191d6fb1 100644 --- a/onnxruntime/test/platform/ios/ios_package_test/Podfile.template +++ b/onnxruntime/test/platform/apple/apple_package_test/Podfile.template @@ -1,14 +1,34 @@ -platform :ios, '13.0' +def include_macos_target + if '@C_POD_NAME@' != 'onnxruntime-mobile-c' + return true + end + return false +end target 'ios_package_test' do # Comment the next line if you don't want to use dynamic frameworks use_frameworks! + platform :ios, '13.0' + target 'ios_package_testUITests' do inherit! :search_paths pod '@C_POD_NAME@', :podspec => '@C_POD_PODSPEC@' end +end +if include_macos_target + target 'macos_package_test' do + # Comment the next line if you don't want to use dynamic frameworks + use_frameworks! + + platform :osx, '11.0' + + target 'macos_package_testUITests' do + inherit! :search_paths + pod '@C_POD_NAME@', :podspec => '@C_POD_PODSPEC@' + end + end end # This is to prevent the pods to be code signed if enabled diff --git a/onnxruntime/test/platform/ios/ios_package_test/README.md b/onnxruntime/test/platform/apple/apple_package_test/README.md similarity index 100% rename from onnxruntime/test/platform/ios/ios_package_test/README.md rename to onnxruntime/test/platform/apple/apple_package_test/README.md diff --git a/onnxruntime/test/platform/ios/ios_package_test/ios_package_test.xcodeproj/project.pbxproj b/onnxruntime/test/platform/apple/apple_package_test/apple_package_test.xcodeproj/project.pbxproj similarity index 57% rename from onnxruntime/test/platform/ios/ios_package_test/ios_package_test.xcodeproj/project.pbxproj rename to onnxruntime/test/platform/apple/apple_package_test/apple_package_test.xcodeproj/project.pbxproj index 151db69323..66dd772e5e 100644 --- a/onnxruntime/test/platform/ios/ios_package_test/ios_package_test.xcodeproj/project.pbxproj +++ b/onnxruntime/test/platform/apple/apple_package_test/apple_package_test.xcodeproj/project.pbxproj @@ -14,6 +14,11 @@ 229E595926586B4A006E41AE /* sigmoid.ort in Resources */ = {isa = PBXBuildFile; fileRef = 229E595826586B4A006E41AE /* sigmoid.ort */; }; 22C1D8EA271A79FD002CEE67 /* ios_package_uitest_cpp_api.mm in Sources */ = {isa = PBXBuildFile; fileRef = 22C1D8E9271A79FD002CEE67 /* ios_package_uitest_cpp_api.mm */; }; 22C1D8EB271A7A06002CEE67 /* sigmoid.ort in Resources */ = {isa = PBXBuildFile; fileRef = 229E595826586B4A006E41AE /* sigmoid.ort */; }; + 51C316BD2B0881450033C70B /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 51C316BC2B0881450033C70B /* AppDelegate.m */; }; + 51C316C52B0881480033C70B /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 51C316C32B0881480033C70B /* Main.storyboard */; }; + 51C316C72B0881480033C70B /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 51C316C62B0881480033C70B /* main.m */; }; + 51C316DC2B0881490033C70B /* macos_package_uitest_cpp_api.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51C316DB2B0881490033C70B /* macos_package_uitest_cpp_api.mm */; }; + 51C316E82B0892EE0033C70B /* sigmoid.ort in Resources */ = {isa = PBXBuildFile; fileRef = 229E595826586B4A006E41AE /* sigmoid.ort */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -24,6 +29,13 @@ remoteGlobalIDString = 229E591B265869BF006E41AE; remoteInfo = ios_package_test; }; + 51C316D82B0881490033C70B /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 229E5914265869BF006E41AE /* Project object */; + proxyType = 1; + remoteGlobalIDString = 51C316B82B0881450033C70B; + remoteInfo = macos_package_test; + }; /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ @@ -37,6 +49,14 @@ 229E595826586B4A006E41AE /* sigmoid.ort */ = {isa = PBXFileReference; lastKnownFileType = file; path = sigmoid.ort; sourceTree = ""; }; 22C1D8DE271A79AF002CEE67 /* ios_package_testUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ios_package_testUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 22C1D8E9271A79FD002CEE67 /* ios_package_uitest_cpp_api.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ios_package_uitest_cpp_api.mm; sourceTree = ""; }; + 51C316B92B0881450033C70B /* macos_package_test.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = macos_package_test.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 51C316BB2B0881450033C70B /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 51C316BC2B0881450033C70B /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 51C316C42B0881480033C70B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 51C316C62B0881480033C70B /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 51C316C82B0881480033C70B /* macos_package_test.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = macos_package_test.entitlements; sourceTree = ""; }; + 51C316D72B0881490033C70B /* macos_package_testUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = macos_package_testUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 51C316DB2B0881490033C70B /* macos_package_uitest_cpp_api.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = macos_package_uitest_cpp_api.mm; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -54,6 +74,20 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 51C316B62B0881450033C70B /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 51C316D42B0881490033C70B /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -63,7 +97,10 @@ 229E595426586A77006E41AE /* models */, 229E591E265869BF006E41AE /* ios_package_test */, 22C1D8DF271A79AF002CEE67 /* ios_package_testUITests */, + 51C316BA2B0881450033C70B /* macos_package_test */, + 51C316DA2B0881490033C70B /* macos_package_testUITests */, 229E591D265869BF006E41AE /* Products */, + B49FE29C3625E88EDCCDD4BC /* Pods */, ); sourceTree = ""; }; @@ -72,6 +109,8 @@ children = ( 229E591C265869BF006E41AE /* ios_package_test.app */, 22C1D8DE271A79AF002CEE67 /* ios_package_testUITests.xctest */, + 51C316B92B0881450033C70B /* macos_package_test.app */, + 51C316D72B0881490033C70B /* macos_package_testUITests.xctest */, ); name = Products; sourceTree = ""; @@ -105,6 +144,33 @@ path = ios_package_testUITests; sourceTree = ""; }; + 51C316BA2B0881450033C70B /* macos_package_test */ = { + isa = PBXGroup; + children = ( + 51C316BB2B0881450033C70B /* AppDelegate.h */, + 51C316BC2B0881450033C70B /* AppDelegate.m */, + 51C316C32B0881480033C70B /* Main.storyboard */, + 51C316C62B0881480033C70B /* main.m */, + 51C316C82B0881480033C70B /* macos_package_test.entitlements */, + ); + path = macos_package_test; + sourceTree = ""; + }; + 51C316DA2B0881490033C70B /* macos_package_testUITests */ = { + isa = PBXGroup; + children = ( + 51C316DB2B0881490033C70B /* macos_package_uitest_cpp_api.mm */, + ); + path = macos_package_testUITests; + sourceTree = ""; + }; + B49FE29C3625E88EDCCDD4BC /* Pods */ = { + isa = PBXGroup; + children = ( + ); + path = Pods; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -143,6 +209,41 @@ productReference = 22C1D8DE271A79AF002CEE67 /* ios_package_testUITests.xctest */; productType = "com.apple.product-type.bundle.ui-testing"; }; + 51C316B82B0881450033C70B /* macos_package_test */ = { + isa = PBXNativeTarget; + buildConfigurationList = 51C316DF2B0881490033C70B /* Build configuration list for PBXNativeTarget "macos_package_test" */; + buildPhases = ( + 51C316B52B0881450033C70B /* Sources */, + 51C316B62B0881450033C70B /* Frameworks */, + 51C316B72B0881450033C70B /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = macos_package_test; + productName = macos_package_test; + productReference = 51C316B92B0881450033C70B /* macos_package_test.app */; + productType = "com.apple.product-type.application"; + }; + 51C316D62B0881490033C70B /* macos_package_testUITests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 51C316E52B0881490033C70B /* Build configuration list for PBXNativeTarget "macos_package_testUITests" */; + buildPhases = ( + 51C316D32B0881490033C70B /* Sources */, + 51C316D42B0881490033C70B /* Frameworks */, + 51C316D52B0881490033C70B /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 51C316D92B0881490033C70B /* PBXTargetDependency */, + ); + name = macos_package_testUITests; + productName = macos_package_testUITests; + productReference = 51C316D72B0881490033C70B /* macos_package_testUITests.xctest */; + productType = "com.apple.product-type.bundle.ui-testing"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -158,9 +259,16 @@ CreatedOnToolsVersion = 13.0; TestTargetID = 229E591B265869BF006E41AE; }; + 51C316B82B0881450033C70B = { + CreatedOnToolsVersion = 15.0.1; + }; + 51C316D62B0881490033C70B = { + CreatedOnToolsVersion = 15.0.1; + TestTargetID = 51C316B82B0881450033C70B; + }; }; }; - buildConfigurationList = 229E5917265869BF006E41AE /* Build configuration list for PBXProject "ios_package_test" */; + buildConfigurationList = 229E5917265869BF006E41AE /* Build configuration list for PBXProject "apple_package_test" */; compatibilityVersion = "Xcode 9.3"; developmentRegion = en; hasScannedForEncodings = 0; @@ -175,6 +283,8 @@ targets = ( 229E591B265869BF006E41AE /* ios_package_test */, 22C1D8DD271A79AF002CEE67 /* ios_package_testUITests */, + 51C316B82B0881450033C70B /* macos_package_test */, + 51C316D62B0881490033C70B /* macos_package_testUITests */, ); }; /* End PBXProject section */ @@ -198,6 +308,22 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 51C316B72B0881450033C70B /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 51C316C52B0881480033C70B /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 51C316D52B0881490033C70B /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 51C316E82B0892EE0033C70B /* sigmoid.ort in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -218,6 +344,23 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 51C316B52B0881450033C70B /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 51C316C72B0881480033C70B /* main.m in Sources */, + 51C316BD2B0881450033C70B /* AppDelegate.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 51C316D32B0881490033C70B /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 51C316DC2B0881490033C70B /* macos_package_uitest_cpp_api.mm in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ @@ -226,6 +369,11 @@ target = 229E591B265869BF006E41AE /* ios_package_test */; targetProxy = 22C1D8E4271A79AF002CEE67 /* PBXContainerItemProxy */; }; + 51C316D92B0881490033C70B /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 51C316B82B0881450033C70B /* macos_package_test */; + targetProxy = 51C316D82B0881490033C70B /* PBXContainerItemProxy */; + }; /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ @@ -245,6 +393,14 @@ name = LaunchScreen.storyboard; sourceTree = ""; }; + 51C316C32B0881480033C70B /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 51C316C42B0881480033C70B /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ @@ -300,6 +456,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 13.0; + MACOSX_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; @@ -353,6 +510,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 13.0; + MACOSX_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; SDKROOT = iphoneos; @@ -365,6 +523,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; INFOPLIST_FILE = ios_package_test/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( @@ -373,7 +532,10 @@ ); PRODUCT_BUNDLE_IDENTIFIER = "ai.onnxruntime.tests.ios-package-test"; PRODUCT_NAME = "$(TARGET_NAME)"; - TARGETED_DEVICE_FAMILY = "1,2"; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; + TARGETED_DEVICE_FAMILY = 1; }; name = Debug; }; @@ -382,6 +544,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; INFOPLIST_FILE = ios_package_test/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( @@ -390,7 +553,10 @@ ); PRODUCT_BUNDLE_IDENTIFIER = "ai.onnxruntime.tests.ios-package-test"; PRODUCT_NAME = "$(TARGET_NAME)"; - TARGETED_DEVICE_FAMILY = "1,2"; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; + TARGETED_DEVICE_FAMILY = 1; }; name = Release; }; @@ -398,6 +564,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; GENERATE_INFOPLIST_FILE = YES; @@ -420,6 +587,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; GENERATE_INFOPLIST_FILE = YES; @@ -438,10 +606,128 @@ }; name = Release; }; + 51C316E02B0881490033C70B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CODE_SIGN_ENTITLEMENTS = macos_package_test/macos_package_test.entitlements; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = UBF8T346G9; + ENABLE_HARDENED_RUNTIME = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + INFOPLIST_KEY_NSMainStoryboardFile = Main; + INFOPLIST_KEY_NSPrincipalClass = NSApplication; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MACOSX_DEPLOYMENT_TARGET = 11.0; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = "ai.onnxruntime.tests.macos-package-test"; + PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; + SDKROOT = macosx; + SWIFT_EMIT_LOC_STRINGS = YES; + }; + name = Debug; + }; + 51C316E12B0881490033C70B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CODE_SIGN_ENTITLEMENTS = macos_package_test/macos_package_test.entitlements; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = UBF8T346G9; + ENABLE_HARDENED_RUNTIME = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + INFOPLIST_KEY_NSMainStoryboardFile = Main; + INFOPLIST_KEY_NSPrincipalClass = NSApplication; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MACOSX_DEPLOYMENT_TARGET = 11.0; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = "ai.onnxruntime.tests.macos-package-test"; + PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; + SDKROOT = macosx; + SWIFT_EMIT_LOC_STRINGS = YES; + }; + name = Release; + }; + 51C316E62B0881490033C70B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = UBF8T346G9; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GENERATE_INFOPLIST_FILE = YES; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MACOSX_DEPLOYMENT_TARGET = 11.0; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = "com.MS.macos-package-testUITests"; + PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; + SDKROOT = macosx; + SWIFT_EMIT_LOC_STRINGS = NO; + TEST_TARGET_NAME = macos_package_test; + }; + name = Debug; + }; + 51C316E72B0881490033C70B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = UBF8T346G9; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GENERATE_INFOPLIST_FILE = YES; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MACOSX_DEPLOYMENT_TARGET = 11.0; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = "com.MS.macos-package-testUITests"; + PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; + SDKROOT = macosx; + SWIFT_EMIT_LOC_STRINGS = NO; + TEST_TARGET_NAME = macos_package_test; + }; + name = Release; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ - 229E5917265869BF006E41AE /* Build configuration list for PBXProject "ios_package_test" */ = { + 229E5917265869BF006E41AE /* Build configuration list for PBXProject "apple_package_test" */ = { isa = XCConfigurationList; buildConfigurations = ( 229E5949265869C2006E41AE /* Debug */, @@ -468,6 +754,24 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 51C316DF2B0881490033C70B /* Build configuration list for PBXNativeTarget "macos_package_test" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 51C316E02B0881490033C70B /* Debug */, + 51C316E12B0881490033C70B /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 51C316E52B0881490033C70B /* Build configuration list for PBXNativeTarget "macos_package_testUITests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 51C316E62B0881490033C70B /* Debug */, + 51C316E72B0881490033C70B /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; /* End XCConfigurationList section */ }; rootObject = 229E5914265869BF006E41AE /* Project object */; diff --git a/onnxruntime/test/platform/ios/ios_package_test/ios_package_test.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/onnxruntime/test/platform/apple/apple_package_test/apple_package_test.xcodeproj/project.xcworkspace/contents.xcworkspacedata similarity index 100% rename from onnxruntime/test/platform/ios/ios_package_test/ios_package_test.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename to onnxruntime/test/platform/apple/apple_package_test/apple_package_test.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/onnxruntime/test/platform/ios/ios_package_test/ios_package_test.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/onnxruntime/test/platform/apple/apple_package_test/apple_package_test.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from onnxruntime/test/platform/ios/ios_package_test/ios_package_test.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to onnxruntime/test/platform/apple/apple_package_test/apple_package_test.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/onnxruntime/test/platform/apple/apple_package_test/apple_package_test.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/onnxruntime/test/platform/apple/apple_package_test/apple_package_test.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 0000000000..0c67376eba --- /dev/null +++ b/onnxruntime/test/platform/apple/apple_package_test/apple_package_test.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,5 @@ + + + + + diff --git a/onnxruntime/test/platform/ios/ios_package_test/ios_package_test/AppDelegate.h b/onnxruntime/test/platform/apple/apple_package_test/ios_package_test/AppDelegate.h similarity index 100% rename from onnxruntime/test/platform/ios/ios_package_test/ios_package_test/AppDelegate.h rename to onnxruntime/test/platform/apple/apple_package_test/ios_package_test/AppDelegate.h diff --git a/onnxruntime/test/platform/ios/ios_package_test/ios_package_test/AppDelegate.m b/onnxruntime/test/platform/apple/apple_package_test/ios_package_test/AppDelegate.m similarity index 100% rename from onnxruntime/test/platform/ios/ios_package_test/ios_package_test/AppDelegate.m rename to onnxruntime/test/platform/apple/apple_package_test/ios_package_test/AppDelegate.m diff --git a/onnxruntime/test/platform/ios/ios_package_test/ios_package_test/Base.lproj/LaunchScreen.storyboard b/onnxruntime/test/platform/apple/apple_package_test/ios_package_test/Base.lproj/LaunchScreen.storyboard similarity index 100% rename from onnxruntime/test/platform/ios/ios_package_test/ios_package_test/Base.lproj/LaunchScreen.storyboard rename to onnxruntime/test/platform/apple/apple_package_test/ios_package_test/Base.lproj/LaunchScreen.storyboard diff --git a/onnxruntime/test/platform/ios/ios_package_test/ios_package_test/Base.lproj/Main.storyboard b/onnxruntime/test/platform/apple/apple_package_test/ios_package_test/Base.lproj/Main.storyboard similarity index 100% rename from onnxruntime/test/platform/ios/ios_package_test/ios_package_test/Base.lproj/Main.storyboard rename to onnxruntime/test/platform/apple/apple_package_test/ios_package_test/Base.lproj/Main.storyboard diff --git a/onnxruntime/test/platform/ios/ios_package_test/ios_package_test/Info.plist b/onnxruntime/test/platform/apple/apple_package_test/ios_package_test/Info.plist similarity index 100% rename from onnxruntime/test/platform/ios/ios_package_test/ios_package_test/Info.plist rename to onnxruntime/test/platform/apple/apple_package_test/ios_package_test/Info.plist diff --git a/onnxruntime/test/platform/ios/ios_package_test/ios_package_test/main.m b/onnxruntime/test/platform/apple/apple_package_test/ios_package_test/main.m similarity index 100% rename from onnxruntime/test/platform/ios/ios_package_test/ios_package_test/main.m rename to onnxruntime/test/platform/apple/apple_package_test/ios_package_test/main.m diff --git a/onnxruntime/test/platform/ios/ios_package_test/ios_package_testUITests/ios_package_uitest_cpp_api.mm b/onnxruntime/test/platform/apple/apple_package_test/ios_package_testUITests/ios_package_uitest_cpp_api.mm similarity index 100% rename from onnxruntime/test/platform/ios/ios_package_test/ios_package_testUITests/ios_package_uitest_cpp_api.mm rename to onnxruntime/test/platform/apple/apple_package_test/ios_package_testUITests/ios_package_uitest_cpp_api.mm diff --git a/onnxruntime/test/platform/apple/apple_package_test/macos_package_test/AppDelegate.h b/onnxruntime/test/platform/apple/apple_package_test/macos_package_test/AppDelegate.h new file mode 100644 index 0000000000..e7b3600a05 --- /dev/null +++ b/onnxruntime/test/platform/apple/apple_package_test/macos_package_test/AppDelegate.h @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// AppDelegate.h +// macos_package_test +// + +#import + +@interface AppDelegate : NSObject + +@end diff --git a/onnxruntime/test/platform/apple/apple_package_test/macos_package_test/AppDelegate.m b/onnxruntime/test/platform/apple/apple_package_test/macos_package_test/AppDelegate.m new file mode 100644 index 0000000000..36d16491c6 --- /dev/null +++ b/onnxruntime/test/platform/apple/apple_package_test/macos_package_test/AppDelegate.m @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// AppDelegate.h +// macos_package_test +// + +#import "AppDelegate.h" + +@interface AppDelegate () + +@end + +@implementation AppDelegate + +- (void)applicationDidFinishLaunching:(NSNotification*)aNotification { + // Insert code here to initialize your application +} + +- (void)applicationWillTerminate:(NSNotification*)aNotification { + // Insert code here to tear down your application +} + +- (BOOL)applicationSupportsSecureRestorableState:(NSApplication*)app { + return YES; +} + +@end diff --git a/onnxruntime/test/platform/apple/apple_package_test/macos_package_test/Base.lproj/Main.storyboard b/onnxruntime/test/platform/apple/apple_package_test/macos_package_test/Base.lproj/Main.storyboard new file mode 100644 index 0000000000..1cddb62a02 --- /dev/null +++ b/onnxruntime/test/platform/apple/apple_package_test/macos_package_test/Base.lproj/Main.storyboard @@ -0,0 +1,719 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Default + + + + + + + Left to Right + + + + + + + Right to Left + + + + + + + + + + + Default + + + + + + + Left to Right + + + + + + + Right to Left + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/onnxruntime/test/platform/apple/apple_package_test/macos_package_test/macos_package_test.entitlements b/onnxruntime/test/platform/apple/apple_package_test/macos_package_test/macos_package_test.entitlements new file mode 100644 index 0000000000..18aff0ce43 --- /dev/null +++ b/onnxruntime/test/platform/apple/apple_package_test/macos_package_test/macos_package_test.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-only + + + diff --git a/onnxruntime/test/platform/apple/apple_package_test/macos_package_test/main.m b/onnxruntime/test/platform/apple/apple_package_test/macos_package_test/main.m new file mode 100644 index 0000000000..ee939ac375 --- /dev/null +++ b/onnxruntime/test/platform/apple/apple_package_test/macos_package_test/main.m @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// AppDelegate.h +// macos_package_test +// + +#import + +int main(int argc, const char* argv[]) { + @autoreleasepool { + // Setup code that might create autoreleased objects goes here. + } + return NSApplicationMain(argc, argv); +} diff --git a/onnxruntime/test/platform/apple/apple_package_test/macos_package_testUITests/macos_package_uitest_cpp_api.mm b/onnxruntime/test/platform/apple/apple_package_test/macos_package_testUITests/macos_package_uitest_cpp_api.mm new file mode 100644 index 0000000000..613c6e5459 --- /dev/null +++ b/onnxruntime/test/platform/apple/apple_package_test/macos_package_testUITests/macos_package_uitest_cpp_api.mm @@ -0,0 +1,108 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// macos_package_test_cpp_api.mm +// macos_package_test_cpp_api +// +// This file hosts the tests of ORT C++ API +// + +#import +#include +#include + +#if __has_include() +#define COREML_EP_AVAILABLE 1 +#else +#define COREML_EP_AVAILABLE 0 +#endif + +#if COREML_EP_AVAILABLE +#include +#endif + +void testSigmoid(const char* modelPath, bool useCoreML) { + // This is an e2e test for ORT C++ API + Ort::Env env(ORT_LOGGING_LEVEL_WARNING, "testCppAPI"); + + // initialize session options if needed + Ort::SessionOptions session_options; + session_options.SetIntraOpNumThreads(1); + +#if COREML_EP_AVAILABLE + if (useCoreML) { + const uint32_t flags = COREML_FLAG_USE_CPU_ONLY; + Ort::ThrowOnError(OrtSessionOptionsAppendExecutionProvider_CoreML(session_options, flags)); + } +#else + (void)useCoreML; +#endif + + Ort::Session session(env, modelPath, session_options); + + size_t input_tensor_size = 3 * 4 * 5; + float input_tensor_values[input_tensor_size]; + float expected_output_values[input_tensor_size]; + const char* input_node_names[] = {"x"}; + const char* output_node_names[] = {"y"}; + const int64_t input_node_dims[] = {3, 4, 5}; + + for (size_t i = 0; i < input_tensor_size; i++) { + input_tensor_values[i] = (float)i - 30; + expected_output_values[i] = 1.0f / (1 + exp(-input_tensor_values[i])); + } + + auto memory_info = Ort::MemoryInfo::CreateCpu(OrtArenaAllocator, OrtMemTypeDefault); + Ort::Value input_tensor = + Ort::Value::CreateTensor(memory_info, input_tensor_values, input_tensor_size, input_node_dims, 3); + XCTAssert(input_tensor.IsTensor()); + + auto output_tensors = session.Run(Ort::RunOptions{nullptr}, input_node_names, + &input_tensor, 1, output_node_names, 1); + XCTAssertEqual(output_tensors.size(), 1); + XCTAssert(output_tensors.front().IsTensor()); + + // Get pointer to output tensor float values + float* output_values = output_tensors.front().GetTensorMutableData(); + for (size_t i = 0; i < input_tensor_size; i++) { + XCTAssertEqualWithAccuracy(expected_output_values[i], output_values[i], 1e-6); + } +} + +@interface macos_package_testUITests : XCTestCase + +@end + +@implementation macos_package_testUITests + +- (void)setUp { + // Put setup code here. This method is called before the invocation of each test method in the class. + + // In UI tests it is usually best to stop immediately when a failure occurs. + self.continueAfterFailure = NO; + + // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. +} + +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. +} + +- (NSString*)getFilePath { + NSBundle* bundle = [NSBundle bundleForClass:[self class]]; + NSString* ns_model_path = [bundle pathForResource:@"sigmoid" ofType:@"ort"]; + XCTAssertNotNil(ns_model_path); + return ns_model_path; +} + +- (void)testCppAPI_Basic { + testSigmoid([self getFilePath].UTF8String, false /* useCoreML */); +} + +#if COREML_EP_AVAILABLE +- (void)testCppAPI_Basic_CoreML { + testSigmoid([self getFilePath].UTF8String, true /* useCoreML */); +} +#endif + +@end diff --git a/onnxruntime/test/platform/ios/ios_package_test/models/sigmoid.ort b/onnxruntime/test/platform/apple/apple_package_test/models/sigmoid.ort similarity index 100% rename from onnxruntime/test/platform/ios/ios_package_test/models/sigmoid.ort rename to onnxruntime/test/platform/apple/apple_package_test/models/sigmoid.ort diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index 3b1a0317c5..76cda428ca 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -378,8 +378,9 @@ 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( - "--ios_sysroot", default="", help="Specify the location name of the macOS platform SDK to be used" + "--apple_sysroot", default="", help="Specify the location name of the macOS platform SDK to be used" ) parser.add_argument( "--ios_toolchain_file", @@ -1273,33 +1274,38 @@ def generate_build_tree( if args.use_snpe: cmake_args += ["-Donnxruntime_USE_SNPE=ON"] - if args.ios: + if args.build_apple_framework or args.ios: if not args.cmake_generator == "Xcode": - raise BuildError("iOS build requires use of the Xcode CMake generator ('--cmake_generator Xcode').") + raise BuildError( + "iOS/MacOS framework build requires use of the Xcode CMake generator ('--cmake_generator Xcode')." + ) needed_args = [ - args.ios_sysroot, + args.apple_sysroot, args.apple_deploy_target, ] arg_names = [ - "--ios_sysroot " + "", + "--apple_sysroot " + "", "--apple_deploy_target " + "", ] if not all(needed_args): raise BuildError( - "iOS build on MacOS canceled due to missing arguments: " + "iOS/MacOS framework build on MacOS canceled due to missing arguments: " + ", ".join(val for val, cond in zip(arg_names, needed_args) if not cond) ) cmake_args += [ - "-DCMAKE_SYSTEM_NAME=iOS", "-Donnxruntime_BUILD_SHARED_LIB=ON", - "-DCMAKE_OSX_SYSROOT=" + args.ios_sysroot, + "-DCMAKE_OSX_SYSROOT=" + args.apple_sysroot, "-DCMAKE_OSX_DEPLOYMENT_TARGET=" + args.apple_deploy_target, # we do not need protoc binary for ios cross build "-Dprotobuf_BUILD_PROTOC_BINARIES=OFF", - "-DCMAKE_TOOLCHAIN_FILE=" - + (args.ios_toolchain_file if args.ios_toolchain_file else "../cmake/onnxruntime_ios.toolchain.cmake"), ] + if args.ios: + cmake_args += [ + "-DCMAKE_SYSTEM_NAME=iOS", + "-DCMAKE_TOOLCHAIN_FILE=" + + (args.ios_toolchain_file if args.ios_toolchain_file else "../cmake/onnxruntime_ios.toolchain.cmake"), + ] if args.build_wasm: emsdk_dir = os.path.join(cmake_dir, "external", "emsdk") @@ -1761,10 +1767,10 @@ def run_ios_tests(args, source_dir, config, cwd): ) if args.build_apple_framework: - package_test_py = os.path.join(source_dir, "tools", "ci_build", "github", "apple", "test_ios_packages.py") + package_test_py = os.path.join(source_dir, "tools", "ci_build", "github", "apple", "test_apple_packages.py") framework_info_file = os.path.join(cwd, "framework_info.json") - dynamic_framework_dir = os.path.join(cwd, config + "-" + args.ios_sysroot) - static_framework_dir = os.path.join(cwd, config + "-" + args.ios_sysroot, "static_framework") + dynamic_framework_dir = os.path.join(cwd, config + "-" + args.apple_sysroot) + static_framework_dir = os.path.join(cwd, config + "-" + args.apple_sysroot, "static_framework") # test dynamic framework run_subprocess( [ @@ -1774,6 +1780,8 @@ def run_ios_tests(args, source_dir, config, cwd): dynamic_framework_dir, "--framework_info_file", framework_info_file, + "--variant", + "Mobile", ], cwd=cwd, ) @@ -1786,6 +1794,8 @@ def run_ios_tests(args, source_dir, config, cwd): static_framework_dir, "--framework_info_file", framework_info_file, + "--variant", + "Mobile", ], cwd=cwd, ) diff --git a/tools/ci_build/github/apple/assemble_ios_packaging_artifacts.sh b/tools/ci_build/github/apple/assemble_apple_packaging_artifacts.sh similarity index 100% rename from tools/ci_build/github/apple/assemble_ios_packaging_artifacts.sh rename to tools/ci_build/github/apple/assemble_apple_packaging_artifacts.sh diff --git a/tools/ci_build/github/apple/build_and_assemble_ios_pods.py b/tools/ci_build/github/apple/build_and_assemble_apple_pods.py similarity index 82% rename from tools/ci_build/github/apple/build_and_assemble_ios_pods.py rename to tools/ci_build/github/apple/build_and_assemble_apple_pods.py index d3443e6cb0..006dc4c33f 100755 --- a/tools/ci_build/github/apple/build_and_assemble_ios_pods.py +++ b/tools/ci_build/github/apple/build_and_assemble_apple_pods.py @@ -32,13 +32,13 @@ def parse_args(): parser.add_argument( "--build-dir", type=pathlib.Path, - default=REPO_DIR / "build" / "ios_framework", + default=REPO_DIR / "build" / "apple_framework", help="The build directory. This will contain the iOS framework build output.", ) parser.add_argument( "--staging-dir", type=pathlib.Path, - default=REPO_DIR / "build" / "ios_pod_staging", + default=REPO_DIR / "build" / "apple_pod_staging", help="The staging directory. This will contain the iOS pod package files. " "The pod package files do not have dependencies on files in the build directory.", ) @@ -60,20 +60,20 @@ def parse_args(): build_framework_group = parser.add_argument_group( title="iOS framework build arguments", - description="See the corresponding arguments in build_ios_framework.py for details.", + description="See the corresponding arguments in build_apple_framework.py for details.", ) build_framework_group.add_argument("--include-ops-by-config") build_framework_group.add_argument( - "--build-settings-file", required=True, help="The positional argument of build_ios_framework.py." + "--build-settings-file", required=True, help="The positional argument of build_apple_framework.py." ) build_framework_group.add_argument( "-b", - "--build-ios-framework-arg", + "--build-apple-framework-arg", action="append", - dest="build_ios_framework_extra_args", + dest="build_apple_framework_extra_args", default=[], - help="Pass an argument through to build_ios_framework.py. This may be specified multiple times.", + help="Pass an argument through to build_apple_framework.py. This may be specified multiple times.", ) args = parser.parse_args() @@ -101,27 +101,27 @@ def main(): # build framework package_variant = PackageVariant[args.variant] - framework_info_file = build_dir / "framework_info.json" + framework_info_file = build_dir / "xcframework_info.json" - log.info("Building iOS framework.") + log.info("Building Apple framework.") - build_ios_framework_args = [ + build_apple_framework_args = [ sys.executable, - str(SCRIPT_DIR / "build_ios_framework.py"), - *args.build_ios_framework_extra_args, + str(SCRIPT_DIR / "build_apple_framework.py"), + *args.build_apple_framework_extra_args, ] if args.include_ops_by_config is not None: - build_ios_framework_args += ["--include_ops_by_config", args.include_ops_by_config] + build_apple_framework_args += ["--include_ops_by_config", args.include_ops_by_config] - build_ios_framework_args += ["--build_dir", str(build_dir), args.build_settings_file] + build_apple_framework_args += ["--build_dir", str(build_dir), args.build_settings_file] - run(build_ios_framework_args) + run(build_apple_framework_args) if args.test: - test_ios_packages_args = [ + test_apple_packages_args = [ sys.executable, - str(SCRIPT_DIR / "test_ios_packages.py"), + str(SCRIPT_DIR / "test_apple_packages.py"), "--fail_if_cocoapods_missing", "--framework_info_file", str(framework_info_file), @@ -131,7 +131,7 @@ def main(): package_variant.name, ] - run(test_ios_packages_args) + run(test_apple_packages_args) # assemble pods and then move them to their target locations (staging_dir/) staging_dir.mkdir(parents=True, exist_ok=True) diff --git a/tools/ci_build/github/apple/build_ios_framework.py b/tools/ci_build/github/apple/build_apple_framework.py similarity index 81% rename from tools/ci_build/github/apple/build_ios_framework.py rename to tools/ci_build/github/apple/build_apple_framework.py index 7983581f07..5137a0644b 100644 --- a/tools/ci_build/github/apple/build_ios_framework.py +++ b/tools/ci_build/github/apple/build_apple_framework.py @@ -30,19 +30,17 @@ def _parse_build_settings(args): build_settings["build_osx_archs"] = build_settings_data.get("build_osx_archs", DEFAULT_BUILD_OSX_ARCHS) - build_params = [] if "build_params" in build_settings_data: - build_params += build_settings_data["build_params"] + build_settings["build_params"] = build_settings_data["build_params"] else: raise ValueError("build_params is required in the build config file") - build_settings["build_params"] = build_params return build_settings # Build fat framework for all archs of a single sysroot # For example, arm64 and x86_64 for iphonesimulator -def _build_for_ios_sysroot( +def _build_for_apple_sysroot( build_config, intermediates_dir, base_build_command, sysroot, archs, build_dynamic_framework ): # paths of the onnxruntime libraries for different archs @@ -54,7 +52,7 @@ def _build_for_ios_sysroot( build_dir_current_arch = os.path.join(intermediates_dir, sysroot + "_" + current_arch) build_command = [ *base_build_command, - "--ios_sysroot=" + sysroot, + "--apple_sysroot=" + sysroot, "--osx_arch=" + current_arch, "--build_dir=" + build_dir_current_arch, ] @@ -103,6 +101,20 @@ def _build_for_ios_sysroot( return framework_dir +def _merge_framework_info_files(files, output_file): + merged_data = {} + + for file in files: + with open(file) as f: + data = json.load(f) + for platform, values in data.items(): + assert platform not in merged_data, f"Duplicate platform value: {platform}" + merged_data[platform] = values + + with open(output_file, "w") as f: + json.dump(merged_data, f, indent=2) + + def _build_package(args): build_settings = _parse_build_settings(args) build_dir = os.path.abspath(args.build_dir) @@ -110,20 +122,26 @@ def _build_package(args): # Temp dirs to hold building results intermediates_dir = os.path.join(build_dir, "intermediates") build_config = args.config - base_build_command = [sys.executable, BUILD_PY] + build_settings["build_params"] + ["--config=" + build_config] - - if args.include_ops_by_config is not None: - base_build_command += ["--include_ops_by_config=" + str(args.include_ops_by_config.resolve())] - - if args.path_to_protoc_exe is not None: - base_build_command += ["--path_to_protoc_exe=" + str(args.path_to_protoc_exe.resolve())] # build framework for individual sysroot framework_dirs = [] - framework_info_path = "" + framework_info_files_to_merge = [] public_headers_path = "" for sysroot in build_settings["build_osx_archs"]: - framework_dir = _build_for_ios_sysroot( + base_build_command = ( + [sys.executable, BUILD_PY] + + build_settings["build_params"]["base"] + + build_settings["build_params"][sysroot] + + ["--config=" + build_config] + ) + + if args.include_ops_by_config is not None: + base_build_command += ["--include_ops_by_config=" + str(args.include_ops_by_config.resolve())] + + if args.path_to_protoc_exe is not None: + base_build_command += ["--path_to_protoc_exe=" + str(args.path_to_protoc_exe.resolve())] + + framework_dir = _build_for_apple_sysroot( build_config, intermediates_dir, base_build_command, @@ -132,17 +150,20 @@ def _build_package(args): args.build_dynamic_framework, ) framework_dirs.append(framework_dir) - # podspec and headers for each sysroot are the same, pick one of them - if not framework_info_path: - framework_info_path = os.path.join(os.path.dirname(framework_dir), "framework_info.json") + + curr_framework_info_path = os.path.join(os.path.dirname(framework_dir), "framework_info.json") + framework_info_files_to_merge.append(curr_framework_info_path) + + # headers for each sysroot are the same, pick one of them + if not public_headers_path: public_headers_path = os.path.join(os.path.dirname(framework_dir), "onnxruntime.framework", "Headers") - # create the folder for xcframework and copy the LICENSE and podspec file + # create the folder for xcframework and copy the LICENSE and framework_info.json file xcframework_dir = os.path.join(build_dir, "framework_out") pathlib.Path(xcframework_dir).mkdir(parents=True, exist_ok=True) shutil.copy(os.path.join(REPO_DIR, "LICENSE"), xcframework_dir) shutil.copytree(public_headers_path, os.path.join(xcframework_dir, "Headers"), dirs_exist_ok=True) - shutil.copy(framework_info_path, build_dir) + _merge_framework_info_files(framework_info_files_to_merge, os.path.join(build_dir, "xcframework_info.json")) # remove existing xcframework if any xcframework_path = os.path.join(xcframework_dir, "onnxruntime.xcframework") @@ -171,7 +192,7 @@ def parse_args(): parser.add_argument( "--build_dir", type=pathlib.Path, - default=os.path.join(REPO_DIR, "build/iOS_framework"), + default=os.path.join(REPO_DIR, "build/apple_framework"), help="Provide the root directory for build output", ) diff --git a/tools/ci_build/github/apple/c/assemble_c_pod_package.py b/tools/ci_build/github/apple/c/assemble_c_pod_package.py index 14e7729610..1d7647dd46 100644 --- a/tools/ci_build/github/apple/c/assemble_c_pod_package.py +++ b/tools/ci_build/github/apple/c/assemble_c_pod_package.py @@ -28,8 +28,6 @@ def get_pod_config_file(package_variant: PackageVariant): return _script_dir / "onnxruntime-c.config.json" elif package_variant == PackageVariant.Mobile: return _script_dir / "onnxruntime-mobile-c.config.json" - elif package_variant == PackageVariant.Test: - return _script_dir / "onnxruntime-test-c.config.json" elif package_variant == PackageVariant.Training: return _script_dir / "onnxruntime-training-c.config.json" else: @@ -49,7 +47,7 @@ def assemble_c_pod_package( :param staging_dir Path to the staging directory for the C/C++ pod files. :param pod_version C/C++ pod version. - :param framework_info_file Path to the framework_info.json file containing additional values for the podspec. + :param framework_info_file Path to the framework_info.json or xcframework_info.json file containing additional values for the podspec. :param public_headers_dir Path to the public headers directory to include in the pod. :param framework_dir Path to the onnxruntime framework directory to include in the pod. :param package_variant The pod package variant. @@ -77,14 +75,16 @@ def assemble_c_pod_package( # generate the podspec file from the template variable_substitutions = { "DESCRIPTION": pod_config["description"], - "IOS_DEPLOYMENT_TARGET": framework_info["IOS_DEPLOYMENT_TARGET"], + # By default, we build both "iphoneos" and "iphonesimulator" architectures, and the deployment target should be the same between these two. + "IOS_DEPLOYMENT_TARGET": framework_info["iphonesimulator"]["APPLE_DEPLOYMENT_TARGET"], + "MACOSX_DEPLOYMENT_TARGET": framework_info.get("macosx", {}).get("APPLE_DEPLOYMENT_TARGET", ""), "LICENSE_FILE": "LICENSE", "NAME": pod_name, "ORT_C_FRAMEWORK": framework_dir.name, "ORT_C_HEADERS_DIR": public_headers_dir.name, "SUMMARY": pod_config["summary"], "VERSION": pod_version, - "WEAK_FRAMEWORK": framework_info["WEAK_FRAMEWORK"], + "WEAK_FRAMEWORK": framework_info["iphonesimulator"]["WEAK_FRAMEWORK"], } podspec_template = _script_dir / "c.podspec.template" @@ -114,7 +114,7 @@ def parse_args(): "--framework-info-file", type=pathlib.Path, required=True, - help="Path to the framework_info.json file containing additional values for the podspec. " + help="Path to the framework_info.json or xcframework_info.json file containing additional values for the podspec. " "This file should be generated by CMake in the build directory.", ) parser.add_argument( diff --git a/tools/ci_build/github/apple/c/c.podspec.template b/tools/ci_build/github/apple/c/c.podspec.template index e0cbfe2360..a04f20b359 100644 --- a/tools/ci_build/github/apple/c/c.podspec.template +++ b/tools/ci_build/github/apple/c/c.podspec.template @@ -6,7 +6,13 @@ Pod::Spec.new do |spec| spec.homepage = "https://github.com/microsoft/onnxruntime" spec.source = { :http => "file:///http_source_placeholder" } spec.summary = "@SUMMARY@" - spec.platform = :ios, "@IOS_DEPLOYMENT_TARGET@" + spec.ios.deployment_target = "@IOS_DEPLOYMENT_TARGET@" + + macosx_deployment_target = "@MACOSX_DEPLOYMENT_TARGET@" + if macosx_deployment_target != "" + spec.osx.deployment_target = macosx_deployment_target + end + spec.vendored_frameworks = "@ORT_C_FRAMEWORK@" spec.static_framework = true spec.weak_framework = [ @WEAK_FRAMEWORK@ ] diff --git a/tools/ci_build/github/apple/c/onnxruntime-test-c.config.json b/tools/ci_build/github/apple/c/onnxruntime-test-c.config.json deleted file mode 100644 index d55dbc63e0..0000000000 --- a/tools/ci_build/github/apple/c/onnxruntime-test-c.config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "onnxruntime-test-c", - "summary": "TEST POD", - "description": "Pod for testing. Not for actual release." -} diff --git a/tools/ci_build/github/apple/default_full_apple_framework_build_settings.json b/tools/ci_build/github/apple/default_full_apple_framework_build_settings.json new file mode 100644 index 0000000000..86b4efdc63 --- /dev/null +++ b/tools/ci_build/github/apple/default_full_apple_framework_build_settings.json @@ -0,0 +1,37 @@ +{ + "build_osx_archs": { + "iphoneos": [ + "arm64" + ], + "iphonesimulator": [ + "arm64", + "x86_64" + ], + "macosx": [ + "arm64", + "x86_64" + ] + }, + "build_params": { + "base": [ + "--parallel", + "--use_xcode", + "--build_apple_framework", + "--use_coreml", + "--use_xnnpack", + "--skip_tests", + "--cmake_extra_defines=onnxruntime_BUILD_UNIT_TESTS=OFF" + ], + "macosx": [ + "--apple_deploy_target=11.0" + ], + "iphoneos": [ + "--ios", + "--apple_deploy_target=12.0" + ], + "iphonesimulator": [ + "--ios", + "--apple_deploy_target=12.0" + ] + } +} diff --git a/tools/ci_build/github/apple/default_full_ios_framework_build_settings.json b/tools/ci_build/github/apple/default_full_ios_framework_build_settings.json deleted file mode 100644 index 621af55fad..0000000000 --- a/tools/ci_build/github/apple/default_full_ios_framework_build_settings.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "build_osx_archs": { - "iphoneos": [ - "arm64" - ], - "iphonesimulator": [ - "arm64", - "x86_64" - ] - }, - "build_params": [ - "--ios", - "--parallel", - "--use_xcode", - "--build_apple_framework", - "--use_coreml", - "--use_xnnpack", - "--skip_tests", - "--cmake_extra_defines=onnxruntime_BUILD_UNIT_TESTS=OFF", - "--apple_deploy_target=12.0" - ] -} diff --git a/tools/ci_build/github/apple/default_mobile_ios_framework_build_settings.json b/tools/ci_build/github/apple/default_mobile_ios_framework_build_settings.json index 2738a7ca7b..2bdf8de24f 100644 --- a/tools/ci_build/github/apple/default_mobile_ios_framework_build_settings.json +++ b/tools/ci_build/github/apple/default_mobile_ios_framework_build_settings.json @@ -8,19 +8,27 @@ "x86_64" ] }, - "build_params": [ - "--ios", - "--parallel", - "--use_xcode", - "--build_apple_framework", - "--minimal_build=extended", - "--disable_rtti", - "--disable_ml_ops", - "--disable_exceptions", - "--enable_reduced_operator_type_support", - "--use_coreml", - "--skip_tests", - "--cmake_extra_defines=onnxruntime_BUILD_UNIT_TESTS=OFF", - "--apple_deploy_target=12.0" - ] + "build_params": { + "base": [ + "--parallel", + "--use_xcode", + "--build_apple_framework", + "--minimal_build=extended", + "--disable_rtti", + "--disable_ml_ops", + "--disable_exceptions", + "--enable_reduced_operator_type_support", + "--use_coreml", + "--skip_tests", + "--cmake_extra_defines=onnxruntime_BUILD_UNIT_TESTS=OFF" + ], + "iphoneos": [ + "--ios", + "--apple_deploy_target=12.0" + ], + "iphonesimulator": [ + "--ios", + "--apple_deploy_target=12.0" + ] + } } diff --git a/tools/ci_build/github/apple/default_training_ios_framework_build_settings.json b/tools/ci_build/github/apple/default_training_ios_framework_build_settings.json index ec7fcafce0..f88934cd44 100644 --- a/tools/ci_build/github/apple/default_training_ios_framework_build_settings.json +++ b/tools/ci_build/github/apple/default_training_ios_framework_build_settings.json @@ -6,18 +6,33 @@ "iphonesimulator": [ "arm64", "x86_64" + ], + "macosx": [ + "arm64", + "x86_64" ] }, - "build_params": [ - "--ios", - "--parallel", - "--use_xcode", - "--enable_training_apis", - "--build_apple_framework", - "--use_coreml", - "--use_xnnpack", - "--skip_tests", - "--cmake_extra_defines=onnxruntime_BUILD_UNIT_TESTS=OFF", - "--apple_deploy_target=12.0" - ] + "build_params": { + "base": [ + "--parallel", + "--use_xcode", + "--enable_training_apis", + "--build_apple_framework", + "--use_coreml", + "--use_xnnpack", + "--skip_tests", + "--cmake_extra_defines=onnxruntime_BUILD_UNIT_TESTS=OFF" + ], + "iphoneos": [ + "--ios", + "--apple_deploy_target=12.0" + ], + "iphonesimulator": [ + "--ios", + "--apple_deploy_target=12.0" + ], + "macosx": [ + "--apple_deploy_target=11.0" + ] + } } diff --git a/tools/ci_build/github/apple/framework_info.json.template b/tools/ci_build/github/apple/framework_info.json.template index 788e52302b..b4c4fb8d16 100644 --- a/tools/ci_build/github/apple/framework_info.json.template +++ b/tools/ci_build/github/apple/framework_info.json.template @@ -1,4 +1,6 @@ { - "IOS_DEPLOYMENT_TARGET": "@CMAKE_OSX_DEPLOYMENT_TARGET@", - "WEAK_FRAMEWORK": "@APPLE_WEAK_FRAMEWORK@" -} \ No newline at end of file + "@CMAKE_OSX_SYSROOT@": { + "APPLE_DEPLOYMENT_TARGET": "@CMAKE_OSX_DEPLOYMENT_TARGET@", + "WEAK_FRAMEWORK": "@APPLE_WEAK_FRAMEWORK@" + } +} diff --git a/tools/ci_build/github/apple/objectivec/assemble_objc_pod_package.py b/tools/ci_build/github/apple/objectivec/assemble_objc_pod_package.py index 135a55165b..ec1feaae82 100755 --- a/tools/ci_build/github/apple/objectivec/assemble_objc_pod_package.py +++ b/tools/ci_build/github/apple/objectivec/assemble_objc_pod_package.py @@ -119,7 +119,7 @@ def assemble_objc_pod_package( :param staging_dir Path to the staging directory for the Objective-C pod files. :param pod_version Objective-C pod version. - :param framework_info_file Path to the framework_info.json file containing additional values for the podspec. + :param framework_info_file Path to the framework_info.json or xcframework_info.json file containing additional values for the podspec. :param package_variant The pod package variant. :return Tuple of (package name, path to the podspec file). """ @@ -153,7 +153,7 @@ def assemble_objc_pod_package( "C_POD_NAME": c_pod_config["name"], "DESCRIPTION": pod_config["description"], "INCLUDE_DIR_LIST": path_patterns_as_variable_value(include_dirs), - "IOS_DEPLOYMENT_TARGET": framework_info["IOS_DEPLOYMENT_TARGET"], + "IOS_DEPLOYMENT_TARGET": framework_info["iphonesimulator"]["APPLE_DEPLOYMENT_TARGET"], "LICENSE_FILE": license_file, "NAME": pod_name, "PUBLIC_HEADER_FILE_LIST": path_patterns_as_variable_value(pod_files["public_header_files"]), @@ -191,7 +191,7 @@ def parse_args(): "--framework-info-file", type=pathlib.Path, required=True, - help="Path to the framework_info.json file containing additional values for the podspec. " + help="Path to the framework_info.json or xcframework_info.json file containing additional values for the podspec. " "This file should be generated by CMake in the build directory.", ) parser.add_argument( diff --git a/tools/ci_build/github/apple/package_assembly_utils.py b/tools/ci_build/github/apple/package_assembly_utils.py index e5940774c5..bdf359df1d 100644 --- a/tools/ci_build/github/apple/package_assembly_utils.py +++ b/tools/ci_build/github/apple/package_assembly_utils.py @@ -17,7 +17,6 @@ class PackageVariant(enum.Enum): Full = 0 # full ORT build with all opsets, ops, and types Mobile = 1 # minimal ORT build with reduced ops Training = 2 # full ORT build with all opsets, ops, and types, plus training APIs - Test = -1 # for testing purposes only @classmethod def release_variant_names(cls): diff --git a/tools/ci_build/github/apple/test_ios_packages.py b/tools/ci_build/github/apple/test_apple_packages.py similarity index 87% rename from tools/ci_build/github/apple/test_ios_packages.py rename to tools/ci_build/github/apple/test_apple_packages.py index ff42e96154..6dc4868dac 100644 --- a/tools/ci_build/github/apple/test_ios_packages.py +++ b/tools/ci_build/github/apple/test_apple_packages.py @@ -19,7 +19,7 @@ SCRIPT_PATH = pathlib.Path(__file__).resolve(strict=True) REPO_DIR = SCRIPT_PATH.parents[4] -def _test_ios_packages(args): +def _test_apple_packages(args): # check if CocoaPods is installed if shutil.which("pod") is None: if args.fail_if_cocoapods_missing: @@ -58,10 +58,10 @@ def _test_ios_packages(args): os.makedirs(stage_dir) # assemble the test project here - target_proj_path = stage_dir / "ios_package_test" + target_proj_path = stage_dir / "apple_package_test" # copy the test project source files to target_proj_path - test_proj_path = pathlib.Path(REPO_DIR, "onnxruntime/test/platform/ios/ios_package_test") + test_proj_path = pathlib.Path(REPO_DIR, "onnxruntime/test/platform/apple/apple_package_test") shutil.copytree(test_proj_path, target_proj_path) # assemble local pod files here @@ -133,7 +133,7 @@ def _test_ios_packages(args): "xcodebuild", "test", "-workspace", - "./ios_package_test.xcworkspace", + "./apple_package_test.xcworkspace", "-scheme", "ios_package_test", "-destination", @@ -144,6 +144,24 @@ def _test_ios_packages(args): cwd=target_proj_path, ) + if PackageVariant[args.variant] != PackageVariant.Mobile: + subprocess.run( + [ + "xcrun", + "xcodebuild", + "test", + "-workspace", + "./apple_package_test.xcworkspace", + "-scheme", + "macos_package_test", + "-destination", + "platform=macos", + ], + shell=False, + check=True, + cwd=target_proj_path, + ) + def parse_args(): parser = argparse.ArgumentParser( @@ -161,7 +179,7 @@ def parse_args(): "--framework_info_file", type=pathlib.Path, required=True, - help="Path to the framework_info.json file containing additional values for the podspec. " + help="Path to the framework_info.json or xcframework_info.json file containing additional values for the podspec. " "This file should be generated by CMake in the build directory.", ) @@ -172,7 +190,7 @@ def parse_args(): parser.add_argument( "--variant", choices=PackageVariant.all_variant_names(), - default=PackageVariant.Test.name, + required=True, help="Pod package variant.", ) @@ -193,7 +211,7 @@ def parse_args(): def main(): args = parse_args() - _test_ios_packages(args) + _test_apple_packages(args) if __name__ == "__main__": diff --git a/tools/ci_build/github/apple/use_ios_pods_with_custom_build.md b/tools/ci_build/github/apple/use_ios_pods_with_custom_build.md index c01f0796db..c8da2eff57 100644 --- a/tools/ci_build/github/apple/use_ios_pods_with_custom_build.md +++ b/tools/ci_build/github/apple/use_ios_pods_with_custom_build.md @@ -2,9 +2,9 @@ If you require a custom build of ONNX Runtime, you can create CocoaPods pods with your custom build locally and use them from a Podfile. -**Prerequisite** - The custom build must be able to be done with [build_ios_framework.py](./build_ios_framework.py). +**Prerequisite** - The custom build must be able to be done with [build_apple_framework.py](./build_apple_framework.py). -To do a custom build and create the pods, run [build_and_assemble_ios_pods.py](./build_and_assemble_ios_pods.py). +To do a custom build and create the pods, run [build_and_assemble_apple_pods.py](./build_and_assemble_apple_pods.py). Use the `--help` argument to see more information. ## Example usage @@ -15,7 +15,7 @@ Our custom build will use a custom reduced operator kernel config file: `/path/t Run the script: ```bash -python3 tools/ci_build/github/apple/build_and_assemble_ios_pods.py \ +python3 tools/ci_build/github/apple/build_and_assemble_apple_pods.py \ --staging-dir /path/to/staging/dir \ --include-ops-by-config /path/to/custom.config \ --build-settings-file tools/ci_build/github/apple/default_mobile_ios_framework_build_settings.json diff --git a/tools/ci_build/github/azure-pipelines/mac-ios-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/mac-ios-ci-pipeline.yml index b1d7ede284..18d53654e7 100644 --- a/tools/ci_build/github/azure-pipelines/mac-ios-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/mac-ios-ci-pipeline.yml @@ -54,7 +54,7 @@ jobs: --use_coreml \ --use_xnnpack \ --ios \ - --ios_sysroot iphonesimulator \ + --apple_sysroot iphonesimulator \ --osx_arch x86_64 \ --apple_deploy_target 12.0 \ --use_xcode \ diff --git a/tools/ci_build/github/azure-pipelines/post-merge-jobs.yml b/tools/ci_build/github/azure-pipelines/post-merge-jobs.yml index 6fdb255606..c86920422b 100644 --- a/tools/ci_build/github/azure-pipelines/post-merge-jobs.yml +++ b/tools/ci_build/github/azure-pipelines/post-merge-jobs.yml @@ -286,14 +286,15 @@ stages: displayName: "Install Python requirements" - script: | - python tools/ci_build/github/apple/build_ios_framework.py \ + python tools/ci_build/github/apple/build_apple_framework.py \ --build_dir "$(Build.BinariesDirectory)/ios_framework" \ --build_dynamic_framework \ tools/ci_build/github/apple/default_mobile_ios_framework_build_settings.json displayName: "Build iOS dynamic framework" - script: | - python tools/ci_build/github/apple/test_ios_packages.py \ - --framework_info_file "$(Build.BinariesDirectory)/ios_framework/framework_info.json" \ - --c_framework_dir "$(Build.BinariesDirectory)/ios_framework/framework_out" + python tools/ci_build/github/apple/test_apple_packages.py \ + --framework_info_file "$(Build.BinariesDirectory)/ios_framework/xcframework_info.json" \ + --c_framework_dir "$(Build.BinariesDirectory)/ios_framework/framework_out" \ + --variant Mobile displayName: "Test pod with iOS dynamic framework" diff --git a/tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml b/tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml index cfd2931665..87fd4de7d3 100644 --- a/tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml +++ b/tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml @@ -117,32 +117,32 @@ stages: - script: | set -e -x - python3 tools/ci_build/github/apple/build_ios_framework.py \ - --build_dir "$(Build.BinariesDirectory)/ios_framework" \ + python3 tools/ci_build/github/apple/build_apple_framework.py \ + --build_dir "$(Build.BinariesDirectory)/apple_framework" \ --path_to_protoc_exe $(Build.BinariesDirectory)/protobuf_install/bin/protoc \ - tools/ci_build/github/apple/default_full_ios_framework_build_settings.json + tools/ci_build/github/apple/default_full_apple_framework_build_settings.json mkdir $(Build.BinariesDirectory)/artifacts - mkdir -p $(Build.BinariesDirectory)/artifacts_staging/onnxruntime-ios-xcframework-$(OnnxRuntimeVersion) - cp -R $(Build.BinariesDirectory)/ios_framework/framework_out/onnxruntime.xcframework \ - $(Build.BinariesDirectory)/artifacts_staging/onnxruntime-ios-xcframework-$(OnnxRuntimeVersion) + mkdir -p $(Build.BinariesDirectory)/artifacts_staging/onnxruntime-apple-xcframework-$(OnnxRuntimeVersion) + cp -R $(Build.BinariesDirectory)/apple_framework/framework_out/onnxruntime.xcframework \ + $(Build.BinariesDirectory)/artifacts_staging/onnxruntime-apple-xcframework-$(OnnxRuntimeVersion) pushd $(Build.BinariesDirectory)/artifacts_staging zip -vr $(Build.BinariesDirectory)/artifacts/onnxruntime_xcframework.zip \ - onnxruntime-ios-xcframework-$(OnnxRuntimeVersion) + onnxruntime-apple-xcframework-$(OnnxRuntimeVersion) popd - displayName: "Build iOS xcframework" + displayName: "Build Apple xcframework" - script: | - python3 tools/ci_build/github/apple/test_ios_packages.py \ + python3 tools/ci_build/github/apple/test_apple_packages.py \ --fail_if_cocoapods_missing \ - --framework_info_file "$(Build.BinariesDirectory)/ios_framework/framework_info.json" \ - --c_framework_dir "$(Build.BinariesDirectory)/ios_framework/framework_out" \ + --framework_info_file "$(Build.BinariesDirectory)/apple_framework/xcframework_info.json" \ + --c_framework_dir "$(Build.BinariesDirectory)/apple_framework/framework_out" \ --variant Full - displayName: "Test iOS framework" + displayName: "Test Apple framework" - task: PublishBuildArtifacts@1 inputs: pathtoPublish: '$(Build.BinariesDirectory)/artifacts' - artifactName: 'onnxruntime-ios-full-xcframework' + artifactName: 'onnxruntime-apple-full-xcframework' - template: component-governance-component-detection-steps.yml parameters: diff --git a/tools/ci_build/github/azure-pipelines/templates/react-native-ci.yml b/tools/ci_build/github/azure-pipelines/templates/react-native-ci.yml index 33f956f931..47cd72f412 100644 --- a/tools/ci_build/github/azure-pipelines/templates/react-native-ci.yml +++ b/tools/ci_build/github/azure-pipelines/templates/react-native-ci.yml @@ -126,7 +126,7 @@ stages: BuildStep: - script: | set -e -x - python $(Build.SourcesDirectory)/tools/ci_build/github/apple/build_and_assemble_ios_pods.py \ + python $(Build.SourcesDirectory)/tools/ci_build/github/apple/build_and_assemble_apple_pods.py \ --build-dir "$(Build.BinariesDirectory)/ios_framework_full" \ --staging-dir "$(Build.BinariesDirectory)/staging" \ --variant Full \ @@ -134,7 +134,7 @@ stages: -b="--path_to_protoc_exe" -b "$(Build.BinariesDirectory)/installed/bin/protoc" # Mobile build: - # python $(Build.SourcesDirectory)/tools/ci_build/github/apple/build_and_assemble_ios_pods.py \ + # python $(Build.SourcesDirectory)/tools/ci_build/github/apple/build_and_assemble_apple_pods.py \ # --build_dir $(Build.BinariesDirectory)/ios_framework_mobile \ # --staging-dir "$(Build.BinariesDirectory)/staging" \ # --include_ops_by_config $(Build.SourcesDirectory)/tools/ci_build/github/android/mobile_package.required_operators.config \ diff --git a/tools/ci_build/github/azure-pipelines/templates/stages/mac-ios-packaging-build-stage.yml b/tools/ci_build/github/azure-pipelines/templates/stages/mac-ios-packaging-build-stage.yml index 81f17a26b1..1a7915172e 100644 --- a/tools/ci_build/github/azure-pipelines/templates/stages/mac-ios-packaging-build-stage.yml +++ b/tools/ci_build/github/azure-pipelines/templates/stages/mac-ios-packaging-build-stage.yml @@ -29,7 +29,7 @@ stages: objcPodName: onnxruntime-mobile-objc ${{ if eq(parameters.packageVariant, 'Full') }}: - buildSettingsFile: "tools/ci_build/github/apple/default_full_ios_framework_build_settings.json" + buildSettingsFile: "tools/ci_build/github/apple/default_full_apple_framework_build_settings.json" cPodName: onnxruntime-c objcPodName: onnxruntime-objc @@ -38,7 +38,7 @@ stages: cPodName: onnxruntime-training-c objcPodName: onnxruntime-training-objc - timeoutInMinutes: 120 + timeoutInMinutes: 180 steps: - script: | @@ -84,8 +84,8 @@ stages: # create and test mobile pods - script: | - python tools/ci_build/github/apple/build_and_assemble_ios_pods.py \ - --build-dir "$(Build.BinariesDirectory)/ios_framework" \ + python tools/ci_build/github/apple/build_and_assemble_apple_pods.py \ + --build-dir "$(Build.BinariesDirectory)/apple_framework" \ --staging-dir "$(Build.BinariesDirectory)/staging" \ --pod-version "$(ortPodVersion)" \ --test \ @@ -93,13 +93,13 @@ stages: --build-settings-file "${{ variables.buildSettingsFile }}" \ ${{ variables.optionalIncludeOpsByConfigOption }} \ -b="--path_to_protoc_exe=$(Build.BinariesDirectory)/protobuf_install/bin/protoc" - displayName: "Build iOS framework and assemble pod package files" + displayName: "Build macOS/iOS framework and assemble pod package files" - script: | - python tools/ci_build/github/apple/test_ios_packages.py \ + python tools/ci_build/github/apple/test_apple_packages.py \ --fail_if_cocoapods_missing \ - --framework_info_file "$(Build.BinariesDirectory)/ios_framework/framework_info.json" \ - --c_framework_dir "$(Build.BinariesDirectory)/ios_framework/framework_out" \ + --framework_info_file "$(Build.BinariesDirectory)/apple_framework/xcframework_info.json" \ + --c_framework_dir "$(Build.BinariesDirectory)/apple_framework/framework_out" \ --variant ${{ parameters.packageVariant }} \ --test_project_stage_dir "$(Build.BinariesDirectory)/app_center_test" \ --prepare_test_project_only @@ -109,7 +109,7 @@ stages: inputs: actions: 'build-for-testing' configuration: 'Debug' - xcWorkspacePath: '$(Build.BinariesDirectory)/app_center_test/ios_package_test/ios_package_test.xcworkspace' + xcWorkspacePath: '$(Build.BinariesDirectory)/app_center_test/apple_package_test/apple_package_test.xcworkspace' sdk: 'iphoneos' scheme: 'ios_package_test' xcodeVersion: 'specifyPath' @@ -118,8 +118,8 @@ stages: signingIdentity: '$(APPLE_CERTIFICATE_SIGNING_IDENTITY)' provisioningProfileName: 'temporary *' # temporary name, change it back to the original below later #provisioningProfileName: 'iOS Team Provisioning Profile' - args: '-derivedDataPath $(Build.BinariesDirectory)/app_center_test/ios_package_test/DerivedData' - workingDirectory: '$(Build.BinariesDirectory)/app_center_test/ios_package_test/' + args: '-derivedDataPath $(Build.BinariesDirectory)/app_center_test/apple_package_test/DerivedData' + workingDirectory: '$(Build.BinariesDirectory)/app_center_test/apple_package_test/' useXcpretty: false # xcpretty can hide useful error output so we will disable it displayName: 'Build App Center iPhone arm64 tests' @@ -130,7 +130,7 @@ stages: --devices $(app_center_test_devices) \ --test-series "master" \ --locale "en_US" \ - --build-dir $(Build.BinariesDirectory)/app_center_test/ios_package_test/DerivedData/Build/Products/Debug-iphoneos \ + --build-dir $(Build.BinariesDirectory)/app_center_test/apple_package_test/DerivedData/Build/Products/Debug-iphoneos \ --token $(app_center_api_token) displayName: "Run E2E tests on App Center" @@ -139,7 +139,7 @@ stages: for POD_NAME in "${{ variables.cPodName}}" "${{ variables.objcPodName }}"; do - ./tools/ci_build/github/apple/assemble_ios_packaging_artifacts.sh \ + ./tools/ci_build/github/apple/assemble_apple_packaging_artifacts.sh \ "$(Build.BinariesDirectory)/staging" \ "$(Build.ArtifactStagingDirectory)" \ "${POD_NAME}" \ diff --git a/tools/ci_build/github/js/react_native_e2e_full_ios_framework_build_settings.json b/tools/ci_build/github/js/react_native_e2e_full_ios_framework_build_settings.json index d15326de41..78de7edb5e 100644 --- a/tools/ci_build/github/js/react_native_e2e_full_ios_framework_build_settings.json +++ b/tools/ci_build/github/js/react_native_e2e_full_ios_framework_build_settings.json @@ -4,13 +4,17 @@ "x86_64" ] }, - "build_params": [ - "--ios", - "--parallel", - "--use_xcode", - "--build_apple_framework", - "--use_coreml", - "--skip_tests", - "--apple_deploy_target=12.0" - ] + "build_params": { + "base": [ + "--parallel", + "--use_xcode", + "--build_apple_framework", + "--use_coreml", + "--skip_tests" + ], + "iphonesimulator": [ + "--ios", + "--apple_deploy_target=12.0" + ] + } } diff --git a/tools/ci_build/github/js/react_native_e2e_mobile_ios_framework_build_settings.json b/tools/ci_build/github/js/react_native_e2e_mobile_ios_framework_build_settings.json index e733885399..3d80231393 100644 --- a/tools/ci_build/github/js/react_native_e2e_mobile_ios_framework_build_settings.json +++ b/tools/ci_build/github/js/react_native_e2e_mobile_ios_framework_build_settings.json @@ -4,18 +4,22 @@ "x86_64" ] }, - "build_params": [ - "--ios", - "--parallel", - "--use_xcode", - "--build_apple_framework", - "--minimal_build=extended", - "--disable_rtti", - "--disable_ml_ops", - "--disable_exceptions", - "--enable_reduced_operator_type_support", - "--use_coreml", - "--skip_tests", - "--apple_deploy_target=12.0" - ] + "build_params": { + "base": [ + "--parallel", + "--use_xcode", + "--build_apple_framework", + "--minimal_build=extended", + "--disable_rtti", + "--disable_ml_ops", + "--disable_exceptions", + "--enable_reduced_operator_type_support", + "--use_coreml", + "--skip_tests" + ], + "iphonesimulator": [ + "--ios", + "--apple_deploy_target=12.0" + ] + } }