Skip to content

Commit 268351f

Browse files
committed
resolve bin_llvm from default compiler layout when not provided
1 parent 4a3ab99 commit 268351f

File tree

3 files changed

+104
-52
lines changed

3 files changed

+104
-52
lines changed

scripts/_build_helper.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,40 +35,6 @@ def err(msg: str):
3535
print(f"[build_locally][error] {msg}", file=sys.stderr)
3636

3737

38-
def resolve_compilers(
39-
oneapi: bool, c_compiler: str, cxx_compiler: str, compiler_root: str
40-
):
41-
is_linux = "linux" in sys.platform
42-
43-
if oneapi or (
44-
c_compiler is None and cxx_compiler is None and compiler_root is None
45-
):
46-
return "icx", ("icpx" if is_linux else "icx")
47-
48-
if not compiler_root or not os.path.exists(compiler_root):
49-
raise RuntimeError(
50-
"--compiler-root option must be set when using non-default DPC++ "
51-
"layout"
52-
)
53-
54-
# default values
55-
if c_compiler is None:
56-
c_compiler = "icx"
57-
if cxx_compiler is None:
58-
cxx_compiler = "icpx" if is_linux else "icx"
59-
60-
for name, opt_name in (
61-
(c_compiler, "--c-compiler"),
62-
(cxx_compiler, "--cxx-compiler"),
63-
):
64-
path = (
65-
name if os.path.exists(name) else os.path.join(compiler_root, name)
66-
)
67-
if not os.path.exists(path):
68-
raise RuntimeError(f"{opt_name} value {name} not found")
69-
return c_compiler, cxx_compiler
70-
71-
7238
def make_cmake_args(
7339
c_compiler=None,
7440
cxx_compiler=None,

scripts/build_locally.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,44 @@
2727
err,
2828
install_editable,
2929
make_cmake_args,
30-
resolve_compilers,
3130
warn,
3231
)
3332

3433

34+
def resolve_compilers(
35+
oneapi: bool, c_compiler: str, cxx_compiler: str, compiler_root: str
36+
):
37+
is_linux = "linux" in sys.platform
38+
39+
if oneapi or (
40+
c_compiler is None and cxx_compiler is None and compiler_root is None
41+
):
42+
return "icx", ("icpx" if is_linux else "icx")
43+
44+
if not compiler_root or not os.path.exists(compiler_root):
45+
raise RuntimeError(
46+
"--compiler-root option must be set when using non-default DPC++ "
47+
"layout"
48+
)
49+
50+
# default values
51+
if c_compiler is None:
52+
c_compiler = "icx"
53+
if cxx_compiler is None:
54+
cxx_compiler = "icpx" if is_linux else "icx"
55+
56+
for name, opt_name in (
57+
(c_compiler, "--c-compiler"),
58+
(cxx_compiler, "--cxx-compiler"),
59+
):
60+
path = (
61+
name if os.path.exists(name) else os.path.join(compiler_root, name)
62+
)
63+
if not os.path.exists(path):
64+
raise RuntimeError(f"{opt_name} value {name} not found")
65+
return c_compiler, cxx_compiler
66+
67+
3568
def parse_args():
3669
p = argparse.ArgumentParser(description="Local dpctl build driver")
3770

scripts/gen_coverage.py

Lines changed: 70 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,68 @@
3030
err,
3131
install_editable,
3232
make_cmake_args,
33-
resolve_compilers,
3433
run,
3534
warn,
3635
)
3736

3837

