From 2e859bab02023c4f2c44aceab287a13fd11dc037 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 9 Oct 2023 09:19:51 +0530 Subject: [PATCH] Use the newest available Visual Studio --- setup/vcvars.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/setup/vcvars.py b/setup/vcvars.py index 25eb65b05f..90e9de8482 100644 --- a/setup/vcvars.py +++ b/setup/vcvars.py @@ -9,17 +9,6 @@ import sys from functools import lru_cache from glob import glob -# See the table at https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B#Internal_version_numbering -python_msc_version = int(re.search(r'\[MSC v\.(\d+) ', sys.version).group(1)) -if python_msc_version < 1920: - raise SystemExit(f'Python MSC version {python_msc_version} too old, needs Visual studio 2019') -if python_msc_version > 1929: - raise SystemExit(f'Python MSC version {python_msc_version} too new, needs Visual studio 2019') - -# The values are for VisualStudio 2022 (python_msc_version 192_) -VS_VERSION = '17.0' -COMN_TOOLS_VERSION = '170' - CSIDL_PROGRAM_FILES = 38 CSIDL_PROGRAM_FILESX86 = 42 @@ -49,10 +38,10 @@ def get_output(*cmd): @lru_cache() -def find_visual_studio(version=VS_VERSION): +def find_visual_studio(): path = get_output( find_vswhere(), - "-version", version, + "-latest", "-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64", "-property", @@ -64,10 +53,10 @@ def find_visual_studio(version=VS_VERSION): @lru_cache() -def find_msbuild(version=VS_VERSION): +def find_msbuild(): base_path = get_output( find_vswhere(), - "-version", version, + "-latest", "-requires", "Microsoft.Component.MSBuild", "-property", 'installationPath' ).strip() @@ -129,6 +118,16 @@ def query_vcvarsall(is64bit=True): plat = 'amd64' if is64bit else 'amd64_x86' vcvarsall = find_vcvarsall() env = query_process(f'"{vcvarsall}" {plat} & set', is64bit) + pat = re.compile('vs(\d+)comntools', re.I) + + comn_tools = {} + + for k in env: + m = pat.match(k) + if m is not None: + comn_tools[k] = int(m.group(1)) + comntools = sorted(comn_tools, key=comn_tools.__getitem__)[-1] + def g(k): try: @@ -145,7 +144,7 @@ def query_vcvarsall(is64bit=True): k: g(k) for k in ( 'PATH LIB INCLUDE LIBPATH WINDOWSSDKDIR' - f' VS{COMN_TOOLS_VERSION}COMNTOOLS PLATFORM' + f' {comntools} PLATFORM' ' UCRTVERSION UNIVERSALCRTSDKDIR VCTOOLSVERSION WINDOWSSDKDIR' ' WINDOWSSDKVERSION WINDOWSSDKVERBINPATH WINDOWSSDKBINPATH' ' VISUALSTUDIOVERSION VSCMD_ARG_HOST_ARCH VSCMD_ARG_TGT_ARCH'