Fix ARM cross compilation (related to #3378, #3298) (#3385)

This commit is contained in:
Tiago Koji Castro Shibata 2020-03-31 17:10:48 -07:00 committed by GitHub
parent 55fd283d20
commit a61400de01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -378,22 +378,22 @@ def generate_build_tree(cmake_path, source_dir, build_dir, cuda_home, cudnn_home
cmake_args += ["-DCMAKE_TOOLCHAIN_FILE=" + args.android_ndk_path + "/build/cmake/android.toolchain.cmake",
"-DANDROID_PLATFORM=android-" + str(args.android_api),
"-DANDROID_ABI=" + str(args.android_abi)]
if args.ios:
needed_args = [len(args.ios_sysroot) == 0, not args.arm64 and not args.arm, len(args.ios_toolchain_dir) == 0]
needed_args = [args.ios_sysroot, args.arm64 or args.arm, args.ios_toolchain_dir]
arg_names = ["--ios_sysroot <path to sysroot>", "--arm or --arm64", "--ios_toolchain_dir <path to toolchain>"]
if any(needed_args):
raise BuildError("iOS build canceled due to missing arguments: " + (val + "," for val, cond in zip(arg_names, needed_args) if cond))
if not all(needed_args):
raise BuildError("iOS build canceled due to missing arguments: " + ', '.join(val for val, cond in zip(arg_names, needed_args) if not cond))
compilers = sorted(glob.glob(args.ios_toolchain_dir + "/bin/*-clang*"))
os.environ["PATH"] = args.ios_toolchain_dir + "/bin:" + os.environ.get("PATH", "")
os.environ["LD_LIBRARY_PATH"] = args.ios_toolchain_dir + "/lib:" + os.environ.get("LD_LIBRARY_PATH", "")
os.environ["PATH"] = os.path.join(args.ios_toolchain_dir, "bin") + os.pathsep + os.environ.get("PATH", "")
os.environ["LD_LIBRARY_PATH"] = os.path.join(args.ios_toolchain_dir, "/lib") + os.pathsep + os.environ.get("LD_LIBRARY_PATH", "")
if len(compilers) != 2:
raise BuildError("error identifying compilers in ios_toolchain_dir")
cmake_args += ["-DCMAKE_OSX_ARCHITECTURES=" + ("arm64" if args.arm64 else "arm"),
"-DCMAKE_SYSTEM_NAME=iOSCross",
"-Donnxruntime_BUILD_UNIT_TESTS=OFF",
"-DCMAKE_OSX_SYSROOT=" + args.ios_sysroot,
"-DCMAKE_C_COMPILER=" + compilers[0],
"-DCMAKE_OSX_SYSROOT=" + args.ios_sysroot,
"-DCMAKE_C_COMPILER=" + compilers[0],
"-DCMAKE_CXX_COMPILER=" + compilers[1]]
if path_to_protoc_exe:
@ -955,14 +955,15 @@ def main():
log.info("Build started")
if (args.update):
cmake_extra_args = []
path_to_protoc_exe = None
path_to_protoc_exe = args.path_to_protoc_exe
if(is_windows()):
if (args.x86):
cmake_extra_args = ['-A','Win32','-T','host=x64','-G', args.cmake_generator]
elif (args.arm or args.arm64):
# Cross-compiling for ARM(64) architecture
# First build protoc for host to use during cross-compilation
path_to_protoc_exe = build_protoc_for_host(cmake_path, source_dir, build_dir, args)
if path_to_protoc_exe is None:
path_to_protoc_exe = build_protoc_for_host(cmake_path, source_dir, build_dir, args)
if args.arm:
cmake_extra_args = ['-A', 'ARM']
else:
@ -989,13 +990,11 @@ def main():
cmake_extra_args = ['-A','x64','-T', toolset, '-G', args.cmake_generator]
if args.enable_wcos:
cmake_extra_args.append('-DCMAKE_TOOLCHAIN_FILE=' + os.path.join(source_dir, 'cmake', 'wcos_toolchain.cmake'))
if (args.android or args.ios) and not args.path_to_protoc_exe:
if (args.android or args.ios) and args.path_to_protoc_exe is None:
# Cross-compiling for Android and iOS
path_to_protoc_exe = build_protoc_for_host(cmake_path, source_dir, build_dir, args)
else :
path_to_protoc_exe = args.path_to_protoc_exe
if is_ubuntu_1604():
if (args.arm or args.arm64):
raise BuildError("Only Windows ARM(64) cross-compiled builds supported currently through this script")