Skip to content

Commit ef30c58

Browse files
skottmckayrohan11235813
authored andcommitted
Updates to apple packaging (#21611)
### Description <!-- Describe your changes. --> Add ability to test packaging without rebuilding every time. Add ability to comment out some platforms/architectures without the scripts to assemble the c/obj-c packages breaking. Update a couple of commands to preserve symlinks. ### 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. --> Make debugging packaging issues faster. Creates correct package for mac-catalyst and doesn't require setting symlinks via bash script.
1 parent 8e8dd7a commit ef30c58

File tree

8 files changed

+65
-36
lines changed

8 files changed

+65
-36
lines changed

tools/ci_build/github/apple/assemble_apple_packaging_artifacts.sh

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,6 @@ ORT_POD_VERSION=${4:?${USAGE_TEXT}}
2323
POD_ARCHIVE_BASENAME="pod-archive-${POD_NAME}-${ORT_POD_VERSION}.zip"
2424
PODSPEC_BASENAME="${POD_NAME}.podspec"
2525

26-
27-
# Macos requires a different structure for the framework
28-
# This will create the necessary symlinks for the macos framework before packaging
29-
# Adding the symlinks here rather than in the build script ensures that symlinks are not lost
30-
for MACOS_DIR in "${BINARIES_STAGING_DIR}/${POD_NAME}/onnxruntime.xcframework/macos"*; do
31-
if [ -d "${MACOS_DIR}" ]; then
32-
echo "Creating symlinks for ${MACOS_DIR}"
33-
pushd "${MACOS_DIR}/onnxruntime.framework"
34-
35-
rm -rf Headers Resources onnxruntime
36-
rm -rf Versions/Current
37-
38-
ln -sfn A Versions/Current
39-
ln -sfn Versions/Current/Headers Headers
40-
ln -sfn Versions/Current/Resources Resources
41-
ln -sfn Versions/Current/onnxruntime onnxruntime
42-
43-
popd
44-
45-
fi
46-
done
47-
48-
4926
echo "Contents of ${BINARIES_STAGING_DIR}/${POD_NAME}:"
5027
ls -lR "${BINARIES_STAGING_DIR}/${POD_NAME}"
5128

tools/ci_build/github/apple/build_and_assemble_apple_pods.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ def parse_args():
5757
)
5858

5959
parser.add_argument("--test", action="store_true", help="Run tests on the framework and pod package files.")
60+
parser.add_argument(
61+
"--skip-build",
62+
action="store_true",
63+
help="Use build from previous run. Useful to debug test issues or packaging changes.",
64+
)
6065

