Build the module in the given build directory using ninja.
(build_dir: str)
| 584 | |
| 585 | |
| 586 | def build_ninja(build_dir: str) -> None: |
| 587 | """Build the module in the given build directory using ninja.""" |
| 588 | command = ["ninja", "-v"] |
| 589 | num_workers = os.environ.get("MAX_JOBS", None) |
| 590 | if num_workers is not None: |
| 591 | command += ["-j", num_workers] |
| 592 | if IS_WINDOWS: |
| 593 | status = _run_command_in_dev_prompt(args=command, cwd=build_dir, capture_output=True) |
| 594 | else: |
| 595 | status = subprocess.run(check=False, args=command, cwd=build_dir, capture_output=True) |
| 596 | encoding = "oem" if IS_WINDOWS else "utf-8" |
| 597 | if status.returncode != 0: |
| 598 | msg = [f"ninja exited with status {status.returncode}"] |
| 599 | if status.stdout: |
| 600 | msg.append(f"stdout:\n{status.stdout.decode(encoding)}") |
| 601 | if status.stderr: |
| 602 | msg.append(f"stderr:\n{status.stderr.decode(encoding)}") |
| 603 | |
| 604 | raise RuntimeError("\n".join(msg)) |
| 605 | |
| 606 | LOG_BUILD = os.environ.get("TVM_FFI_CPP_EXTENSION_LOG_BUILD", "0") |
| 607 | if LOG_BUILD in ("1", "stdout"): |
| 608 | logger.info("ninja build stdout:\n%s", status.stdout.decode(encoding)) |
| 609 | if LOG_BUILD in ("1", "stderr"): |
| 610 | logger.info("ninja build stderr:\n%s", status.stderr.decode(encoding)) |
| 611 | |
| 612 | |
| 613 | # Translation table for escaping C++ string literals |
no test coverage detected