Skip to content

Commit b57f1b5

Browse files
authored
Setup MSVC environment in CI workflow (#2942)
Part of #2030 Part of #2824 For all other compilers the situation is about the same, it is expected that they are already in the paths. I don't think it should be any different for Windows. --------- Signed-off-by: Anatoly Myachev <[email protected]>
1 parent c878427 commit b57f1b5

File tree

4 files changed

+7
-109
lines changed

4 files changed

+7
-109
lines changed

.github/workflows/build-test-windows.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ jobs:
4545
- name: Build Triton
4646
run: |
4747
cd ${{ env.NEW_WORKSPACE }}
48+
49+
cmd /c '"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 && set' | ForEach-Object {
50+
if ($_ -match '^(.*?)=(.*)$') {
51+
[Environment]::SetEnvironmentVariable($matches[1], $matches[2])
52+
}
53+
}
54+
4855
cd python
4956
pip install -U wheel pybind11 certifi cython cmake setuptools>=65.6.1
5057
python -m certifi

python/setup.py

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -103,56 +103,6 @@ def copy_externals():
103103
]
104104

105105

106-
def find_vswhere():
107-
program_files = os.environ.get("ProgramFiles(x86)", "C:\\Program Files (x86)")
108-
vswhere_path = Path(program_files) / "Microsoft Visual Studio" / "Installer" / "vswhere.exe"
109-
if vswhere_path.exists():
110-
return vswhere_path
111-
return None
112-
113-
114-
def find_visual_studio(version_ranges):
115-
vswhere = find_vswhere()
116-
if not vswhere:
117-
raise FileNotFoundError("vswhere.exe not found.")
118-
119-
for version_range in version_ranges:
120-
command = [
121-
str(vswhere), "-version", version_range, "-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
122-
"-products", "*", "-property", "installationPath", "-prerelease"
123-
]
124-
125-
try:
126-
output = subprocess.check_output(command, text=True).strip()
127-
if output:
128-
return output.split("\n")[0]
129-
except subprocess.CalledProcessError:
130-
continue
131-
132-
return None
133-
134-
135-
def set_env_vars(vs_path, arch="x64"):
136-
vcvarsall_path = Path(vs_path) / "VC" / "Auxiliary" / "Build" / "vcvarsall.bat"
137-
if not vcvarsall_path.exists():
138-
raise FileNotFoundError(f"vcvarsall.bat not found in expected path: {vcvarsall_path}")
139-
140-
command = ["call", vcvarsall_path, arch, "&&", "set"]
141-
output = subprocess.check_output(command, shell=True, text=True)
142-
143-
for line in output.splitlines():
144-
if '=' in line:
145-
var, value = line.split('=', 1)
146-
os.environ[var] = value
147-
148-
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-
156106
# Taken from https://github.com/pytorch/pytorch/blob/master/tools/setup_helpers/env.py
157107
def check_env_flag(name: str, default: str = "") -> bool:
158108
return os.getenv(name, default).upper() in ["ON", "1", "YES", "TRUE", "Y"]
@@ -475,8 +425,6 @@ def get_proton_cmake_args(self):
475425
def build_extension(self, ext):
476426
lit_dir = shutil.which('lit')
477427
ninja_dir = shutil.which('ninja')
478-
if platform.system() == "Windows":
479-
initialize_visual_studio_env(["[17.0,18.0)", "[16.0,17.0)"])
480428
# lit is used by the test suite
481429
thirdparty_cmake_args = get_thirdparty_packages([get_llvm_package_info()])
482430
thirdparty_cmake_args += self.get_pybind11_cmake_args()

python/triton/runtime/CLFinder.py

Lines changed: 0 additions & 55 deletions
This file was deleted.

python/triton/runtime/build.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import subprocess
88
import setuptools
99
import platform
10-
from .CLFinder import initialize_visual_studio_env
1110

1211

1312
def is_xpu():
@@ -60,7 +59,6 @@ def _build(name, src, srcdir, library_dirs, include_dirs, libraries, extra_compi
6059
cc = gcc if gcc is not None else clang
6160
if platform.system() == "Windows":
6261
cc = "cl"
63-
initialize_visual_studio_env(["[17.0,18.0)", "[16.0,17.0)"])
6462
if cc is None:
6563
raise RuntimeError("Failed to find C compiler. Please specify via CC environment variable.")
6664
# This function was renamed and made public in Python 3.10

0 commit comments

Comments
 (0)