-
Notifications
You must be signed in to change notification settings - Fork 75
Allow different Microsoft products for the search of VC.Tools.x86.x64
#2744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
10d4a96
6e76f02
70b5fb0
d31b3cc
23ba54f
f5f7101
e986f52
db18b5d
1ac5119
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,6 +103,49 @@ 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", | ||
| "-property", "installationPath", "-prerelease" | ||
| ] | ||
|
|
||
| try: | ||
| output = subprocess.check_output(command, text=True).strip() | ||
| if output: | ||
| return output | ||
| except subprocess.CalledProcessError: | ||
| continue | ||
|
|
||
| return None | ||
|
|
||
|
|
||
| def set_env_vars(vs_path, arch="x64"): | ||
| vcvarsall_path = Path(vs_path) / "VC" / "Auxiliary" / "Build" / "vcvarsall.bat" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The case when vs_path is None is not handled. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will be processed at a higher level: https://github.com/intel/intel-xpu-backend-for-triton/pull/2478/files#r1848201018 |
||
| 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 | ||
|
|
||
|
|
||
| # 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"] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| 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", | ||
| "-property", "installationPath", "-prerelease" | ||
| ] | ||
|
|
||
| try: | ||
| output = subprocess.check_output(command, text=True).strip() | ||
| if output: | ||
| return output | ||
| 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As of now we don't know how to reuse the code from
CLFinder.py. See https://github.com/intel/intel-xpu-backend-for-triton/pull/2478/files#r1831953188 for details.