6166
build_framework_group = parser.add_argument_group(
6267
title="iOS framework build arguments",
@@ -114,7 +119,8 @@ def main():
114119

115120
build_apple_framework_args += ["--build_dir", str(build_dir), args.build_settings_file]
116121

117-
run(build_apple_framework_args)
122+
if not args.skip_build:
123+
run(build_apple_framework_args)
118124

119125
if args.test:
120126
test_apple_packages_args = [
@@ -171,7 +177,8 @@ def main():
171177
def move_dir(src, dst):
172178
if dst.is_dir():
173179
shutil.rmtree(dst)
174-
shutil.move(src, dst)
180+
shutil.copytree(src, dst, symlinks=True)
181+
shutil.rmtree(src)
175182

176183
move_dir(c_pod_staging_dir, staging_dir / c_pod_name)
177184
move_dir(objc_pod_staging_dir, staging_dir / objc_pod_name)

tools/ci_build/github/apple/build_apple_framework.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def _build_package(args):
200200
xcframework_dir = os.path.join(build_dir, "framework_out")
201201
pathlib.Path(xcframework_dir).mkdir(parents=True, exist_ok=True)
202202
shutil.copy(os.path.join(REPO_DIR, "LICENSE"), xcframework_dir)
203-
shutil.copytree(public_headers_path, os.path.join(xcframework_dir, "Headers"), dirs_exist_ok=True)
203+
shutil.copytree(public_headers_path, os.path.join(xcframework_dir, "Headers"), dirs_exist_ok=True, symlinks=True)
204204
_merge_framework_info_files(framework_info_files_to_merge, os.path.join(build_dir, "xcframework_info.json"))
205205

206206
# remove existing xcframework if any

tools/ci_build/github/apple/c/assemble_c_pod_package.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
PackageVariant,
1717
copy_repo_relative_to_dir,
1818
gen_file_from_template,
19+
get_podspec_values,
1920
load_json_config,
2021
)
2122

@@ -66,23 +67,25 @@ def assemble_c_pod_package(
6667
print("Warning: staging directory already exists", file=sys.stderr)
6768

6869
# copy the necessary files to the staging directory
69-
shutil.copytree(framework_dir, staging_dir / framework_dir.name, dirs_exist_ok=True)
70-
shutil.copytree(public_headers_dir, staging_dir / public_headers_dir.name, dirs_exist_ok=True)
70+
shutil.copytree(framework_dir, staging_dir / framework_dir.name, dirs_exist_ok=True, symlinks=True)
71+
shutil.copytree(public_headers_dir, staging_dir / public_headers_dir.name, dirs_exist_ok=True, symlinks=True)
7172
copy_repo_relative_to_dir(["LICENSE"], staging_dir)
7273

74+
(ios_deployment_target, macos_deployment_target, weak_framework) = get_podspec_values(framework_info)
75+
7376
# generate the podspec file from the template
7477
variable_substitutions = {
7578
"DESCRIPTION": pod_config["description"],
7679
# By default, we build both "iphoneos" and "iphonesimulator" architectures, and the deployment target should be the same between these two.
77-
"IOS_DEPLOYMENT_TARGET": framework_info["iphonesimulator"]["APPLE_DEPLOYMENT_TARGET"],
78-
"MACOSX_DEPLOYMENT_TARGET": framework_info.get("macosx", {}).get("APPLE_DEPLOYMENT_TARGET", ""),
80+
"IOS_DEPLOYMENT_TARGET": ios_deployment_target,
81+
"MACOSX_DEPLOYMENT_TARGET": macos_deployment_target,
7982
"LICENSE_FILE": "LICENSE",
8083
"NAME": pod_name,
8184
"ORT_C_FRAMEWORK": framework_dir.name,
8285
"ORT_C_HEADERS_DIR": public_headers_dir.name,
8386
"SUMMARY": pod_config["summary"],
8487
"VERSION": pod_version,
85-
"WEAK_FRAMEWORK": framework_info["iphonesimulator"]["WEAK_FRAMEWORK"],
88+
"WEAK_FRAMEWORK": weak_framework,
8689
}
8790

8891
podspec_template = _script_dir / "c.podspec.template"

tools/ci_build/github/apple/objectivec/assemble_objc_pod_package.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
copy_repo_relative_to_dir,
1818
filter_files,
1919
gen_file_from_template,
20+
get_podspec_values,
2021
load_json_config,
2122
)
2223

@@ -147,12 +148,14 @@ def assemble_objc_pod_package(
147148
def path_patterns_as_variable_value(patterns: list[str]):
148149
return ", ".join([f'"{pattern}"' for pattern in patterns])
149150

151+
(ios_deployment_target, macos_deployment_target, _) = get_podspec_values(framework_info)
152+
150153
variable_substitutions = {
151154
"C_POD_NAME": c_pod_config["name"],
152155
"DESCRIPTION": pod_config["description"],
153156
"INCLUDE_DIR_LIST": path_patterns_as_variable_value(include_dirs),
154-
"IOS_DEPLOYMENT_TARGET": framework_info["iphonesimulator"]["APPLE_DEPLOYMENT_TARGET"],
155-
"MACOSX_DEPLOYMENT_TARGET": framework_info.get("macosx", {}).get("APPLE_DEPLOYMENT_TARGET", ""),
157+
"IOS_DEPLOYMENT_TARGET": ios_deployment_target,
158+
"MACOSX_DEPLOYMENT_TARGET": macos_deployment_target,
156159
"LICENSE_FILE": license_file,
157160
"NAME": pod_name,
158161
"PUBLIC_HEADER_FILE_LIST": path_patterns_as_variable_value(pod_files["public_header_files"]),

tools/ci_build/github/apple/package_assembly_utils.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,44 @@ def load_json_config(json_config_file: pathlib.Path):
118118
return json.load(config)
119119

120120

121+
def get_podspec_values(framework_info):
122+
"""
123+
Get the podspec deployement targets and weak framework info from the dictionary that load_json_config returned.
124+
Looks for iphonesimulator, iphoneos and macos settings.
125+
Handles missing platforms and checks consistency.
126+
Returns empty string for deployment target if that platofrm is not enabled.
127+
128+
:return (ios_deployment_target, macos_deployment_target, weak_framework)
129+
"""
130+
ios_deployment_target = ""
131+
macos_deployment_target = ""
132+
weak_framework = "" # should be the same for all platforms
133+
# get info, allowing for a subset of platforms to be specified
134+
for framework in ("iphonesimulator", "iphoneos", "macosx"):
135+
if framework not in framework_info:
136+
continue
137+
138+
target = framework_info[framework]["APPLE_DEPLOYMENT_TARGET"]
139+
weak = framework_info[framework]["WEAK_FRAMEWORK"]
140+
141+
if not weak_framework:
142+
weak_framework = weak
143+
else:
144+
# should be consistent
145+
assert weak == weak_framework
146+
147+
if framework == "macosx":
148+
macos_deployment_target = target
149+
else:
150+
if not ios_deployment_target:
151+
ios_deployment_target = target
152+
else:
153+
# should be consistent
154+
assert ios_deployment_target == target
155+
156+
return (ios_deployment_target, macos_deployment_target, weak_framework)
157+
158+
121159
def get_ort_version():
122160
"""
123161
Gets the ONNX Runtime version string from the repo.

tools/ci_build/github/apple/test_apple_packages.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ def _test_apple_packages(args):
8989

9090
# create a zip file contains the framework
9191
zip_file_path = local_pods_dir / f"{pod_name}.zip"
92-
# shutil.make_archive require target file as full path without extension
93-
shutil.make_archive(zip_file_path.with_suffix(""), "zip", root_dir=local_pods_dir)
92+
93+
# shutil.make_archive doesn't preserve symlinks. we know this is running on macOS so use zip
94+
subprocess.run(["zip", "-r", "-y", str(zip_file_path), "."], cwd=local_pods_dir, check=True)
9495

9596
# update the podspec to point to the local framework zip file
9697
with open(podspec) as file:

tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ stages:
111111
cp -R $(Build.BinariesDirectory)/ios_framework/framework_out/onnxruntime.xcframework \
112112
$(Build.BinariesDirectory)/artifacts_staging/onnxruntime-ios-xcframework-$(OnnxRuntimeVersion)
113113
pushd $(Build.BinariesDirectory)/artifacts_staging
114-
zip -vr $(Build.BinariesDirectory)/artifacts/onnxruntime_xcframework.zip \
114+
zip -vry $(Build.BinariesDirectory)/artifacts/onnxruntime_xcframework.zip \
115115
onnxruntime-ios-xcframework-$(OnnxRuntimeVersion)
116116
popd
117117
displayName: "Build Apple xcframework"

0 commit comments

Comments
 (0)