@@ -142,9 +142,6 @@ def exit_with_error(msg):
142142 ARCH = 'x86'
143143elif machine .startswith ('aarch64' ) or machine .lower ().startswith ('arm64' ):
144144 ARCH = 'aarch64'
145- if WINDOWS :
146- errlog ('No support for Windows on Arm, fallback to x64' )
147- ARCH = 'x86_64'
148145elif machine .startswith ('arm' ):
149146 ARCH = 'arm'
150147else :
@@ -256,7 +253,11 @@ def vswhere(version):
256253 if not program_files :
257254 program_files = os .environ ['ProgramFiles' ]
258255 vswhere_path = os .path .join (program_files , 'Microsoft Visual Studio' , 'Installer' , 'vswhere.exe' )
259- output = json .loads (subprocess .check_output ([vswhere_path , '-latest' , '-version' , '[%s.0,%s.0)' % (version , version + 1 ), '-requires' , 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64' , '-property' , 'installationPath' , '-format' , 'json' ]))
256+ # Source: https://learn.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-build-tools?view=vs-2022
257+ tools_arch = 'ARM64' if ARCH == 'aarch64' else 'x86.x64'
258+ # The "-products *" allows detection of Build Tools, the "-prerelease" allows detection of Preview version
259+ # of Visual Studio and Build Tools.
260+ output = json .loads (subprocess .check_output ([vswhere_path , '-latest' , '-products' , '*' , '-prerelease' , '-version' , '[%s.0,%s.0)' % (version , version + 1 ), '-requires' , 'Microsoft.VisualStudio.Component.VC.Tools.' + tools_arch , '-property' , 'installationPath' , '-format' , 'json' ]))
260261 return str (output [0 ]['installationPath' ])
261262 except Exception :
262263 return ''
@@ -1014,15 +1015,41 @@ def xcode_sdk_version():
10141015 return subprocess .checkplatform .mac_ver ()[0 ].split ('.' )
10151016
10161017
1018+ def cmake_target_platform (tool ):
1019+ # Source: https://cmake.org/cmake/help/latest/generator/Visual%20Studio%2017%202022.html#platform-selection
1020+ if hasattr (tool , 'arch' ):
1021+ if tool .arch == 'aarch64' :
1022+ return 'ARM64'
1023+ elif tool .arch == 'x86_64' :
1024+ return 'x64'
1025+ elif tool .arch == 'x86' :
1026+ return 'Win32'
1027+ if ARCH == 'aarch64' :
1028+ return 'ARM64'
1029+ else :
1030+ return 'x64' if tool .bitness == 64 else 'Win32'
1031+
1032+
1033+ def cmake_host_platform ():
1034+ # Source: https://cmake.org/cmake/help/latest/generator/Visual%20Studio%2017%202022.html#toolset-selection
1035+ arch_to_cmake_host_platform = {
1036+ 'aarch64' : 'ARM64' ,
1037+ 'arm' : 'ARM' ,
1038+ 'x86_64' : 'x64' ,
1039+ 'x86' : 'x86'
1040+ }
1041+ return arch_to_cmake_host_platform [ARCH ]
1042+
1043+
10171044def get_generator_and_config_args (tool ):
10181045 args = []
10191046 cmake_generator = CMAKE_GENERATOR
10201047 if 'Visual Studio 16' in CMAKE_GENERATOR or 'Visual Studio 17' in CMAKE_GENERATOR : # VS2019 or VS2022
10211048 # With Visual Studio 16 2019, CMake changed the way they specify target arch.
10221049 # Instead of appending it into the CMake generator line, it is specified
10231050 # with a -A arch parameter.
1024- args += ['-A' , 'x64' if tool . bitness == 64 else 'x86' ]
1025- args += ['-Thost=x64' ]
1051+ args += ['-A' , cmake_target_platform ( tool ) ]
1052+ args += ['-Thost=' + cmake_host_platform () ]
10261053 elif 'Visual Studio' in CMAKE_GENERATOR and tool .bitness == 64 :
10271054 cmake_generator += ' Win64'
10281055 args += ['-Thost=x64' ]
@@ -1831,6 +1858,10 @@ def install_tool(self):
18311858 elif hasattr (self , 'git_branch' ):
18321859 success = git_clone_checkout_and_pull (url , self .installation_path (), self .git_branch )
18331860 elif url .endswith (ARCHIVE_SUFFIXES ):
1861+ global ARCH
1862+ if WINDOWS and ARCH == 'aarch64' :
1863+ errlog ('No support for Windows on Arm, fallback to x64' )
1864+ ARCH = 'x86_64'
18341865 success = download_and_unzip (url , self .installation_path (), filename_prefix = getattr (self , 'zipfile_prefix' , '' ))
18351866 else :
18361867 assert False , 'unhandled url type: ' + url
0 commit comments