Skip to content

Commit

Permalink
Fix iOS artifacts issue in Microsoft.ML.OnnxRuntime Nuget Package (#1…
Browse files Browse the repository at this point in the history
…9311)

### Description
<!-- Describe your changes. -->

Updates to only include ios archs framework in artifacts included in
Nuget Package.


### 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. -->

Related issue:
#19295 (comment)

---------

Co-authored-by: rachguo <rachguo@rachguos-Mini.attlocal.net>
Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com>
  • Loading branch information
3 people authored and rachguo committed Jan 30, 2024
1 parent 674afbe commit ed8b7a6
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
def include_macos_target
if '@C_POD_NAME@' != 'onnxruntime-mobile-c'
return true
if ENV['SKIP_MACOS_TEST'] != 'true'
return true
else
return false
end
end
return false
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"build_osx_archs": {
"iphoneos": [
"arm64"
],
"iphonesimulator": [
"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"
],
"iphoneos": [
"--ios",
"--apple_deploy_target=12.0"
],
"iphonesimulator": [
"--ios",
"--apple_deploy_target=12.0"
]
}
}
13 changes: 11 additions & 2 deletions tools/ci_build/github/apple/test_apple_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ def _test_apple_packages(args):
subprocess.run(["pod", "cache", "clean", "--all"], shell=False, check=True, cwd=target_proj_path)

# install pods
subprocess.run(["pod", "install"], shell=False, check=True, cwd=target_proj_path)
# set env to skip macos test targets accordingly
env = os.environ.copy()
env["SKIP_MACOS_TEST"] = "true" if args.skip_macos_test else "false"
subprocess.run(["pod", "install"], shell=False, check=True, cwd=target_proj_path, env=env)

# run the tests
if not args.prepare_test_project_only:
Expand Down Expand Up @@ -144,7 +147,7 @@ def _test_apple_packages(args):
cwd=target_proj_path,
)

if PackageVariant[args.variant] != PackageVariant.Mobile:
if PackageVariant[args.variant] != PackageVariant.Mobile and not args.skip_macos_test:
subprocess.run(
[
"xcrun",
Expand Down Expand Up @@ -206,6 +209,12 @@ def parse_args():
help="Prepare the test project only, without running the tests",
)

parser.add_argument(
"--skip_macos_test",
action="store_true",
help="Skip macos platform tests. Specify this argument when build targets only contain ios archs. ",
)

return parser.parse_args()


Expand Down
23 changes: 12 additions & 11 deletions tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,31 +119,32 @@ stages:
- script: |
set -e -x
python3 tools/ci_build/github/apple/build_apple_framework.py \
--build_dir "$(Build.BinariesDirectory)/apple_framework" \
--build_dir "$(Build.BinariesDirectory)/ios_framework" \
--path_to_protoc_exe $(Build.BinariesDirectory)/protobuf_install/bin/protoc \
tools/ci_build/github/apple/default_full_apple_framework_build_settings.json
tools/ci_build/github/apple/default_full_ios_framework_build_settings.json
mkdir $(Build.BinariesDirectory)/artifacts
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)
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)
pushd $(Build.BinariesDirectory)/artifacts_staging
zip -vr $(Build.BinariesDirectory)/artifacts/onnxruntime_xcframework.zip \
onnxruntime-apple-xcframework-$(OnnxRuntimeVersion)
onnxruntime-ios-xcframework-$(OnnxRuntimeVersion)
popd
displayName: "Build Apple xcframework"
- script: |
python3 tools/ci_build/github/apple/test_apple_packages.py \
--fail_if_cocoapods_missing \
--framework_info_file "$(Build.BinariesDirectory)/apple_framework/xcframework_info.json" \
--c_framework_dir "$(Build.BinariesDirectory)/apple_framework/framework_out" \
--variant Full
--framework_info_file "$(Build.BinariesDirectory)/ios_framework/xcframework_info.json" \
--c_framework_dir "$(Build.BinariesDirectory)/ios_framework/framework_out" \
--variant Full \
--skip_macos_test
displayName: "Test Apple framework"
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: '$(Build.BinariesDirectory)/artifacts'
artifactName: 'onnxruntime-apple-full-xcframework'
artifactName: 'onnxruntime-ios-full-xcframework'

- template: component-governance-component-detection-steps.yml
parameters:
Expand Down Expand Up @@ -350,7 +351,7 @@ stages:
- template: flex-downloadPipelineArtifact.yml
parameters:
StepName: 'Download iOS Pipeline Artifact'
ArtifactName: 'onnxruntime-apple-full-xcframework'
ArtifactName: 'onnxruntime-ios-full-xcframework'
TargetPath: '$(Build.BinariesDirectory)/nuget-artifact'
SpecificArtifact: ${{ parameters.specificArtifact }}
BuildId: ${{ parameters.BuildId }}
Expand Down

0 comments on commit ed8b7a6

Please sign in to comment.