From 410ae94e9e136e6fbc5ee368b4605c658cc7dfd0 Mon Sep 17 00:00:00 2001 From: Scott McKay Date: Fri, 9 Aug 2024 17:38:18 +1000 Subject: [PATCH] Use zipped xcframework in nuget package (#21663) ### Description The xcframework now uses symlinks to have the correct structure according to Apple requirements. Symlinks are not supported by nuget on Windows. In order to work around that we can store a zip of the xcframeworks in the nuget package. ### Motivation and Context Fix nuget packaging build break --- .../targets/net8.0-ios/targets.xml | 4 ++-- .../azure-pipelines/templates/c-api-cpu.yml | 9 +++------ .../github/windows/extract_nuget_files.ps1 | 20 ++++++++++++++++++- .../nuget/generate_nuspec_for_native_nuget.py | 6 ++++-- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/csharp/src/Microsoft.ML.OnnxRuntime/targets/net8.0-ios/targets.xml b/csharp/src/Microsoft.ML.OnnxRuntime/targets/net8.0-ios/targets.xml index 3eb9720af5..c6dbba8dfd 100644 --- a/csharp/src/Microsoft.ML.OnnxRuntime/targets/net8.0-ios/targets.xml +++ b/csharp/src/Microsoft.ML.OnnxRuntime/targets/net8.0-ios/targets.xml @@ -1,7 +1,7 @@ - + Static True True @@ -10,4 +10,4 @@ CoreML - \ No newline at end of file + 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 0368c91290..74fc64fa53 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 @@ -107,12 +107,9 @@ stages: --build_dir "$(Build.BinariesDirectory)/ios_framework" \ tools/ci_build/github/apple/default_full_ios_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) - pushd $(Build.BinariesDirectory)/artifacts_staging - zip -vry $(Build.BinariesDirectory)/artifacts/onnxruntime_xcframework.zip \ - onnxruntime-ios-xcframework-$(OnnxRuntimeVersion) + pushd $(Build.BinariesDirectory)/ios_framework/framework_out + zip -vry $(Build.BinariesDirectory)/artifacts/onnxruntime_ios_xcframework.$(OnnxRuntimeVersion).zip \ + onnxruntime.xcframework popd displayName: "Build Apple xcframework" diff --git a/tools/ci_build/github/windows/extract_nuget_files.ps1 b/tools/ci_build/github/windows/extract_nuget_files.ps1 index 68757e25b0..095153cb6a 100644 --- a/tools/ci_build/github/windows/extract_nuget_files.ps1 +++ b/tools/ci_build/github/windows/extract_nuget_files.ps1 @@ -10,7 +10,8 @@ New-Item -Path $nuget_artifacts_dir -ItemType directory ## .zip files # unzip directly -Get-ChildItem $Env:BUILD_BINARIESDIRECTORY\nuget-artifact -Filter *.zip | +# exclude the iOS xcframework as we need to leave that zipped up to preserve symlinks +Get-ChildItem -Path $Env:BUILD_BINARIESDIRECTORY\nuget-artifact\* -Include *.zip -Exclude onnxruntime_ios_xcframework.*.zip | Foreach-Object { $cmd = "7z.exe x $($_.FullName) -y -o$nuget_artifacts_dir" Write-Output $cmd @@ -34,6 +35,23 @@ Foreach-Object { Invoke-Expression -Command $cmd } +# process iOS xcframework +$xcframeworks = Get-ChildItem $Env:BUILD_BINARIESDIRECTORY\nuget-artifact -Filter onnxruntime_ios_xcframework.*.zip +if ($xcframeworks.Count -eq 1) { + $xcframework = $xcframeworks[0] + $target_dir = "$nuget_artifacts_dir\onnxruntime-ios-xcframework" + # remove version info from filename and use required filename format + $target_file = "$target_dir\onnxruntime.xcframework.zip" + New-Item -Path $target_dir -ItemType directory + + Write-Output "Copy-Item $($xcframework.FullName) $target_file" + Copy-Item $xcframework.FullName $target_file +} +elseif ($xcframeworks.Count -gt 1) { + Write-Error "Expected at most one onnxruntime_ios_xcframework*.zip file but got: [$xcframeworks]" +} + + # copy android AAR. # for full build of onnxruntime Android AAR, there should only be one .aar file # called onnxruntime-android-x.y.z.aar or onnxruntime-training-android-x.y.z.aar but sanity check that diff --git a/tools/nuget/generate_nuspec_for_native_nuget.py b/tools/nuget/generate_nuspec_for_native_nuget.py index a005bd4c4b..2dda41a5a3 100644 --- a/tools/nuget/generate_nuspec_for_native_nuget.py +++ b/tools/nuget/generate_nuspec_for_native_nuget.py @@ -105,8 +105,10 @@ def generate_file_list_for_ep(nuget_artifacts_dir, ep, files_list, include_pdbs, if child_file.suffix in [".aar"]: files_list.append('') - if child.name == "onnxruntime-ios-xcframework": - files_list.append('') # noqa: ISC001 + if child.name == "onnxruntime-ios": + for child_file in child.iterdir(): + if child_file.suffix in [".zip"]: + files_list.append('') def parse_arguments():