mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-21 19:18:55 +00:00
* Add test for iOS package (#7816) * Add test for iOS package * Add readme * fix pep8 warning * Addressed CR comments, fixed CI failure * Address CR comments * Update readme.md * Update package name and readme, added comments to the podspec * Add podspec template for ios package, update build settings (#7907) * Add podspec template for ios package * minor formatting update * Add spec.source_files for header files * Update spec.public_header_files to spec.source_files * minor update * Add iOS packaging pipeline (#8264) Create a pipeline to produce the iOS package artifacts. * [iOS] Packaging pipeline improvements. (#8324) Updates to the iOS packaging pipeline: - Make it harder to overwrite package archives accidentally when uploading (fails if the archive already exists) - Only upload package archives for release builds - Some clean up * Add metadata_props to ORT model (#8340) * Add metadata_props to ORT model * Minor update * Update python binding, and increase the minimal pipeline size threshold * Fixed a small bug in serializing ir_version * Remove temp ort.py.fbs and add it to .gitignore * Add iOS/macOS static framework (#8357) * Add ability to generate ios static framework * Fix typos * Add pod cache clean, update some comments of previous commit * Fix CI failure with newly added cpuinfo library * Update test model (CoreML requires node has a name) * Addressed CR comments * Fix iOS packaging pipeline failure (#8433) * Fix optimizer crash (#8274) * Update iOS packaging script to default build static framework, disable bitcode (#8533) * default package build to static, disable bitcode * fix pipeline failure * Address CR comments * Add HardSigmoid to mobile packages. Used by PyTorch MobileNet v3 (#8552) * bump the version number to 1.8.2 * Change Windows GPU machine pool to onnxruntime-win-cuda11-0 * [Objective-C API] Fix ORTIsCoreMLExecutionProviderAvailable link error when used from Swift. (#8350) Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com> Co-authored-by: RandySheriffH <48490400+RandySheriffH@users.noreply.github.com> Co-authored-by: Scott McKay <skottmckay@gmail.com> Co-authored-by: Changming Sun <chasun@microsoft.com>
124 lines
5.1 KiB
Python
124 lines
5.1 KiB
Python
#!/usr/bin/env python3
|
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
# Licensed under the MIT License.
|
|
|
|
import argparse
|
|
import os
|
|
import pathlib
|
|
import shutil
|
|
import subprocess
|
|
|
|
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
|
|
REPO_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, "..", "..", "..", ".."))
|
|
|
|
|
|
from package_assembly_utils import ( # noqa: E402
|
|
gen_file_from_template, load_framework_info)
|
|
|
|
|
|
def _test_ios_packages(args):
|
|
# check if CocoaPods is installed
|
|
if shutil.which('pod') is None:
|
|
if args.fail_if_cocoapods_missing:
|
|
raise ValueError('CocoaPods is required for this test')
|
|
else:
|
|
print('CocoaPods is not installed, ignore this test')
|
|
return
|
|
|
|
# Now we need to create a zip file contains the framework and the podspec file, both of these 2 files
|
|
# should be under the c_framework_dir
|
|
c_framework_dir = args.c_framework_dir.resolve()
|
|
if not c_framework_dir.is_dir():
|
|
raise FileNotFoundError('c_framework_dir {} is not a folder.'.format(c_framework_dir))
|
|
|
|
framework_path = os.path.join(c_framework_dir, 'onnxruntime.framework')
|
|
if not pathlib.Path(framework_path).exists():
|
|
raise FileNotFoundError('{} does not have onnxruntime.framework'.format(c_framework_dir))
|
|
|
|
# create a temp folder
|
|
import tempfile
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
# This is for debugging only
|
|
# temp_dir = <a local directory>
|
|
# shutil.rmtree(temp_dir)
|
|
|
|
# create a zip file contains the framework
|
|
# TODO, move this into a util function
|
|
local_pods_dir = os.path.join(temp_dir, 'local_pods')
|
|
os.makedirs(local_pods_dir, exist_ok=True)
|
|
# shutil.make_archive require target file as full path without extension
|
|
zip_base_filename = os.path.join(local_pods_dir, 'onnxruntime-mobile-c')
|
|
zip_file_path = zip_base_filename + '.zip'
|
|
shutil.make_archive(zip_base_filename, 'zip', root_dir=c_framework_dir, base_dir='onnxruntime.framework')
|
|
|
|
# copy the test project to the temp_dir
|
|
test_proj_path = os.path.join(REPO_DIR, 'onnxruntime', 'test', 'platform', 'ios', 'ios_package_test')
|
|
target_proj_path = os.path.join(temp_dir, 'ios_package_test')
|
|
shutil.copytree(test_proj_path, target_proj_path)
|
|
|
|
# generate the podspec file from the template
|
|
framework_info = load_framework_info(args.framework_info_file.resolve())
|
|
|
|
with open(os.path.join(REPO_DIR, 'VERSION_NUMBER')) as version_file:
|
|
ORT_VERSION = version_file.readline().strip()
|
|
|
|
variable_substitutions = {
|
|
"VERSION": ORT_VERSION,
|
|
"IOS_DEPLOYMENT_TARGET": framework_info["IOS_DEPLOYMENT_TARGET"],
|
|
"WEAK_FRAMEWORK": framework_info["WEAK_FRAMEWORK"],
|
|
"LICENSE_FILE": '"LICENSE"',
|
|
}
|
|
|
|
podspec_template = os.path.join(SCRIPT_DIR, "c", "onnxruntime-mobile-c.podspec.template")
|
|
podspec = os.path.join(target_proj_path, "onnxruntime-mobile-c.podspec")
|
|
|
|
gen_file_from_template(podspec_template, podspec, variable_substitutions)
|
|
|
|
# update the podspec to point to the local framework zip file
|
|
with open(podspec, 'r') as file:
|
|
file_data = file.read()
|
|
file_data = file_data.replace('file:///http_source_placeholder', 'file:' + zip_file_path)
|
|
with open(podspec, 'w') as file:
|
|
file.write(file_data)
|
|
|
|
# clean the Cocoapods cache first, in case the same pod was cached in previous runs
|
|
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)
|
|
|
|
# run the tests
|
|
subprocess.run(['xcrun', 'xcodebuild', 'test',
|
|
'-workspace', './ios_package_test.xcworkspace',
|
|
'-scheme', 'ios_package_test',
|
|
'-destination', 'platform=iOS Simulator,OS=latest,name=iPhone SE (2nd generation)'],
|
|
shell=False, check=True, cwd=target_proj_path)
|
|
|
|
|
|
def parse_args():
|
|
parser = argparse.ArgumentParser(
|
|
os.path.basename(__file__),
|
|
description='Test iOS framework using CocoaPods package.'
|
|
)
|
|
|
|
parser.add_argument('--fail_if_cocoapods_missing', action='store_true',
|
|
help='This script will fail if CocoaPods is not installed, '
|
|
'will not throw error unless fail_if_cocoapod_missing is set.')
|
|
|
|
parser.add_argument("--framework_info_file", type=pathlib.Path, required=True,
|
|
help="Path to the framework_info.json file containing additional values for the podspec. "
|
|
"This file should be generated by CMake in the build directory.")
|
|
|
|
parser.add_argument('--c_framework_dir', type=pathlib.Path, required=True,
|
|
help='Provide the parent directory for C/C++ framework')
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
def main():
|
|
args = parse_args()
|
|
_test_ios_packages(args)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|