2020import sys
2121
2222
23- def run (cmd , env = None , cwd = None ):
23+ def resolve_compilers (
24+ oneapi : bool ,
25+ c_compiler : str ,
26+ cxx_compiler : str ,
27+ compiler_root : str ,
28+ ):
29+ is_linux = "linux" in sys .platform
30+
31+ if oneapi or (
32+ c_compiler is None and cxx_compiler is None and compiler_root is None
33+ ):
34+ return "icx" , ("icpx" if is_linux else "icx" )
35+
36+ if (
37+ (c_compiler is None or not os .path .isabs (c_compiler ))
38+ and (cxx_compiler is None or not os .path .isabs (cxx_compiler ))
39+ and (not compiler_root or not os .path .exists (compiler_root ))
40+ ):
41+ raise RuntimeError (
42+ "--compiler-root option must be set when using non-default DPC++ "
43+ "layout unless absolute paths are provided for both compilers"
44+ )
45+
46+ # default values
47+ if c_compiler is None :
48+ c_compiler = "icx"
49+ if cxx_compiler is None :
50+ cxx_compiler = "icpx" if is_linux else "icx"
51+
52+ for name , opt_name in (
53+ (c_compiler , "--c-compiler" ),
54+ (cxx_compiler , "--cxx-compiler" ),
55+ ):
56+ if os .path .isabs (name ):
57+ path = name
58+ else :
59+ path = os .path .join (compiler_root , name )
60+ if not os .path .exists (path ):
61+ raise RuntimeError (f"{ opt_name } value { name } not found" )
62+ return c_compiler , cxx_compiler
63+
64+
65+ def run (cmd : list [str ], env : dict [str , str ] = None , cwd : str = None ):
2466 print ("+" , " " .join (cmd ))
2567 subprocess .check_call (
2668 cmd , env = env or os .environ .copy (), cwd = cwd or os .getcwd ()
2769 )
2870
2971
72+ def get_output (cmd : list [str ], cwd : str = None ):
73+ print ("+" , " " .join (cmd ))
74+ return (
75+ subprocess .check_output (cmd , cwd = cwd or os .getcwd ())
76+ .decode ("utf-8" )
77+ .strip ("\n " )
78+ )
79+
80+
3081def warn (msg : str , script : str ):
3182 print (f"[{ script } ][warning] { msg } " , file = sys .stderr )
3283
@@ -36,12 +87,12 @@ def err(msg: str, script: str):
3687
3788
3889def make_cmake_args (
39- c_compiler = None ,
40- cxx_compiler = None ,
41- level_zero = True ,
42- glog = False ,
43- verbose = False ,
44- other_opts = "" ,
90+ c_compiler : str = None ,
91+ cxx_compiler : str = None ,
92+ level_zero : bool = True ,
93+ glog : bool = False ,
94+ verbose : bool = False ,
95+ other_opts : str = None ,
4596):
4697 args = [
4798 f"-DCMAKE_C_COMPILER:PATH={ c_compiler } " if c_compiler else "" ,
@@ -59,7 +110,11 @@ def make_cmake_args(
59110
60111
61112def build_extension (
62- setup_dir , env , cmake_executable = None , generator = None , build_type = None
113+ setup_dir : str ,
114+ env : dict [str , str ],
115+ cmake_executable : str = None ,
116+ generator : str = None ,
117+ build_type : str = None ,
63118):
64119 cmd = [sys .executable , "setup.py" , "build_ext" , "--inplace" ]
65120 if cmake_executable :
@@ -75,7 +130,7 @@ def build_extension(
75130 )
76131
77132
78- def install_editable (setup_dir , env ):
133+ def install_editable (setup_dir : str , env : dict [ str , str ] ):
79134 run (
80135 [
81136 sys .executable ,
@@ -91,7 +146,7 @@ def install_editable(setup_dir, env):
91146 )
92147
93148
94- def clean_build_dir (setup_dir ):
149+ def clean_build_dir (setup_dir : str = None ):
95150 target = os .path .join (setup_dir or os .getcwd (), "_skbuild" )
96151 if os .path .exists (target ):
97152 print (f"Cleaning build directory: { target } " )
0 commit comments