From 196d44b8a1bd626764e9679c1b4b77ccc1d7ed3f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 27 Aug 2024 11:31:46 -0400 Subject: [PATCH 1/2] Apply downstream VS 2017 support. Ref pypa/setuptools#2663 and pypa/setuptools#3950 and pypa/setuptools#4600 --- distutils/_msvccompiler.py | 56 ++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/distutils/_msvccompiler.py b/distutils/_msvccompiler.py index b0322410..14efed83 100644 --- a/distutils/_msvccompiler.py +++ b/distutils/_msvccompiler.py @@ -79,32 +79,40 @@ def _find_vc2017(): if not root: return None, None - try: - path = subprocess.check_output( - [ - os.path.join( - root, "Microsoft Visual Studio", "Installer", "vswhere.exe" - ), - "-latest", - "-prerelease", - "-requires", - "Microsoft.VisualStudio.Component.VC.Tools.x86.x64", - "-property", - "installationPath", - "-products", - "*", - ], - encoding="mbcs", - errors="strict", - ).strip() - except (subprocess.CalledProcessError, OSError, UnicodeDecodeError): - return None, None + variant = 'arm64' if get_platform() == 'win-arm64' else 'x86.x64' + suitable_components = ( + f"Microsoft.VisualStudio.Component.VC.Tools.{variant}", + "Microsoft.VisualStudio.Workload.WDExpress", + ) + + for component in suitable_components: + # Workaround for `-requiresAny` (only available on VS 2017 > 15.6) + with contextlib.suppress( + subprocess.CalledProcessError, OSError, UnicodeDecodeError + ): + path = ( + subprocess.check_output([ + os.path.join( + root, "Microsoft Visual Studio", "Installer", "vswhere.exe" + ), + "-latest", + "-prerelease", + "-requires", + component, + "-property", + "installationPath", + "-products", + "*", + ]) + .decode(encoding="mbcs", errors="strict") + .strip() + ) - path = os.path.join(path, "VC", "Auxiliary", "Build") - if os.path.isdir(path): - return 15, path + path = os.path.join(path, "VC", "Auxiliary", "Build") + if os.path.isdir(path): + return 15, path - return None, None + return None, None # no suitable component found PLAT_SPEC_TO_RUNTIME = { From 5f1160f4a0f3fababf5222edbf536f1690d94ed1 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 27 Aug 2024 11:43:34 -0400 Subject: [PATCH 2/2] Apply error message from downstream. Ref pypa/setuptools#4600 and pypa/setuptools#2334 --- distutils/_msvccompiler.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/distutils/_msvccompiler.py b/distutils/_msvccompiler.py index 14efed83..425bd72b 100644 --- a/distutils/_msvccompiler.py +++ b/distutils/_msvccompiler.py @@ -148,7 +148,11 @@ def _get_vc_env(plat_spec): vcvarsall, _ = _find_vcvarsall(plat_spec) if not vcvarsall: - raise DistutilsPlatformError("Unable to find vcvarsall.bat") + raise DistutilsPlatformError( + 'Microsoft Visual C++ 14.0 or greater is required. ' + 'Get it with "Microsoft C++ Build Tools": ' + 'https://visualstudio.microsoft.com/visual-cpp-build-tools/' + ) try: out = subprocess.check_output(