4
4
5
5
import argparse
6
6
import contextlib
7
- import glob
8
7
import os
9
8
import re
10
9
import shlex
@@ -279,15 +278,15 @@ def parse_arguments():
279
278
"CMake setup. Delete CMakeCache.txt if needed" )
280
279
parser .add_argument (
281
280
"--arm" , action = 'store_true' ,
282
- help = "[cross-compiling] Create ARM makefiles. Requires --update and no existing cache "
281
+ help = "[cross-compiling] Create Windows ARM makefiles. Requires --update and no existing cache "
283
282
"CMake setup. Delete CMakeCache.txt if needed" )
284
283
parser .add_argument (
285
284
"--arm64" , action = 'store_true' ,
286
- help = "[cross-compiling] Create ARM64 makefiles. Requires --update and no existing cache "
285
+ help = "[cross-compiling] Create Windows ARM64 makefiles. Requires --update and no existing cache "
287
286
"CMake setup. Delete CMakeCache.txt if needed" )
288
287
parser .add_argument (
289
288
"--arm64ec" , action = 'store_true' ,
290
- help = "[cross-compiling] Create ARM64EC makefiles. Requires --update and no existing cache "
289
+ help = "[cross-compiling] Create Windows ARM64EC makefiles. Requires --update and no existing cache "
291
290
"CMake setup. Delete CMakeCache.txt if needed" )
292
291
parser .add_argument (
293
292
"--msvc_toolset" , help = "MSVC toolset to use. e.g. 14.11" )
@@ -311,7 +310,7 @@ def parse_arguments():
311
310
parser .add_argument ("--ios" , action = 'store_true' , help = "build for ios" )
312
311
parser .add_argument (
313
312
"--ios_sysroot" , default = "" ,
314
- help = "Specify the location name of the macOS platform SDK to be used" )
313
+ help = "Specify the location name of the macOS platform SDK to be used" )
315
314
parser .add_argument (
316
315
"--xcode_code_signing_team_id" , default = "" ,
317
316
help = "The development team ID used for code signing in Xcode" )
@@ -321,11 +320,6 @@ def parse_arguments():
321
320
parser .add_argument (
322
321
"--use_xcode" , action = 'store_true' ,
323
322
help = "Use Xcode as cmake generator, this is only supported on MacOS." )
324
- parser .add_argument (
325
- "--osx_arch" ,
326
- default = "arm64" if platform .machine () == "arm64" else "x86_64" ,
327
- choices = ["arm64" , "arm64e" , "x86_64" ],
328
- help = "Specify the Target specific architectures for macOS and iOS, This is only supported on MacOS" )
329
323
330
324
# WebAssembly build
331
325
parser .add_argument ("--build_wasm" , action = 'store_true' , help = "Build for WebAssembly" )
@@ -775,8 +769,34 @@ def generate_build_tree(cmake_path, source_dir, build_dir, cuda_home, cudnn_home
775
769
# It should be default ON in CI build pipelines, and OFF in packaging pipelines.
776
770
# And OFF for the people who are not actively developing onnx runtime.
777
771
add_cmake_define_without_override (cmake_extra_defines , "onnxruntime_DEV_MODE" , use_dev_mode (args ))
778
-
779
- if args .arm64 or args .arm64ec or args .arm :
772
+ if is_macOS :
773
+ ARCHFLAGS = os .environ .get ('ARCHFLAGS' , None )
774
+ OSX_ARCHS = []
775
+ if ARCHFLAGS :
776
+ ARCHFLAGS = shlex .split (ARCHFLAGS )
777
+ for i in range (0 , len (ARCHFLAGS )- 1 ):
778
+ if ARCHFLAGS [i ] == '-arch' :
779
+ OSX_ARCHS .append (ARCHFLAGS [i + 1 ])
780
+
781
+ if len (OSX_ARCHS ) == 1 and OSX_ARCHS [0 ] == platform .machine ():
782
+ # We have use the default value
783
+ OSX_ARCHS = None
784
+
785
+ is_cmake_osx_architectures_set = False
786
+ if OSX_ARCHS :
787
+ is_cmake_osx_architectures_set = True
788
+ add_cmake_define_without_override (cmake_extra_defines , "CMAKE_OSX_ARCHITECTURES" , ";" .join (OSX_ARCHS ))
789
+ else :
790
+ for x in cmake_extra_defines :
791
+ if x .startswith ("CMAKE_OSX_ARCHITECTURES=" ):
792
+ is_cmake_osx_architectures_set = True
793
+ break
794
+
795
+ if is_cmake_osx_architectures_set :
796
+ print ("CMAKE_OSX_ARCHITECTURES is set" )
797
+ else :
798
+ print ("CMAKE_OSX_ARCHITECTURES is not set" )
799
+ elif args .arm64 or args .arm64ec or args .arm :
780
800
# In most cases, we don't need to manually set this variable.
781
801
# Please refer https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html
782
802
add_cmake_define_without_override (cmake_extra_defines , "CMAKE_CROSSCOMPILING" , "ON" )
@@ -900,30 +920,30 @@ def generate_build_tree(cmake_path, source_dir, build_dir, cuda_home, cudnn_home
900
920
cmake_args += ["-Donnxruntime_USE_COREML=ON" ]
901
921
902
922
if args .ios :
903
- needed_args = [
904
- args .use_xcode ,
905
- args .ios_sysroot ,
906
- ]
907
- arg_names = [
908
- "--use_xcode " +
909
- "<need use xcode to cross build iOS on MacOS>" ,
910
- "--ios_sysroot " +
911
- "<the location or name of the macOS platform SDK>" ,
912
- ]
913
- if not all (needed_args ):
914
- raise BuildError (
915
- "iOS build on MacOS canceled due to missing arguments: " +
916
- ', ' .join (
917
- val for val , cond in zip (arg_names , needed_args )
918
- if not cond ))
919
- cmake_args += [
920
- "-DCMAKE_SYSTEM_NAME=iOS" ,
921
- "-Donnxruntime_BUILD_SHARED_LIB=ON" ,
922
- "-DCMAKE_OSX_SYSROOT=" + args .ios_sysroot ,
923
- # we do not need protoc binary for ios cross build
924
- "-Dprotobuf_BUILD_PROTOC_BINARIES=OFF" ,
925
- "-DCMAKE_TOOLCHAIN_FILE=../cmake/onnxruntime_ios.toolchain.cmake"
926
- ]
923
+ needed_args = [
924
+ args .use_xcode ,
925
+ args .ios_sysroot ,
926
+ ]
927
+ arg_names = [
928
+ "--use_xcode " +
929
+ "<need use xcode to cross build iOS on MacOS>" ,
930
+ "--ios_sysroot " +
931
+ "<the location or name of the macOS platform SDK>" ,
932
+ ]
933
+ if not all (needed_args ):
934
+ raise BuildError (
935
+ "iOS build on MacOS canceled due to missing arguments: " +
936
+ ', ' .join (
937
+ val for val , cond in zip (arg_names , needed_args )
938
+ if not cond ))
939
+ cmake_args += [
940
+ "-DCMAKE_SYSTEM_NAME=iOS" ,
941
+ "-Donnxruntime_BUILD_SHARED_LIB=ON" ,
942
+ "-DCMAKE_OSX_SYSROOT=" + args .ios_sysroot ,
943
+ # we do not need protoc binary for ios cross build
944
+ "-Dprotobuf_BUILD_PROTOC_BINARIES=OFF" ,
945
+ "-DCMAKE_TOOLCHAIN_FILE=../cmake/onnxruntime_ios.toolchain.cmake"
946
+ ]
927
947
928
948
if args .build_wasm :
929
949
emsdk_dir = os .path .join (cmake_dir , "external" , "emsdk" )
@@ -1725,7 +1745,6 @@ def run_csharp_tests(source_dir, build_dir, use_cuda, use_openvino, use_tensorrt
1725
1745
run_subprocess (cmd_args , cwd = csharp_source_dir )
1726
1746
1727
1747
1728
-
1729
1748
def build_protoc_for_host (cmake_path , source_dir , build_dir , args ):
1730
1749
if (args .arm or args .arm64 or args .arm64ec or args .enable_windows_store ) and \
1731
1750
not (is_windows ()):
@@ -2004,12 +2023,6 @@ def main():
2004
2023
elif is_macOS ():
2005
2024
if args .use_xcode :
2006
2025
cmake_extra_args += ['-G' , 'Xcode' ]
2007
- if not args .ios and not args .android and \
2008
- args .osx_arch == 'arm64' and platform .machine () == 'x86_64' :
2009
- if args .test :
2010
- log .warning (
2011
- "Cannot test ARM64 build on X86_64. Will skip test running after build." )
2012
- args .test = False
2013
2026
2014
2027
if args .build_wasm :
2015
2028
emsdk_version = args .emsdk_version
@@ -2043,19 +2056,12 @@ def main():
2043
2056
os .path .join (SCRIPT_DIR , "wasm" , "file_packager.py.patch" ),
2044
2057
os .path .join (emsdk_dir , "upstream" , "emscripten" , "tools" , "file_packager.py" ))
2045
2058
2046
- if (args .android or args .ios or args .enable_windows_store or args .build_wasm ) and args .path_to_protoc_exe is None :
2059
+ path_to_protoc_exe = args .path_to_protoc_exe
2060
+ if (args .android or args .ios or args .enable_windows_store or args .build_wasm ) and path_to_protoc_exe is None :
2047
2061
# Cross-compiling for Android, iOS, and WebAssembly
2048
2062
path_to_protoc_exe = build_protoc_for_host (
2049
2063
cmake_path , source_dir , build_dir , args )
2050
2064
2051
- if is_ubuntu_1604 ():
2052
- if (args .arm or args .arm64 ):
2053
- raise BuildError (
2054
- "Only Windows ARM(64) cross-compiled builds supported "
2055
- "currently through this script" )
2056
- if not is_docker () and not args .use_acl and not args .use_armnn :
2057
- install_python_deps ()
2058
-
2059
2065
if args .enable_pybind and is_windows ():
2060
2066
install_python_deps (args .numpy_version )
2061
2067
0 commit comments