From db4fc12318575cecaa1ffa09e68fc1f596dff18d Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Tue, 11 Apr 2023 17:14:54 -0700 Subject: [PATCH] Add support for building the code on Windows ARM64 natively (#15371) ### Description Recently Visual Studio and python started to provide native Windows ARM64 packages. This PR is to provide better support for building on Windows ARM64. You can do it as what you did for x64. Like: ``` python tools\ci_build\build.py --config Debug --update --skip_submodule_sync --build_dir b --cmake_generator "Visual Studio 17 2022" ``` You do not need to append the "--arm64" build arg, and do not need to cross-compile protoc for a different arch as you are not cross-compiling. **caveat:** it does not work with the latest cmake release(3.26.x). It only works fine with cmake 3.25.x and below. Filed a bug to them: https://gitlab.kitware.com/cmake/cmake/-/issues/24797 ### Motivation and Context Provide better support for building on Windows ARM64. --- tools/ci_build/build.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index 24a656765c..1efc5c1f37 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -2462,16 +2462,25 @@ def main(): "ARM(64) builds. Will skip test running after build." ) args.test = False - elif cpu_arch == "32bit" or args.x86: - cmake_extra_args = ["-A", "Win32", "-T", "host=x64", "-G", args.cmake_generator] else: - if args.msvc_toolset: - toolset = "host=x64,version=" + args.msvc_toolset + target_arch = platform.machine() + if target_arch == "AMD64": + if cpu_arch == "32bit" or args.x86: + target_arch = "Win32" + else: + target_arch = "x64" + host_arch = "x64" + elif target_arch == "ARM64": + host_arch = "ARM64" else: - toolset = "host=x64" + raise BuildError("unknown python arch") + if args.msvc_toolset: + toolset = "host=" + host_arch + ",version=" + args.msvc_toolset + else: + toolset = "host=" + host_arch if args.cuda_version: toolset += ",cuda=" + args.cuda_version - cmake_extra_args = ["-A", "x64", "-T", toolset, "-G", args.cmake_generator] + cmake_extra_args = ["-A", target_arch, "-T", toolset, "-G", args.cmake_generator] if args.enable_wcos: cmake_extra_defines.append("CMAKE_USER_MAKE_RULES_OVERRIDE=wcos_rules_override.cmake") elif args.cmake_generator is not None and not (is_macOS() and args.use_xcode):