|
8 | 8 | import ast |
9 | 9 | import glob |
10 | 10 | import shutil |
| 11 | +import tempfile |
11 | 12 | from pathlib import Path |
12 | 13 | from typing import Literal, Optional |
13 | 14 | from packaging.version import parse, Version |
@@ -637,6 +638,35 @@ def __init__(self, *args, **kwargs) -> None: |
637 | 638 |
|
638 | 639 | super().__init__(*args, **kwargs) |
639 | 640 |
|
| 641 | + def build_extensions(self) -> None: |
| 642 | + original_spawn = None |
| 643 | + if sys.platform == "win32" and self.compiler.compiler_type == "msvc": |
| 644 | + original_spawn = self.compiler.spawn |
| 645 | + |
| 646 | + def spawn(cmd): |
| 647 | + if not cmd or Path(str(cmd[0])).name.lower() != "link.exe": |
| 648 | + return original_spawn(cmd) |
| 649 | + cmd = [str(arg) for arg in cmd] |
| 650 | + if len(subprocess.list2cmdline(cmd)) <= 32767: |
| 651 | + return original_spawn(cmd) |
| 652 | + # Temporary workaround adapted from https://github.com/pypa/distutils/pull/406 |
| 653 | + # until setuptools/distutils ships response-file handling for long MSVC links. |
| 654 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 655 | + rsp_path = Path(tmpdir) / "cmdline.txt" |
| 656 | + rsp_path.write_text( |
| 657 | + "\n".join(subprocess.list2cmdline([arg]) for arg in cmd[1:]) + "\n", |
| 658 | + encoding="ascii", |
| 659 | + ) |
| 660 | + return original_spawn([cmd[0], f"@{rsp_path}"]) |
| 661 | + |
| 662 | + self.compiler.spawn = spawn |
| 663 | + |
| 664 | + try: |
| 665 | + super().build_extensions() |
| 666 | + finally: |
| 667 | + if original_spawn is not None: |
| 668 | + self.compiler.spawn = original_spawn |
| 669 | + |
640 | 670 |
|
641 | 671 | # Build install_requires based on platform |
642 | 672 | if ROCM_BACKEND == "triton": |
|
0 commit comments