Skip to content

Commit

Permalink
add changes for build.py script to add optional --macosx behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
rachguo authored and rachguo committed Nov 8, 2023
1 parent 2c69e12 commit 700a40d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
25 changes: 15 additions & 10 deletions tools/ci_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,13 @@ def convert_arg_line_to_args(self, arg_line):
)
parser.add_argument("--gdk_platform", default="Scarlett", help="Sets the GDK target platform.")

# Note: This arg is for specifying if the build includes macosx arch.
# Different from helper function is_macOS() that's for verifying system platform info that we are building on.
parser.add_argument("--macosx", action="store_true", help="build for macosx")
parser.add_argument("--ios", action="store_true", help="build for ios")

parser.add_argument(
"--ios_sysroot", default="", help="Specify the location name of the macOS platform SDK to be used"
"--osx_sysroot", default="", help="Specify the location name of the macOS platform SDK to be used"
)
parser.add_argument(
"--ios_toolchain_file",
Expand Down Expand Up @@ -1258,27 +1262,28 @@ def generate_build_tree(
if args.use_snpe:
cmake_args += ["-Donnxruntime_USE_SNPE=ON"]

if args.ios:
if args.macosx or args.ios:
if not args.cmake_generator == "Xcode":
raise BuildError("iOS build requires use of the Xcode CMake generator ('--cmake_generator Xcode').")
raise BuildError("MacOS/iOS build requires use of the Xcode CMake generator ('--cmake_generator Xcode').")

needed_args = [
args.ios_sysroot,
args.osx_sysroot,
args.apple_deploy_target,
]
arg_names = [
"--ios_sysroot " + "<the location or name of the macOS platform SDK>",
"--osx_sysroot " + "<the location or name of the macOS platform SDK>",
"--apple_deploy_target " + "<the minimum version of the target platform>",
]
if not all(needed_args):
raise BuildError(
"iOS build on MacOS canceled due to missing arguments: "
"iOS/MacOS framework build on MacOS canceled due to missing arguments: "
+ ", ".join(val for val, cond in zip(arg_names, needed_args) if not cond)
)
cmake_system_name = "Darwin" if args.osx_sysroot == "macosx" else "iOS"
cmake_args += [
"-DCMAKE_SYSTEM_NAME=iOS",
"-DCMAKE_SYSTEM_NAME=" + cmake_system_name,
"-Donnxruntime_BUILD_SHARED_LIB=ON",
"-DCMAKE_OSX_SYSROOT=" + args.ios_sysroot,
"-DCMAKE_OSX_SYSROOT=" + args.osx_sysroot,
"-DCMAKE_OSX_DEPLOYMENT_TARGET=" + args.apple_deploy_target,
# we do not need protoc binary for ios cross build
"-Dprotobuf_BUILD_PROTOC_BINARIES=OFF",
Expand Down Expand Up @@ -1750,8 +1755,8 @@ def run_ios_tests(args, source_dir, config, cwd):
if args.build_apple_framework:
package_test_py = os.path.join(source_dir, "tools", "ci_build", "github", "apple", "test_ios_packages.py")
framework_info_file = os.path.join(cwd, "framework_info.json")
dynamic_framework_dir = os.path.join(cwd, config + "-" + args.ios_sysroot)
static_framework_dir = os.path.join(cwd, config + "-" + args.ios_sysroot, "static_framework")
dynamic_framework_dir = os.path.join(cwd, config + "-" + args.osx_sysroot)
static_framework_dir = os.path.join(cwd, config + "-" + args.osx_sysroot, "static_framework")
# test dynamic framework
run_subprocess(
[
Expand Down
6 changes: 3 additions & 3 deletions tools/ci_build/github/apple/build_ios_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _parse_build_settings(args):

# Build fat framework for all archs of a single sysroot
# For example, arm64 and x86_64 for iphonesimulator
def _build_for_ios_sysroot(
def _build_for_osx_sysroot(
build_config, intermediates_dir, base_build_command, sysroot, archs, build_dynamic_framework
):
# paths of the onnxruntime libraries for different archs
Expand All @@ -52,7 +52,7 @@ def _build_for_ios_sysroot(
build_dir_current_arch = os.path.join(intermediates_dir, sysroot + "_" + current_arch)
build_command = [
*base_build_command,
"--ios_sysroot=" + sysroot,
"--osx_sysroot=" + sysroot,
"--osx_arch=" + current_arch,
"--build_dir=" + build_dir_current_arch,
]
Expand Down Expand Up @@ -133,7 +133,7 @@ def _build_package(args):
if args.path_to_protoc_exe is not None:
base_build_command += ["--path_to_protoc_exe=" + str(args.path_to_protoc_exe.resolve())]

framework_dir = _build_for_ios_sysroot(
framework_dir = _build_for_osx_sysroot(
build_config,
intermediates_dir,
base_build_command,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
{
"build_osx_archs": {
"iphoneos": [
"arm64"
],
"iphonesimulator": [
"arm64",
"x86_64"
],
"macosx": [
"x86_64"
]
},
"build_params": {
"macosx": [
"--macosx",
"--parallel",
"--use_xcode",
"--build_apple_framework",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
--use_coreml \
--use_xnnpack \
--ios \
--ios_sysroot iphonesimulator \
--osx_sysroot iphonesimulator \
--osx_arch x86_64 \
--apple_deploy_target 12.0 \
--use_xcode \
Expand Down

0 comments on commit 700a40d

Please sign in to comment.