|
26 | 26 | from setuptools.command.egg_info import egg_info |
27 | 27 | from wheel.bdist_wheel import bdist_wheel |
28 | 28 |
|
| 29 | +from CLFinder import initialize_visual_studio_env |
| 30 | + |
29 | 31 | import pybind11 |
30 | 32 |
|
31 | 33 |
|
@@ -103,56 +105,6 @@ def copy_externals(): |
103 | 105 | ] |
104 | 106 |
|
105 | 107 |
|
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 | | - |
156 | 108 | # Taken from https://github.com/pytorch/pytorch/blob/master/tools/setup_helpers/env.py |
157 | 109 | def check_env_flag(name: str, default: str = "") -> bool: |
158 | 110 | return os.getenv(name, default).upper() in ["ON", "1", "YES", "TRUE", "Y"] |
|
0 commit comments