55import sys
66
77import subprocess
8+ from typing import List
9+ import pybind11
810
911ROOT_DIR = os .path .abspath ("./" )
1012BUILD_DIR = os .path .join (ROOT_DIR , "build" )
1113
14+ def get_pybind11_cmake_args ():
15+ pybind11_sys_path = os .getenv ("PYBIND11_SYSPATH" )
16+ if pybind11_sys_path :
17+ # pybind11_include_dir = os.path.join(pybind11_sys_path, "include")
18+ pybind11_cmake_dir = os .path .join (pybind11_sys_path , "share" , "cmake" , "pybind11" )
19+ else :
20+ # pybind11_include_dir = pybind11.get_include()
21+ pybind11_cmake_dir = pybind11 .get_cmake_dir ()
22+ # print(f"{pybind11_include_dir=}")
23+ print (f"{ pybind11_cmake_dir = } " )
24+ return [f"-Dpybind11_DIR={ pybind11_cmake_dir } " ]
1225
13- def run (cmd , cwd = "./" ):
26+ def run (cmd : List [ str ] , cwd : str = "./" ):
1427
15- print (f"\n launch: { cmd } " )
28+ print_cmd = " " .join (cmd )
29+ print (f"\n launch: { print_cmd } " )
1630
17- parts = cmd .split (" " )
18- message = subprocess .run (parts , cwd = cwd )
31+ message = subprocess .run (cmd , cwd = cwd )
1932
2033 if "returncode=0" in str (message ):
2134 print (f" -> SUCCESS" )
@@ -27,20 +40,26 @@ def run(cmd, cwd="./"):
2740
2841def build_local (num_threads : int ):
2942
30- if not os .path .exists (BUILD_DIR ):
31- print ("python executable: " , sys .executable )
32-
33- cmd = f"cmake -B { BUILD_DIR } -DPYTHON_EXECUTABLE={ sys .executable } "
34- success = run (cmd , cwd = ROOT_DIR )
35- if not success :
36- raise RuntimeError ("Error building." )
37- else :
38- print (f"build directory detected: { BUILD_DIR } " )
43+ print ("python prefix: " , sys .exec_prefix )
44+ config_cmd = [
45+ "cmake" ,
46+ "-B" , f"{ BUILD_DIR } " ,
47+ f"-DPython_ROOT_DIR={ sys .exec_prefix } " ,
48+ f"-DPython3_ROOT_DIR={ sys .exec_prefix } " ,
49+ ]
50+ config_cmd .extend (get_pybind11_cmake_args ())
51+ success = run (config_cmd , cwd = ROOT_DIR )
52+ if not success :
53+ raise RuntimeError ("Error building." )
3954
40- cmd = f"cmake --build { BUILD_DIR } --target install"
55+ build_cmd = [
56+ "cmake" ,
57+ "--build" , f"{ BUILD_DIR } " ,
58+ "--target=install" ,
59+ ]
4160 if num_threads > 1 :
42- cmd += f" -j { num_threads } "
43- success = run (cmd , cwd = ROOT_DIR )
61+ build_cmd . extend ([ "-j" , f" { num_threads } "])
62+ success = run (build_cmd , cwd = ROOT_DIR )
4463 if not success :
4564 raise RuntimeError ("Error building." )
4665
0 commit comments