From a523998630f76824e808d4c3e1a3fbb0b3fac602 Mon Sep 17 00:00:00 2001 From: Fabien LOISON Date: Mon, 25 Nov 2024 13:34:37 +0100 Subject: [PATCH] fix(build): Fixed Windows build with recent setuptools versions --- setup.py | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index 9c436c1..fea47ef 100644 --- a/setup.py +++ b/setup.py @@ -11,12 +11,33 @@ def _find_msbuild(plat_spec="x64"): from setuptools import msvc - vc_env = msvc.msvc14_get_vc_env(plat_spec) - if "vsinstalldir" not in vc_env: - raise Exception("Unable to find any Visual Studio installation") - return os.path.join( - vc_env["vsinstalldir"], "MSBuild", "Current", "Bin", "MSBuild.exe" - ) + if hasattr(msvc, "msvc14_get_vc_env"): + vc_env = msvc.msvc14_get_vc_env(plat_spec) + if "vsinstalldir" in vc_env: + msbuild_path = os.path.join( + vc_env["vsinstalldir"], + "MSBuild", + "Current", + "Bin", + "MSBuild.exe", + ) + if os.path.isfile(msbuild_path): + return msbuild_path + + for path in msvc.EnvironmentInfo(plat_spec).VCTools: + if "\\VC\\" not in path: + continue + msbuild_path = os.path.join( + path[: path.index("\\VC\\")], + "MSBuild", + "Current", + "Bin", + "MSBuild.exe", + ) + if os.path.isfile(msbuild_path): + return msbuild_path + + raise Exception("Unable to find any Visual Studio installation") class CustomBuildExt(build_ext):