38+
def find_bin_llvm(compiler_name):
39+
icx_path = subprocess.check_output(["which", compiler_name])
40+
bin_dir = os.path.dirname(icx_path)
41+
compiler_dir = os.path.join(bin_dir.decode("utf-8"), "compiler")
42+
if os.path.exists(compiler_dir):
43+
bin_llvm = compiler_dir
44+
else:
45+
bin_dir = os.path.dirname(bin_dir)
46+
bin_llvm = os.path.join(bin_dir.decode("utf-8"), "bin-llvm")
47+
assert os.path.exists(bin_llvm)
48+
return bin_llvm
49+
50+
51+
def resolve_compilers(
52+
oneapi: bool,
53+
c_compiler: str,
54+
cxx_compiler: str,
55+
compiler_root: str,
56+
bin_llvm: str = None,
57+
):
58+
is_linux = "linux" in sys.platform
59+
60+
if oneapi or (
61+
c_compiler is None
62+
and cxx_compiler is None
63+
and compiler_root is None
64+
and bin_llvm is None
65+
):
66+
return "icx", ("icpx" if is_linux else "icx"), find_bin_llvm("icx")
67+
68+
if not compiler_root or not os.path.exists(compiler_root):
69+
raise RuntimeError(
70+
"--compiler-root option must be set when using non-default DPC++ "
71+
"layout"
72+
)
73+
74+
# default values
75+
if c_compiler is None:
76+
c_compiler = "icx"
77+
if cxx_compiler is None:
78+
cxx_compiler = "icpx" if is_linux else "icx"
79+
if bin_llvm is None:
80+
bin_llvm = find_bin_llvm(c_compiler)
81+
82+
for name, opt_name in (
83+
(c_compiler, "--c-compiler"),
84+
(cxx_compiler, "--cxx-compiler"),
85+
(bin_llvm, "--bin-llvm"),
86+
):
87+
path = (
88+
name if os.path.exists(name) else os.path.join(compiler_root, name)
89+
)
90+
if not os.path.exists(path):
91+
raise RuntimeError(f"{opt_name} value {name} not found")
92+
return c_compiler, cxx_compiler, bin_llvm
93+
94+
3995
def parse_args():
4096
p = argparse.ArgumentParser(description="Build dpctl and generate coverage")
4197

@@ -140,8 +196,12 @@ def main():
140196
args = parse_args()
141197
setup_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
142198

143-
c_compiler, cxx_compiler = resolve_compilers(
144-
args.oneapi, args.c_compiler, args.cxx_compiler, args.compiler_root
199+
c_compiler, cxx_compiler, bin_llvm = resolve_compilers(
200+
args.oneapi,
201+
args.c_compiler,
202+
args.cxx_compiler,
203+
args.compiler_root,
204+
args.bin_llvm,
145205
)
146206

147207
if args.clean:
@@ -178,21 +238,14 @@ def main():
178238
warn("Ignoring pre-existing CMAKE_ARGS in environment")
179239
del env["CMAKE_ARGS"]
180240

181-
if args.bin_llvm:
182-
env["PATH"] = ":".join((env.get("PATH", ""), args.bin_llvm))
183-
env["LLVM_TOOLS_HOME"] = args.bin_llvm
184-
llvm_profdata = os.path.join(args.bin_llvm, "llvm-profdata")
185-
llvm_cov = os.path.join(args.bin_llvm, "llvm-cov")
186-
cmake_args += f" -DLLVM_TOOLS_HOME={args.bin_llvm}"
187-
cmake_args += f" -DLLVM_PROFDATA={llvm_profdata}"
188-
cmake_args += f" -DLLVM_COV={llvm_cov}"
189-
# Add LLVMCov_EXE for CMake find_package(LLVMCov)
190-
cmake_args += f" -DLLVMCov_EXE={llvm_cov}"
191-
192-
print(f"[gen_coverage] Using CMake args:\n {env['CMAKE_ARGS']}")
241+
if bin_llvm:
242+
env["PATH"] = ":".join((env.get("PATH", ""), bin_llvm))
243+
env["LLVM_TOOLS_HOME"] = bin_llvm
193244

194245
env["CMAKE_ARGS"] = cmake_args
195246

247+
print(f"[gen_coverage] Using CMake args:\n {env['CMAKE_ARGS']}")
248+
196249
build_extension(
197250
setup_dir,
198251
env,
@@ -242,7 +295,7 @@ def main():
242295

243296
run(
244297
[
245-
os.path.join(args.bin_llvm or "", "llvm-profdata"),
298+
os.path.join(bin_llvm, "llvm-profdata"),
246299
"merge",
247300
"-sparse",
248301
env["LLVM_PROFILE_FILE"],
@@ -254,7 +307,7 @@ def main():
254307
with open("dpctl_pytest.lcov", "w") as fh:
255308
subprocess.check_call(
256309
[
257-
os.path.join(args.bin_llvm or "", "llvm-cov"),
310+
os.path.join(bin_llvm, "llvm-cov"),
258311
"export",
259312
"-format=lcov",
260313
"-ignore-filename-regex=/tmp/icpx*",

0 commit comments

Comments
 (0)