Skip to content

Commit

Permalink
merge nested framework_info.json
Browse files Browse the repository at this point in the history
  • Loading branch information
rachguo authored and rachguo committed Nov 16, 2023
1 parent b653bd6 commit 2273c98
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tools/ci_build/github/apple/build_and_assemble_ios_pods.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def parse_args():
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.",
)
Expand Down
27 changes: 21 additions & 6 deletions tools/ci_build/github/apple/build_ios_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import shutil
import subprocess
import sys
from collections import defaultdict

SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
REPO_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, "..", "..", "..", ".."))
Expand Down Expand Up @@ -100,6 +101,17 @@ def _build_for_osx_sysroot(

return framework_dir

def _merge_json_lists(files, output_file):
merged_data = defaultdict(dict)

for file in files:
with open(file, 'r') as f:

Check warning

Code scanning / lintrunner

RUFF/UP015 Warning

Unnecessary open mode parameters.
See https://beta.ruff.rs/docs/rules/
data = json.load(f)
for platform, values in data.items():
merged_data[platform].update(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)
Expand All @@ -112,7 +124,7 @@ def _build_package(args):
# build framework for individual sysroot
base_build_command = []
framework_dirs = []
framework_info_path = ""
framework_info_files_to_merge = []
public_headers_path = ""
for sysroot in build_settings["build_osx_archs"]:
base_build_command = [sys.executable, BUILD_PY] + build_settings["build_params"][sysroot] + ["--config=" + build_config]
Expand All @@ -132,17 +144,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_json_lists(framework_info_files_to_merge, os.path.join(build_dir, "framework_info.json"))

# remove existing xcframework if any
xcframework_path = os.path.join(xcframework_dir, "onnxruntime.xcframework")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"--use_xnnpack",
"--skip_tests",
"--cmake_extra_defines=onnxruntime_BUILD_UNIT_TESTS=OFF",
"--apple_deploy_target=10.14"
"--apple_deploy_target=11.0"
],
"iphoneos": [
"--ios",
Expand Down

0 comments on commit 2273c98

Please sign in to comment.