-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuild.py
73 lines (55 loc) · 1.95 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
import os
import sys
import subprocess
from typing import List
import pybind11
ROOT_DIR = os.path.abspath("./")
BUILD_DIR = os.path.join(ROOT_DIR, "build")
def get_pybind11_cmake_args():
pybind11_sys_path = os.getenv("PYBIND11_SYSPATH")
if pybind11_sys_path:
# pybind11_include_dir = os.path.join(pybind11_sys_path, "include")
pybind11_cmake_dir = os.path.join(pybind11_sys_path, "share", "cmake", "pybind11")
else:
# pybind11_include_dir = pybind11.get_include()
pybind11_cmake_dir = pybind11.get_cmake_dir()
# print(f"{pybind11_include_dir=}")
print(f"{pybind11_cmake_dir=}")
return [f"-Dpybind11_DIR={pybind11_cmake_dir}"]
def run(cmd: List[str], cwd: str="./"):
print_cmd = " ".join(cmd)
print(f"\nlaunch: {print_cmd}")
message = subprocess.run(cmd, cwd=cwd)
if "returncode=0" in str(message):
print(f" -> SUCCESS")
return True
print(f" -> ERROR with message: '{message}'\n")
return False
def build_local(num_threads: int):
USE_SYSTEM_DEPS = os.getenv("USE_SYSTEM_DEPS", "OFF")
print("python prefix: ", sys.exec_prefix)
print("python executable: ", sys.executable)
config_cmd = [
"cmake",
"-B", f"{BUILD_DIR}",
f"-DUSE_SYSTEM_DEPS={USE_SYSTEM_DEPS}",
f"-DPYTHON_EXECUTABLE={sys.executable}",
]
config_cmd.extend(get_pybind11_cmake_args())
success = run(config_cmd, cwd=ROOT_DIR)
if not success:
raise RuntimeError("Error building.")
build_cmd = [
"cmake",
"--build", f"{BUILD_DIR}",
"--target=install",
]
if num_threads > 1:
build_cmd.extend(["-j", f"{num_threads}"])
success = run(build_cmd, cwd=ROOT_DIR)
if not success:
raise RuntimeError("Error building.")
if "__main__" == __name__:
num_threads = int(os.getenv("BUILD_THREADS", "4"))
build_local(num_threads=num_threads)