1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+ load ("@bazel_features//:features.bzl" , "bazel_features" )
1516load ("@bazel_skylib//lib:paths.bzl" , "paths" )
1617load (
1718 "//toolchain:aliases.bzl" ,
@@ -76,11 +77,11 @@ def llvm_config_impl(rctx):
7677 if not rctx .attr .toolchain_roots :
7778 toolchain_root = ("@" if BZLMOD_ENABLED else "" ) + "@%s_llvm//" % rctx .attr .name
7879 else :
79- ( _key , toolchain_root ) = _exec_os_arch_dict_value (rctx , "toolchain_roots" )
80+ _ , toolchain_root = _exec_os_arch_dict_value (rctx , "toolchain_roots" )
8081
8182 if not toolchain_root :
8283 fail ("LLVM toolchain root missing for ({}, {})" .format (os , arch ))
83- ( _key , llvm_version ) = _exec_os_arch_dict_value (rctx , "llvm_versions" )
84+ _ , llvm_version = _exec_os_arch_dict_value (rctx , "llvm_versions" )
8485 if is_requirement (llvm_version ):
8586 llvm_version , distribution , error = required_llvm_release_name_rctx (rctx , llvm_version )
8687 if error :
@@ -231,7 +232,7 @@ def llvm_config_impl(rctx):
231232 "%{cc_toolchain_config_bzl}" : str (rctx .attr ._cc_toolchain_config_bzl ),
232233 "%{cc_toolchains}" : cc_toolchains_str ,
233234 "%{symlinked_tools}" : symlinked_tools_str ,
234- "%{wrapper_bin_prefix }" : wrapper_bin_prefix ,
235+ "%{tools_dir }" : wrapper_bin_prefix . removesuffix ( "/" ) ,
235236 "%{convenience_targets}" : convenience_targets_str ,
236237 },
237238 )
@@ -335,7 +336,7 @@ def _cc_toolchain_str(
335336 # TODO: Are there other situations where we can continue?
336337 return ""
337338
338- extra_files_str = " \" :internal-use-files \" "
339+ extra_files_str = repr ( " :internal-use-tools" if bazel_features . rules . merkle_cache_v2 else ":internal-use-tools-legacy" )
339340
340341 # C++ built-in include directories.
341342 # This contains both the includes shipped with the compiler as well as the sysroot (or host)
@@ -360,17 +361,24 @@ def _cc_toolchain_str(
360361 "wasip1-wasm32" : "wasm32-wasip1" ,
361362 "wasip1-wasm64" : "wasm64-wasip1" ,
362363 }[target_pair ]
364+
363365 cxx_builtin_include_directories = [
364366 toolchain_path_prefix + "include/c++/v1" ,
367+ toolchain_path_prefix + "lib/clang/{}/include" .format (
368+ major_llvm_version if major_llvm_version >= 16 else llvm_version ,
369+ ),
370+ # Note(zbarsky): We could avoid this path if we renamed `include/{target_system_name}/c++/v1/__config_site` to `include/c++/v1/__config_site` in the LLVM repo.
371+ # However, that would preclude sharing it across multiple toolchain definitions.
365372 toolchain_path_prefix + "include/{}/c++/v1" .format (target_system_name ),
366- toolchain_path_prefix + "lib/clang/{}/include" .format (llvm_version ),
367- toolchain_path_prefix + "lib/clang/{}/share" .format (llvm_version ),
368- toolchain_path_prefix + "lib64/clang/{}/include" .format (llvm_version ),
369- toolchain_path_prefix + "lib/clang/{}/include" .format (major_llvm_version ),
370- toolchain_path_prefix + "lib/clang/{}/share" .format (major_llvm_version ),
371- toolchain_path_prefix + "lib64/clang/{}/include" .format (major_llvm_version ),
372373 ]
373374
375+ # TODO(zbarsky): Not sure if these lib64 paths are actually needed for system toolchains?
376+ if use_absolute_paths_llvm :
377+ cxx_builtin_include_directories .extend ([
378+ toolchain_path_prefix + "lib64/clang/{}/include" .format (llvm_version ),
379+ toolchain_path_prefix + "lib64/clang/{}/include" .format (major_llvm_version ),
380+ ])
381+
374382 sysroot_prefix = ""
375383 if sysroot_path :
376384 sysroot_prefix = "%sysroot%"
@@ -505,17 +513,16 @@ filegroup(name = "strip-files-{suffix}", srcs = [{extra_files_str}])
505513 template = template + """
506514filegroup(
507515 name = "cxx_builtin_include_files-{suffix}",
508- srcs = [
509- "{llvm_dist_label_prefix}clang",
510- "{llvm_dist_label_prefix}include",
511- ],
516+ srcs = ["{llvm_dist_label_prefix}{cxx_builtin_include_label}"],
512517)
513518
514519filegroup(
515520 name = "compiler-components-{suffix}",
516521 srcs = [
517522 ":cxx_builtin_include_files-{suffix}",
518523 ":sysroot-components-{suffix}",
524+ "{llvm_dist_label_prefix}extra_config_site",
525+ "{llvm_dist_label_prefix}clang",
519526 {extra_compiler_files}
520527 ],
521528)
@@ -526,7 +533,7 @@ filegroup(
526533 "{llvm_dist_label_prefix}clang",
527534 "{llvm_dist_label_prefix}ld",
528535 "{llvm_dist_label_prefix}ar",
529- "{llvm_dist_label_prefix}lib ",
536+ "{llvm_dist_label_prefix}{lib_label} ",
530537 ":sysroot-components-{suffix}",
531538 ],
532539)
@@ -629,6 +636,8 @@ cc_toolchain(
629636 extra_unfiltered_compile_flags = _list_to_string (_dict_value (toolchain_info .extra_unfiltered_compile_flags_dict , target_pair )),
630637 extra_files_str = extra_files_str ,
631638 cxx_builtin_include_directories = _list_to_string (filtered_cxx_builtin_include_directories ),
639+ cxx_builtin_include_label = "cxx_builtin_include" if bazel_features .rules .merkle_cache_v2 else "include" ,
640+ lib_label = "lib" if bazel_features .rules .merkle_cache_v2 else "lib_legacy" ,
632641 extra_compiler_files = ("\" %s\" ," % str (toolchain_info .extra_compiler_files )) if toolchain_info .extra_compiler_files else "" ,
633642 major_llvm_version = major_llvm_version ,
634643 extra_exec_compatible_with_specific = toolchain_info .extra_exec_compatible_with .get (target_pair , []),
0 commit comments