Skip to content

Commit 646ae70

Browse files
authored
fix: Skip cxx_builtin_include_directories filtering when remote (#415)
It is not possible to determine directory existence remotely, so for remote execution the best option is not to filter. This PR addresses https://github.com/bazel-contrib/toolchains_llvm/pull/280/files/1a11e9f0f58f89789b5cd0a389efc7e321e33b3b#r1830121103
1 parent ab5557f commit 646ae70

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

toolchain/internal/common.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ def os(rctx):
115115
return name
116116
else:
117117
fail("Unsupported value for exec_os: %s" % name)
118+
return os_from_rctx(rctx)
118119

120+
def os_from_rctx(rctx):
119121
name = rctx.os.name
120122
if name == "linux":
121123
return "linux"
@@ -138,7 +140,9 @@ def arch(rctx):
138140
return "x86_64"
139141
else:
140142
fail("Unsupported value for exec_arch: %s" % arch)
143+
return arch_from_rctx(rctx)
141144

145+
def arch_from_rctx(rctx):
142146
arch = rctx.os.arch
143147
if arch == "arm64":
144148
return "aarch64"

toolchain/internal/configure.bzl

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ load(
2121
load(
2222
"//toolchain/internal:common.bzl",
2323
_arch = "arch",
24+
_arch_from_rctx = "arch_from_rctx",
2425
_canonical_dir_path = "canonical_dir_path",
2526
_check_os_arch_keys = "check_os_arch_keys",
2627
_exec_os_arch_dict_value = "exec_os_arch_dict_value",
@@ -30,6 +31,7 @@ load(
3031
_os = "os",
3132
_os_arch_pair = "os_arch_pair",
3233
_os_bzl = "os_bzl",
34+
_os_from_rctx = "os_from_rctx",
3335
_pkg_path_from_label = "pkg_path_from_label",
3436
_supported_targets = "SUPPORTED_TARGETS",
3537
_toolchain_tools = "toolchain_tools",
@@ -518,6 +520,16 @@ cc_toolchain(
518520
)
519521
"""
520522

523+
# Filter out non-existing directories with absolute paths as they
524+
# result in a -Wincomplete-umbrella warning when mentioned in the
525+
# system module map. Note that this filtering is skipped for remote
526+
# execution because it is not possible to check directory existence.
527+
filtered_cxx_builtin_include_directories = cxx_builtin_include_directories if _is_remote(rctx, exec_os, exec_arch) else [
528+
dir
529+
for dir in cxx_builtin_include_directories
530+
if _is_hermetic_or_exists(rctx, dir, sysroot_path)
531+
]
532+
521533
return template.format(
522534
suffix = suffix,
523535
target_os = target_os,
@@ -548,14 +560,7 @@ cc_toolchain(
548560
coverage_link_flags = _list_to_string(_dict_value(toolchain_info.coverage_link_flags_dict, target_pair)),
549561
unfiltered_compile_flags = _list_to_string(_dict_value(toolchain_info.unfiltered_compile_flags_dict, target_pair)),
550562
extra_files_str = extra_files_str,
551-
cxx_builtin_include_directories = _list_to_string([
552-
# Filter out non-existing directories with absolute paths as they
553-
# result in a -Wincomplete-umbrella warning when mentioned in the
554-
# system module map.
555-
dir
556-
for dir in cxx_builtin_include_directories
557-
if _is_hermetic_or_exists(rctx, dir, sysroot_path)
558-
]),
563+
cxx_builtin_include_directories = _list_to_string(filtered_cxx_builtin_include_directories),
559564
extra_compiler_files = ("\"%s\"," % str(toolchain_info.extra_compiler_files)) if toolchain_info.extra_compiler_files else "",
560565
major_llvm_version = major_llvm_version,
561566
extra_exec_compatible_with_specific = toolchain_info.extra_exec_compatible_with.get(target_pair, []),
@@ -564,6 +569,9 @@ cc_toolchain(
564569
extra_target_compatible_with_all_targets = toolchain_info.extra_target_compatible_with.get("", []),
565570
)
566571

572+
def _is_remote(rctx, exec_os, exec_arch):
573+
return not (_os_from_rctx(rctx) == exec_os and _arch_from_rctx(rctx) == exec_arch)
574+
567575
def _convenience_targets_str(rctx, use_absolute_paths, llvm_dist_rel_path, llvm_dist_label_prefix, exec_dl_ext):
568576
if use_absolute_paths:
569577
llvm_dist_label_prefix = ":"

0 commit comments

Comments
 (0)