Skip to content

Commit

Permalink
Force Clang modules with LLVM >= 14 (#337)
Browse files Browse the repository at this point in the history
Otherwise Clang defaults to C++ modules with `-std=c++20`, which breaks
`layering_check`.

Fixes #334
  • Loading branch information
fmeum authored Jun 6, 2024
1 parent 1f6b2f1 commit b193952
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion toolchain/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def cc_toolchain_config(
tools_path_prefix,
wrapper_bin_prefix,
compiler_configuration,
cxx_builtin_include_directories):
cxx_builtin_include_directories,
major_llvm_version):
exec_os_arch_key = _os_arch_pair(exec_os, exec_arch)
target_os_arch_key = _os_arch_pair(target_os, target_arch)
_check_os_arch_keys([exec_os_arch_key, target_os_arch_key])
Expand Down Expand Up @@ -189,6 +190,15 @@ def cc_toolchain_config(
"-std=" + cxx_standard,
"-stdlib=libc++",
]
if major_llvm_version >= 14:
# With C++20, Clang defaults to using C++ rather than Clang modules,
# which breaks Bazel's `use_module_maps` feature, which is used by
# `layering_check`. Since Bazel doesn't support C++ modules yet, it
# is safe to disable them globally until the toolchain shipped by
# Bazel sets this flag on `use_module_maps`.
# https://github.com/llvm/llvm-project/commit/0556138624edf48621dd49a463dbe12e7101f17d
cxx_flags.append("-Xclang")
cxx_flags.append("-fno-cxx-modules")
if use_lld:
# For single-platform builds, we can statically link the bundled
# libraries.
Expand Down
2 changes: 2 additions & 0 deletions toolchain/internal/configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ cc_toolchain_config(
"unfiltered_compile_flags": {unfiltered_compile_flags},
}},
cxx_builtin_include_directories = {cxx_builtin_include_directories},
major_llvm_version = {major_llvm_version},
)
toolchain(
Expand Down Expand Up @@ -541,6 +542,7 @@ cc_toolchain(
if _is_hermetic_or_exists(rctx, dir, sysroot_path)
]),
extra_compiler_files = ("\"%s\"," % str(toolchain_info.extra_compiler_files)) if toolchain_info.extra_compiler_files else "",
major_llvm_version = major_llvm_version,
)

def _convenience_targets_str(rctx, use_absolute_paths, llvm_dist_rel_path, llvm_dist_label_prefix, exec_dl_ext):
Expand Down

0 comments on commit b193952

Please sign in to comment.