@@ -142,9 +142,6 @@ def exit_with_error(msg):
142
142
ARCH = 'x86'
143
143
elif machine .startswith ('aarch64' ) or machine .lower ().startswith ('arm64' ):
144
144
ARCH = 'aarch64'
145
- if WINDOWS :
146
- errlog ('No support for Windows on Arm, fallback to x64' )
147
- ARCH = 'x86_64'
148
145
elif machine .startswith ('arm' ):
149
146
ARCH = 'arm'
150
147
else :
@@ -256,7 +253,11 @@ def vswhere(version):
256
253
if not program_files :
257
254
program_files = os .environ ['ProgramFiles' ]
258
255
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' ]))
260
261
return str (output [0 ]['installationPath' ])
261
262
except Exception :
262
263
return ''
@@ -1014,15 +1015,41 @@ def xcode_sdk_version():
1014
1015
return subprocess .checkplatform .mac_ver ()[0 ].split ('.' )
1015
1016
1016
1017
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
+
1017
1044
def get_generator_and_config_args (tool ):
1018
1045
args = []
1019
1046
cmake_generator = CMAKE_GENERATOR
1020
1047
if 'Visual Studio 16' in CMAKE_GENERATOR or 'Visual Studio 17' in CMAKE_GENERATOR : # VS2019 or VS2022
1021
1048
# With Visual Studio 16 2019, CMake changed the way they specify target arch.
1022
1049
# Instead of appending it into the CMake generator line, it is specified
1023
1050
# 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 () ]
1026
1053
elif 'Visual Studio' in CMAKE_GENERATOR and tool .bitness == 64 :
1027
1054
cmake_generator += ' Win64'
1028
1055
args += ['-Thost=x64' ]
@@ -1831,6 +1858,10 @@ def install_tool(self):
1831
1858
elif hasattr (self , 'git_branch' ):
1832
1859
success = git_clone_checkout_and_pull (url , self .installation_path (), self .git_branch )
1833
1860
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'
1834
1865
success = download_and_unzip (url , self .installation_path (), filename_prefix = getattr (self , 'zipfile_prefix' , '' ))
1835
1866
else :
1836
1867
assert False , 'unhandled url type: ' + url
0 commit comments