diff --git a/.github/workflows/build-test-windows.yml b/.github/workflows/build-test-windows.yml index d5b78c1bbe..2927086eb0 100644 --- a/.github/workflows/build-test-windows.yml +++ b/.github/workflows/build-test-windows.yml @@ -45,6 +45,13 @@ jobs: - name: Build Triton run: | cd ${{ env.NEW_WORKSPACE }} + + cmd /c '"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 && set' | ForEach-Object { + if ($_ -match '^(.*?)=(.*)$') { + [Environment]::SetEnvironmentVariable($matches[1], $matches[2]) + } + } + cd python pip install -U wheel pybind11 certifi cython cmake setuptools>=65.6.1 python -m certifi diff --git a/python/setup.py b/python/setup.py index 4ee43718cb..0bde0f7b1c 100644 --- a/python/setup.py +++ b/python/setup.py @@ -103,56 +103,6 @@ def copy_externals(): ] -def find_vswhere(): - program_files = os.environ.get("ProgramFiles(x86)", "C:\\Program Files (x86)") - vswhere_path = Path(program_files) / "Microsoft Visual Studio" / "Installer" / "vswhere.exe" - if vswhere_path.exists(): - return vswhere_path - return None - - -def find_visual_studio(version_ranges): - vswhere = find_vswhere() - if not vswhere: - raise FileNotFoundError("vswhere.exe not found.") - - for version_range in version_ranges: - command = [ - str(vswhere), "-version", version_range, "-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64", - "-products", "*", "-property", "installationPath", "-prerelease" - ] - - try: - output = subprocess.check_output(command, text=True).strip() - if output: - return output.split("\n")[0] - except subprocess.CalledProcessError: - continue - - return None - - -def set_env_vars(vs_path, arch="x64"): - vcvarsall_path = Path(vs_path) / "VC" / "Auxiliary" / "Build" / "vcvarsall.bat" - if not vcvarsall_path.exists(): - raise FileNotFoundError(f"vcvarsall.bat not found in expected path: {vcvarsall_path}") - - command = ["call", vcvarsall_path, arch, "&&", "set"] - output = subprocess.check_output(command, shell=True, text=True) - - for line in output.splitlines(): - if '=' in line: - var, value = line.split('=', 1) - os.environ[var] = value - - -def initialize_visual_studio_env(version_ranges, arch="x64"): - vs_path = find_visual_studio(version_ranges) - if not vs_path: - raise EnvironmentError("Visual Studio not found in specified version ranges.") - set_env_vars(vs_path, arch) - - # Taken from https://github.com/pytorch/pytorch/blob/master/tools/setup_helpers/env.py def check_env_flag(name: str, default: str = "") -> bool: return os.getenv(name, default).upper() in ["ON", "1", "YES", "TRUE", "Y"] @@ -475,8 +425,6 @@ def get_proton_cmake_args(self): def build_extension(self, ext): lit_dir = shutil.which('lit') ninja_dir = shutil.which('ninja') - if platform.system() == "Windows": - initialize_visual_studio_env(["[17.0,18.0)", "[16.0,17.0)"]) # lit is used by the test suite thirdparty_cmake_args = get_thirdparty_packages([get_llvm_package_info()]) thirdparty_cmake_args += self.get_pybind11_cmake_args() diff --git a/python/triton/runtime/CLFinder.py b/python/triton/runtime/CLFinder.py deleted file mode 100644 index 1a489a2e3c..0000000000 --- a/python/triton/runtime/CLFinder.py +++ /dev/null @@ -1,55 +0,0 @@ -import os -import subprocess -from pathlib import Path - - -def find_vswhere(): - program_files = os.environ.get("ProgramFiles(x86)", "C:\\Program Files (x86)") - vswhere_path = Path(program_files) / "Microsoft Visual Studio" / "Installer" / "vswhere.exe" - if vswhere_path.exists(): - return vswhere_path - return None - - -def find_visual_studio(version_ranges): - vswhere = find_vswhere() - if not vswhere: - raise FileNotFoundError("vswhere.exe not found.") - - for version_range in version_ranges: - command = [ - str(vswhere), "-version", version_range, "-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64", - "-products", "*", "-property", "installationPath", "-prerelease" - ] - - try: - output = subprocess.check_output(command, text=True).strip() - if output: - return output.split("\n")[0] - except subprocess.CalledProcessError: - continue - - return None - - -def set_env_vars(vs_path, arch="x64"): - vcvarsall_path = Path(vs_path) / "VC" / "Auxiliary" / "Build" / "vcvarsall.bat" - if not vcvarsall_path.exists(): - raise FileNotFoundError(f"vcvarsall.bat not found in expected path: {vcvarsall_path}") - - command = ["call", vcvarsall_path, arch, "&&", "set"] - output = subprocess.check_output(command, shell=True, text=True) - - for line in output.splitlines(): - if '=' in line: - var, value = line.split('=', 1) - os.environ[var] = value - - -def initialize_visual_studio_env(version_ranges, arch="x64"): - # Check if the environment variable that vcvarsall.bat sets is present - if os.environ.get('VSCMD_ARG_TGT_ARCH') != arch: - vs_path = find_visual_studio(version_ranges) - if not vs_path: - raise EnvironmentError("Visual Studio not found in specified version ranges.") - set_env_vars(vs_path, arch) diff --git a/python/triton/runtime/build.py b/python/triton/runtime/build.py index b40411aec6..ec294aee71 100644 --- a/python/triton/runtime/build.py +++ b/python/triton/runtime/build.py @@ -7,7 +7,6 @@ import subprocess import setuptools import platform -from .CLFinder import initialize_visual_studio_env def is_xpu(): @@ -60,7 +59,6 @@ def _build(name, src, srcdir, library_dirs, include_dirs, libraries, extra_compi cc = gcc if gcc is not None else clang if platform.system() == "Windows": cc = "cl" - initialize_visual_studio_env(["[17.0,18.0)", "[16.0,17.0)"]) if cc is None: raise RuntimeError("Failed to find C compiler. Please specify via CC environment variable.") # This function was renamed and made public in Python 3.10