Skip to content

Commit b27fbbe

Browse files
prathikrvraspar
andauthored
Update macosx framework packaging to follow apple guidelines (#776) (#789)
* Update macosx framework packaging to follow apple guidelines * Test path fix * Update tools/ci_build/extract_nuget_files.ps1 --------- Co-authored-by: vraspar <vrajang@outlook.com>
1 parent c7a2d45 commit b27fbbe

9 files changed

Lines changed: 92 additions & 34 deletions

File tree

.pipelines/ios_packaging.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ jobs:
162162
pushd ${POD_STAGING_DIR}
163163
164164
# assemble the files in the artifacts staging directory
165-
zip -r ${ARTIFACTS_STAGING_DIR}/${POD_ARCHIVE_BASENAME} * --exclude ${PODSPEC_BASENAME}
165+
zip -vry ${ARTIFACTS_STAGING_DIR}/${POD_ARCHIVE_BASENAME} * --exclude ${PODSPEC_BASENAME}
166166
cp ${PODSPEC_BASENAME} ${ARTIFACTS_STAGING_DIR}/${PODSPEC_BASENAME}
167167
168168
popd

.pipelines/templates/build-package-for-ios-cocoapods.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,13 @@ jobs:
173173
POD_STAGING_DIR="$(Build.BinariesDirectory)/pod_staging"
174174
ARTIFACTS_STAGING_DIR="$(Build.ArtifactStagingDirectory)"
175175
POD_NAME="onnxruntime-extensions-c"
176-
POD_ARCHIVE_BASENAME="pod-archive-${POD_NAME}-${ORT_EXTENSIONS_POD_VERSION}.zip"
176+
POD_ARCHIVE_BASENAME="onnxruntime_extensions.xcframework.${ORT_EXTENSIONS_POD_VERSION}.zip"
177177
PODSPEC_BASENAME="${POD_NAME}.podspec"
178178
179179
pushd ${POD_STAGING_DIR}
180180
181181
# assemble the files in the artifacts staging directory
182-
zip -r ${ARTIFACTS_STAGING_DIR}/${POD_ARCHIVE_BASENAME} * --exclude ${PODSPEC_BASENAME}
182+
zip -vry ${ARTIFACTS_STAGING_DIR}/${POD_ARCHIVE_BASENAME} * --exclude ${PODSPEC_BASENAME}
183183
cp ${PODSPEC_BASENAME} ${ARTIFACTS_STAGING_DIR}/${PODSPEC_BASENAME}
184184
185185
popd

nuget/DummyNativeNuget.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<file src="targets\net6.0-android\Microsoft.ML.OnnxRuntime.Extensions.Dummy.targets" target="build\net6.0-android31.0" />
5555
<file src="targets\net6.0-android\Microsoft.ML.OnnxRuntime.Extensions.Dummy.targets" target="buildTransitive\net6.0-android31.0" />
5656
<!-- iOS via Xamarin/MAUI. -->
57-
<file src="..\nuget-artifacts\onnxruntime_extensions.xcframework\**" target="runtimes\ios\native\onnxruntime_extensions.xcframework" />
57+
<file src="..\nuget-artifacts\onnxruntime_extensions.xcframework.zip" target="runtimes\ios\native\" />
5858
<file src="targets\xamarinios10\Microsoft.ML.OnnxRuntime.Extensions.Dummy.targets" target="build\xamarinios10" />
5959
<file src="targets\xamarinios10\Microsoft.ML.OnnxRuntime.Extensions.Dummy.targets" target="buildTransitive\xamarinios10" />
6060
<file src="targets\net6.0-ios\Microsoft.ML.OnnxRuntime.Extensions.Dummy.targets" target="build\net6.0-ios15.4" />

nuget/NativeNuget.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<file src="targets\net6.0-android\Microsoft.ML.OnnxRuntime.Extensions.targets" target="build\net6.0-android31.0" />
5252
<file src="targets\net6.0-android\Microsoft.ML.OnnxRuntime.Extensions.targets" target="buildTransitive\net6.0-android31.0" />
5353
<!-- iOS via Xamarin/MAUI. -->
54-
<file src="..\nuget-artifacts\onnxruntime_extensions.xcframework\**" target="runtimes\ios\native\onnxruntime_extensions.xcframework" />
54+
<file src="..\nuget-artifacts\onnxruntime_extensions.xcframework.zip" target="runtimes\ios\native\" />
5555
<file src="targets\xamarinios10\Microsoft.ML.OnnxRuntime.Extensions.targets" target="build\xamarinios10" />
5656
<file src="targets\xamarinios10\Microsoft.ML.OnnxRuntime.Extensions.targets" target="buildTransitive\xamarinios10" />
5757
<file src="targets\net6.0-ios\Microsoft.ML.OnnxRuntime.Extensions.targets" target="build\net6.0-ios15.4" />

nuget/targets/net6.0-ios/Microsoft.ML.OnnxRuntime.Extensions.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ItemGroup Condition="('$(OutputType)'!='Library' OR '$(IsAppExtension)'=='True')">
4-
<NativeReference Include="$(MSBuildThisFileDirectory)..\..\runtimes\ios\native\onnxruntime_extensions.xcframework">
4+
<NativeReference Include="$(MSBuildThisFileDirectory)..\..\runtimes\ios\native\onnxruntime_extensions.xcframework.zip">
55
<Kind>Static</Kind>
66
<IsCxx>True</IsCxx>
77
<SmartLink>True</SmartLink>

tools/android/build_aar.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ def build_for_abi(
3030
str(_repo_dir / "tools" / "build.py"),
3131
f"--build_dir={build_dir}",
3232
f"--config={config}",
33-
"--update",
34-
"--build",
3533
"--parallel",
36-
"--test",
3734
# Android options
3835
"--android",
3936
f"--android_abi={abi}",
@@ -53,7 +50,7 @@ def do_build_by_mode(
5350
api_level: int,
5451
sdk_path: Path,
5552
ndk_path: Path,
56-
build_py_args: list[str]
53+
build_py_args: list[str],
5754
):
5855
output_dir = output_dir.resolve()
5956

@@ -77,12 +74,12 @@ def do_build_by_mode(
7774

7875
jnilib_names = ["libortextensions.so", "libonnxruntime_extensions4j_jni.so"]
7976
for jnilib_name in jnilib_names:
80-
shutil.copyfile(build_dir / config / "java" / "android" / abi / jnilib_name, jnilibs_dir / jnilib_name)
77+
shutil.copyfile(build_dir / config / "lib" / jnilib_name, jnilibs_dir / jnilib_name)
8178

8279
# depending on the build settings these libraries may not be build
8380
optional_jnilib_names = ["libcrypto.so", "libssl.so", "libcurl.so"]
8481
for jnilib_name in optional_jnilib_names:
85-
src = build_dir / config / "java" / "android" / abi / jnilib_name
82+
src = build_dir / config / "lib" / jnilib_name
8683
if src.exists():
8784
shutil.copyfile(src, jnilibs_dir / jnilib_name)
8885

tools/ci_build/extract_nuget_files.ps1

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ New-Item -Path $nuget_sources_dir -ItemType directory
2020

2121
## .zip files
2222
# unzip directly
23-
Get-ChildItem $artifact_download_dir -Filter *.zip |
23+
Get-ChildItem $artifact_download_dir -Include *.zip -Exclude onnxruntime_extensions.xcframework.*.zip |
2424
Foreach-Object {
2525
$cmd = "7z.exe x $($_.FullName) -y -o$nuget_sources_dir"
2626
Write-Output $cmd
@@ -44,6 +44,21 @@ Foreach-Object {
4444
Invoke-Expression -Command $cmd
4545
}
4646

47+
# process iOS xcframework
48+
$xcframeworks = Get-ChildItem $Env:BUILD_BINARIESDIRECTORY\nuget-artifacts -Filter onnxruntime_extensions.xcframework.*.zip
49+
if ($xcframeworks.Count -eq 1) {
50+
$xcframework = $xcframeworks[0]
51+
# remove version info from filename and use required filename format
52+
$target_file = "$nuget_sources_dir\onnxruntime_extensions.xcframework.zip"
53+
New-Item -Path $target_dir -ItemType directory
54+
55+
Write-Output "Copy-Item $($xcframework.FullName) $target_file"
56+
Copy-Item $xcframework.FullName $target_file
57+
}
58+
elseif ($xcframeworks.Count -ne 1) {
59+
Write-Error "Expected at most one onnxruntime_extensions.xcframework.*.zip file but got: [$xcframeworks]"
60+
}
61+
4762
# copy android AAR.
4863

4964
# target file structure:

tools/ios/assemble_pod_package.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
import argparse
99
import json
10-
from pathlib import Path
1110
import re
1211
import shutil
1312
import sys
13+
from pathlib import Path
1414
from typing import Dict
1515

1616
_script_dir = Path(__file__).resolve().parent
@@ -60,7 +60,12 @@ def replace_template_variable(match):
6060

6161

6262
def assemble_pod_package(
63-
staging_dir: Path, xcframework_dir: Path, public_headers_dir: Path, xcframework_info_file: Path, pod_version: str, catalyst_enabled: bool,
63+
staging_dir: Path,
64+
xcframework_dir: Path,
65+
public_headers_dir: Path,
66+
xcframework_info_file: Path,
67+
pod_version: str,
68+
catalyst_enabled: bool,
6469
):
6570
staging_dir = staging_dir.resolve()
6671
xcframework_dir = xcframework_dir.resolve(strict=True)
@@ -74,8 +79,8 @@ def assemble_pod_package(
7479

7580
# copy files to staging dir
7681
shutil.copyfile(_repo_dir / "LICENSE", staging_dir / "LICENSE")
77-
shutil.copytree(xcframework_dir, staging_dir / xcframework_dir.name, dirs_exist_ok=True)
78-
shutil.copytree(public_headers_dir, staging_dir / public_headers_dir.name, dirs_exist_ok=True)
82+
shutil.copytree(xcframework_dir, staging_dir / xcframework_dir.name, dirs_exist_ok=True, symlinks=True)
83+
shutil.copytree(public_headers_dir, staging_dir / public_headers_dir.name, dirs_exist_ok=True, symlinks=True)
7984

8085
# generate podspec
8186
pod_name = "onnxruntime-extensions-c"

tools/ios/build_xcframework.py

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99

1010
import argparse
1111
import json
12-
import os
13-
from pathlib import Path
1412
import shutil
1513
import sys
14+
from pathlib import Path
1615

1716
_repo_dir = Path(__file__).resolve().parents[2]
1817
sys.path.insert(0, str(_repo_dir / "tools"))
@@ -98,7 +97,7 @@ def build_framework_for_platform_and_arch(
9897

9998
cmake_defines = []
10099

101-
if platform != "macosx" and platform != "maccatalyst": #ios simulator or iphoneos platform
100+
if platform != "macosx" and platform != "maccatalyst": # ios simulator or iphoneos platform
102101
cmake_defines += [
103102
# required by OpenCV CMake toolchain file
104103
# https://github.com/opencv/opencv/blob/4223495e6cd67011f86b8ecd9be1fa105018f3b1/platforms/ios/cmake/Toolchains/common-ios-toolchain.cmake#L64-L66
@@ -213,19 +212,61 @@ def platform_arch_framework_build_dir(platform, arch):
213212
platform_fat_framework_dir.mkdir()
214213

215214
# copy over files from arch-specific framework to fat framework
216-
for framework_file_relative_path in [Path("Headers"), Path("Info.plist")]:
217-
src = first_arch_framework_dir / framework_file_relative_path
218-
dst = platform_fat_framework_dir / framework_file_relative_path
219-
if src.is_dir():
220-
shutil.copytree(src, dst)
221-
else:
222-
shutil.copy(src, dst)
223-
224-
# combine arch-specific framework libraries
225-
arch_libs = [str(framework_dir / "onnxruntime_extensions") for framework_dir in arch_framework_dirs]
226-
run(
227-
*([_lipo, "-create", "-output", str(platform_fat_framework_dir / "onnxruntime_extensions")] + arch_libs)
228-
)
215+
# macos requires different framework structure:
216+
# https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/FrameworkAnatomy.html
217+
if platform == "macosx" or platform == "maccatalyst":
218+
# Set up directory strcture
219+
dest_headers_dir = platform_fat_framework_dir / "Versions/A/Headers"
220+
dest_resources_dir = platform_fat_framework_dir / "Versions/A/Resources"
221+
222+
# Copy headers and Info.plist
223+
shutil.copytree(first_arch_framework_dir / Path("Headers"), dest_headers_dir)
224+
Path(dest_resources_dir).mkdir(parents=True, exist_ok=True)
225+
shutil.copy(first_arch_framework_dir / Path("Info.plist"), dest_resources_dir / "Info.plist")
226+
227+
# combine arch-specific framework libraries
228+
arch_libs = [str(framework_dir / "onnxruntime_extensions") for framework_dir in arch_framework_dirs]
229+
run(
230+
*(
231+
[
232+
_lipo,
233+
"-create",
234+
"-output",
235+
str(platform_fat_framework_dir / "Versions/A/onnxruntime_extensions"),
236+
]
237+
+ arch_libs
238+
)
239+
)
240+
241+
# create Symbolic links
242+
Path(platform_fat_framework_dir / "Versions/Current").symlink_to("A", target_is_directory=True)
243+
Path(platform_fat_framework_dir / "Headers").symlink_to(
244+
"Versions/Current/Headers", target_is_directory=True
245+
)
246+
Path(platform_fat_framework_dir / "Resources").symlink_to(
247+
"Versions/Current/Resources", target_is_directory=True
248+
)
249+
Path(platform_fat_framework_dir / "onnxruntime_extensions").symlink_to(
250+
"Versions/Current/onnxruntime_extensions"
251+
)
252+
253+
else:
254+
for framework_file_relative_path in [Path("Headers"), Path("Info.plist")]:
255+
src = first_arch_framework_dir / framework_file_relative_path
256+
dst = platform_fat_framework_dir / framework_file_relative_path
257+
if src.is_dir():
258+
shutil.copytree(src, dst)
259+
else:
260+
shutil.copy(src, dst)
261+
262+
# combine arch-specific framework libraries
263+
arch_libs = [str(framework_dir / "onnxruntime_extensions") for framework_dir in arch_framework_dirs]
264+
run(
265+
*(
266+
[_lipo, "-create", "-output", str(platform_fat_framework_dir / "onnxruntime_extensions")]
267+
+ arch_libs
268+
)
269+
)
229270

230271
platform_fat_framework_dirs.append(platform_fat_framework_dir)
231272

@@ -241,7 +282,7 @@ def platform_arch_framework_build_dir(platform, arch):
241282
# copy public headers
242283
output_headers_dir = output_dir / "Headers"
243284
_rmtree_if_existing(output_headers_dir)
244-
shutil.copytree(headers_dir, output_headers_dir)
285+
shutil.copytree(headers_dir, output_headers_dir, symlinks=True)
245286

246287
# merge framework_info.json per platform into xcframework_info.json in output_dir
247288
_merge_framework_info_files(framework_info_files_to_merge, Path(output_dir, "xcframework_info.json"))

0 commit comments

Comments
 (0)