Skip to content

Commit

Permalink
Setup MSVC environment in CI workflow (#2942)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
anmyachev authored Dec 7, 2024
1 parent c878427 commit b57f1b5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 109 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/build-test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 0 additions & 52 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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()
Expand Down
55 changes: 0 additions & 55 deletions python/triton/runtime/CLFinder.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/triton/runtime/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import subprocess
import setuptools
import platform
from .CLFinder import initialize_visual_studio_env


def is_xpu():
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b57f1b5

Please sign in to comment.