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.
This commit is contained in:
Changming Sun 2023-04-11 17:14:54 -07:00 committed by GitHub
parent 9c42d5e31f
commit db4fc12318
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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):