Skip to content

Commit 61f5381

Browse files
authored
Allow different Microsoft products for the search of VC.Tools.x86.x64 (#2744)
Signed-off-by: Anatoly Myachev <[email protected]>
1 parent 80fd6c0 commit 61f5381

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

python/setup.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ def find_visual_studio(version_ranges):
119119
for version_range in version_ranges:
120120
command = [
121121
str(vswhere), "-version", version_range, "-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
122-
"-property", "installationPath", "-prerelease"
122+
"-products", "*", "-property", "installationPath", "-prerelease"
123123
]
124124

125125
try:
126126
output = subprocess.check_output(command, text=True).strip()
127127
if output:
128-
return output
128+
return output.split("\n")[0]
129129
except subprocess.CalledProcessError:
130130
continue
131131

@@ -146,6 +146,13 @@ def set_env_vars(vs_path, arch="x64"):
146146
os.environ[var] = value
147147

148148

149+
def initialize_visual_studio_env(version_ranges, arch="x64"):
150+
vs_path = find_visual_studio(version_ranges)
151+
if not vs_path:
152+
raise EnvironmentError("Visual Studio not found in specified version ranges.")
153+
set_env_vars(vs_path, arch)
154+
155+
149156
# Taken from https://github.com/pytorch/pytorch/blob/master/tools/setup_helpers/env.py
150157
def check_env_flag(name: str, default: str = "") -> bool:
151158
return os.getenv(name, default).upper() in ["ON", "1", "YES", "TRUE", "Y"]
@@ -447,10 +454,7 @@ def build_extension(self, ext):
447454
lit_dir = shutil.which('lit')
448455
ninja_dir = shutil.which('ninja')
449456
if platform.system() == "Windows":
450-
vs_path = find_visual_studio(["[17.0,18.0)", "[16.0,17.0)"])
451-
env = set_env_vars(vs_path)
452-
if not vs_path:
453-
raise EnvironmentError("Visual Studio 2019 or 2022 not found.")
457+
initialize_visual_studio_env(["[17.0,18.0)", "[16.0,17.0)"])
454458
# lit is used by the test suite
455459
thirdparty_cmake_args = get_thirdparty_packages([get_llvm_package_info()])
456460
thirdparty_cmake_args += self.get_pybind11_cmake_args()

python/triton/runtime/CLFinder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ def find_visual_studio(version_ranges):
1919
for version_range in version_ranges:
2020
command = [
2121
str(vswhere), "-version", version_range, "-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
22-
"-property", "installationPath", "-prerelease"
22+
"-products", "*", "-property", "installationPath", "-prerelease"
2323
]
2424

2525
try:
2626
output = subprocess.check_output(command, text=True).strip()
2727
if output:
28-
return output
28+
return output.split("\n")[0]
2929
except subprocess.CalledProcessError:
3030
continue
3131

@@ -37,7 +37,7 @@ def set_env_vars(vs_path, arch="x64"):
3737
if not vcvarsall_path.exists():
3838
raise FileNotFoundError(f"vcvarsall.bat not found in expected path: {vcvarsall_path}")
3939

40-
command = f'call "{vcvarsall_path}" {arch} && set'
40+
command = ["call", vcvarsall_path, arch, "&&", "set"]
4141
output = subprocess.check_output(command, shell=True, text=True)
4242

4343
for line in output.splitlines():

0 commit comments

Comments
 (0)