@@ -400,6 +400,12 @@ def convert_arg_line_to_args(self, arg_line):
400
400
401
401
parser .add_argument ("--ios" , action = "store_true" , help = "build for ios" )
402
402
403
+ parser .add_argument (
404
+ "--macos" ,
405
+ choices = ["MacOSX" , "Catalyst" ],
406
+ help = "Specify the target platform for macOS build. Only specify this argument when --build_apple_framework is present." ,
407
+ )
408
+
403
409
parser .add_argument (
404
410
"--apple_sysroot" , default = "" , help = "Specify the location name of the macOS platform SDK to be used"
405
411
)
@@ -419,7 +425,7 @@ def convert_arg_line_to_args(self, arg_line):
419
425
action = "store_const" ,
420
426
const = "Xcode" ,
421
427
dest = "cmake_generator" ,
422
- help = "Use Xcode as cmake generator, this is only supported on MacOS. Equivalent to '--cmake_generator Xcode'." ,
428
+ help = "Use Xcode as cmake generator, this is only supported on MacOS. (non Catalyst build). Equivalent to '--cmake_generator Xcode'." ,
423
429
)
424
430
parser .add_argument (
425
431
"--osx_arch" ,
@@ -1323,8 +1329,12 @@ def generate_build_tree(
1323
1329
if args .use_snpe :
1324
1330
cmake_args += ["-Donnxruntime_USE_SNPE=ON" ]
1325
1331
1326
- if args .build_apple_framework or args .ios :
1327
- if not args .cmake_generator == "Xcode" :
1332
+ if args .macos or args .ios :
1333
+ # Note: Xcode CMake generator doesn't have a good support for Mac Catalyst yet.
1334
+ if args .macos == "Catalyst" and args .cmake_generator == "Xcode" :
1335
+ raise BuildError ("Xcode CMake generator ('--cmake_generator Xcode') doesn't support Mac Catalyst build." )
1336
+
1337
+ if (args .ios or args .macos == "MacOSX" ) and not args .cmake_generator == "Xcode" :
1328
1338
raise BuildError (
1329
1339
"iOS/MacOS framework build requires use of the Xcode CMake generator ('--cmake_generator Xcode')."
1330
1340
)
@@ -1342,19 +1352,37 @@ def generate_build_tree(
1342
1352
"iOS/MacOS framework build on MacOS canceled due to missing arguments: "
1343
1353
+ ", " .join (val for val , cond in zip (arg_names , needed_args ) if not cond )
1344
1354
)
1355
+ # note: this value is mainly used in framework_info.json file to specify the build osx type
1356
+ platform_name = "macabi" if args .macos == "Catalyst" else args .apple_sysroot
1345
1357
cmake_args += [
1346
1358
"-Donnxruntime_BUILD_SHARED_LIB=ON" ,
1347
1359
"-DCMAKE_OSX_SYSROOT=" + args .apple_sysroot ,
1348
1360
"-DCMAKE_OSX_DEPLOYMENT_TARGET=" + args .apple_deploy_target ,
1349
1361
# we do not need protoc binary for ios cross build
1350
1362
"-Dprotobuf_BUILD_PROTOC_BINARIES=OFF" ,
1363
+ "-DPLATFORM_NAME=" + platform_name ,
1351
1364
]
1352
1365
if args .ios :
1353
1366
cmake_args += [
1354
1367
"-DCMAKE_SYSTEM_NAME=iOS" ,
1355
1368
"-DCMAKE_TOOLCHAIN_FILE="
1356
1369
+ (args .ios_toolchain_file if args .ios_toolchain_file else "../cmake/onnxruntime_ios.toolchain.cmake" ),
1357
1370
]
1371
+ # for catalyst build, we need to manually specify cflags for target e.g. x86_64-apple-ios14.0-macabi, etc.
1372
+ # https://forums.developer.apple.com/forums/thread/122571
1373
+ if args .macos == "Catalyst" :
1374
+ macabi_target = f"{ args .osx_arch } -apple-ios{ args .apple_deploy_target } -macabi"
1375
+ cmake_args += [
1376
+ "-DCMAKE_CXX_COMPILER_TARGET=" + macabi_target ,
1377
+ "-DCMAKE_C_COMPILER_TARGET=" + macabi_target ,
1378
+ "-DCMAKE_CC_COMPILER_TARGET=" + macabi_target ,
1379
+ f"-DCMAKE_CXX_FLAGS=--target={ macabi_target } " ,
1380
+ f"-DCMAKE_CXX_FLAGS_RELEASE=-O3 -DNDEBUG --target={ macabi_target } " ,
1381
+ f"-DCMAKE_C_FLAGS=--target={ macabi_target } " ,
1382
+ f"-DCMAKE_C_FLAGS_RELEASE=-O3 -DNDEBUG --target={ macabi_target } " ,
1383
+ f"-DCMAKE_CC_FLAGS=--target={ macabi_target } " ,
1384
+ f"-DCMAKE_CC_FLAGS_RELEASE=-O3 -DNDEBUG --target={ macabi_target } " ,
1385
+ ]
1358
1386
1359
1387
if args .build_wasm :
1360
1388
emsdk_dir = os .path .join (cmake_dir , "external" , "emsdk" )
@@ -2740,7 +2768,13 @@ def main():
2740
2768
cmake_extra_args += ["-G" , args .cmake_generator ]
2741
2769
2742
2770
if is_macOS ():
2743
- if not args .ios and not args .android and args .osx_arch == "arm64" and platform .machine () == "x86_64" :
2771
+ if (
2772
+ not args .ios
2773
+ and args .macos != "Catalyst"
2774
+ and not args .android
2775
+ and args .osx_arch == "arm64"
2776
+ and platform .machine () == "x86_64"
2777
+ ):
2744
2778
if args .test :
2745
2779
log .warning ("Cannot test ARM64 build on X86_64. Will skip test running after build." )
2746
2780
args .test = False
0 commit comments