2222 _arch = "arch" ,
2323 _canonical_dir_path = "canonical_dir_path" ,
2424 _check_os_arch_keys = "check_os_arch_keys" ,
25- _host_os_arch_dict_value = "host_os_arch_dict_value" ,
26- _host_tools = "host_tools" ,
25+ _exec_os_arch_dict_value = "exec_os_arch_dict_value" ,
2726 _is_absolute_path = "is_absolute_path" ,
2827 _list_to_string = "list_to_string" ,
2928 _os = "os" ,
@@ -63,11 +62,11 @@ def llvm_config_impl(rctx):
6362 if not rctx .attr .toolchain_roots :
6463 toolchain_root = ("@" if BZLMOD_ENABLED else "" ) + "@%s_llvm//" % rctx .attr .name
6564 else :
66- (_key , toolchain_root ) = _host_os_arch_dict_value (rctx , "toolchain_roots" )
65+ (_key , toolchain_root ) = _exec_os_arch_dict_value (rctx , "toolchain_roots" )
6766
6867 if not toolchain_root :
6968 fail ("LLVM toolchain root missing for ({}, {})" .format (os , arch ))
70- (_key , llvm_version ) = _host_os_arch_dict_value (rctx , "llvm_versions" )
69+ (_key , llvm_version ) = _exec_os_arch_dict_value (rctx , "llvm_versions" )
7170 if not llvm_version :
7271 # LLVM version missing for (os, arch)
7372 _empty_repository (rctx )
@@ -161,30 +160,20 @@ def llvm_config_impl(rctx):
161160 llvm_version = llvm_version ,
162161 extra_compiler_files = rctx .attr .extra_compiler_files ,
163162 )
164- host_dl_ext = "dylib" if os == "darwin" else "so"
165- host_tools_info = dict ([
166- pair
167- for (key , tool_path ) in [
168- # This is used when lld doesn't support the target platform (i.e.
169- # Mach-O for macOS):
170- ("ld" , "/usr/bin/ld" ),
171- ]
172- for pair in _host_tools .get_tool_info (rctx , tool_path , key ).items ()
173- ])
163+ exec_dl_ext = "dylib" if os == "darwin" else "so"
174164 cc_toolchains_str , toolchain_labels_str = _cc_toolchains_str (
175165 rctx ,
176166 workspace_name ,
177167 toolchain_info ,
178168 use_absolute_paths_llvm ,
179- host_tools_info ,
180169 )
181170
182171 convenience_targets_str = _convenience_targets_str (
183172 rctx ,
184173 use_absolute_paths_llvm ,
185174 llvm_dist_rel_path ,
186175 llvm_dist_label_prefix ,
187- host_dl_ext ,
176+ exec_dl_ext ,
188177 )
189178
190179 # Convenience macro to register all generated toolchains.
@@ -226,8 +215,7 @@ def _cc_toolchains_str(
226215 rctx ,
227216 workspace_name ,
228217 toolchain_info ,
229- use_absolute_paths_llvm ,
230- host_tools_info ):
218+ use_absolute_paths_llvm ):
231219 # Since all the toolchains rely on downloading the right LLVM toolchain for
232220 # the host architecture, we don't need to explicitly specify
233221 # `exec_compatible_with` attribute. If the host and execution platform are
@@ -252,7 +240,6 @@ def _cc_toolchains_str(
252240 target_arch ,
253241 toolchain_info ,
254242 use_absolute_paths_llvm ,
255- host_tools_info ,
256243 )
257244 if cc_toolchain_str :
258245 cc_toolchains_str = cc_toolchains_str + cc_toolchain_str
@@ -275,12 +262,11 @@ def _cc_toolchain_str(
275262 target_os ,
276263 target_arch ,
277264 toolchain_info ,
278- use_absolute_paths_llvm ,
279- host_tools_info ):
280- host_os = toolchain_info .os
281- host_arch = toolchain_info .arch
265+ use_absolute_paths_llvm ):
266+ exec_os = toolchain_info .os
267+ exec_arch = toolchain_info .arch
282268
283- host_os_bzl = _os_bzl (host_os )
269+ exec_os_bzl = _os_bzl (exec_os )
284270 target_os_bzl = _os_bzl (target_os )
285271
286272 target_pair = _os_arch_pair (target_os , target_arch )
@@ -293,20 +279,16 @@ def _cc_toolchain_str(
293279 sysroot_label_str = ""
294280
295281 if not sysroot_path :
296- if host_os == target_os and host_arch == target_arch :
282+ if exec_os == target_os and exec_arch == target_arch :
297283 # For darwin -> darwin, we can use the macOS SDK path.
298- sysroot_path = _default_sysroot_path (rctx , host_os )
284+ sysroot_path = _default_sysroot_path (rctx , exec_os )
299285 else :
300286 # We are trying to cross-compile without a sysroot, let's bail.
301287 # TODO: Are there situations where we can continue?
302288 return ""
303289
304290 extra_files_str = "\" :internal-use-files\" "
305291
306- # `struct` isn't allowed in `BUILD` files so we JSON encode + decode to turn
307- # them into `dict`s.
308- host_tools_info = json .decode (json .encode (host_tools_info ))
309-
310292 # C++ built-in include directories.
311293 # This contains both the includes shipped with the compiler as well as the sysroot (or host)
312294 # include directories. While Bazel's default undeclared inclusions check does not seem to be
@@ -358,8 +340,8 @@ def _cc_toolchain_str(
358340
359341cc_toolchain_config(
360342 name = "local-{suffix}",
361- host_arch = "{host_arch }",
362- host_os = "{host_os }",
343+ exec_arch = "{exec_arch }",
344+ exec_os = "{exec_os }",
363345 target_arch = "{target_arch}",
364346 target_os = "{target_os}",
365347 target_system_name = "{target_system_name}",
@@ -382,15 +364,14 @@ cc_toolchain_config(
382364 "coverage_link_flags": {coverage_link_flags},
383365 "unfiltered_compile_flags": {unfiltered_compile_flags},
384366 }},
385- host_tools_info = {host_tools_info},
386367 cxx_builtin_include_directories = {cxx_builtin_include_directories},
387368)
388369
389370toolchain(
390371 name = "cc-toolchain-{suffix}",
391372 exec_compatible_with = [
392- "@platforms//cpu:{host_arch }",
393- "@platforms//os:{host_os_bzl }",
373+ "@platforms//cpu:{exec_arch }",
374+ "@platforms//os:{exec_os_bzl }",
394375 ],
395376 target_compatible_with = [
396377 "@platforms//cpu:{target_arch}",
@@ -518,12 +499,12 @@ cc_toolchain(
518499 suffix = suffix ,
519500 target_os = target_os ,
520501 target_arch = target_arch ,
521- host_os = host_os ,
522- host_arch = host_arch ,
502+ exec_os = exec_os ,
503+ exec_arch = exec_arch ,
523504 target_settings = _list_to_string (_dict_value (toolchain_info .target_settings_dict , target_pair )),
524505 target_os_bzl = target_os_bzl ,
525506 target_system_name = target_system_name ,
526- host_os_bzl = host_os_bzl ,
507+ exec_os_bzl = exec_os_bzl ,
527508 llvm_dist_label_prefix = toolchain_info .llvm_dist_label_prefix ,
528509 llvm_dist_path_prefix = toolchain_info .llvm_dist_path_prefix ,
529510 tools_path_prefix = toolchain_info .tools_path_prefix ,
@@ -544,7 +525,6 @@ cc_toolchain(
544525 coverage_link_flags = _list_to_string (_dict_value (toolchain_info .coverage_link_flags_dict , target_pair )),
545526 unfiltered_compile_flags = _list_to_string (_dict_value (toolchain_info .unfiltered_compile_flags_dict , target_pair )),
546527 extra_files_str = extra_files_str ,
547- host_tools_info = host_tools_info ,
548528 cxx_builtin_include_directories = _list_to_string ([
549529 # Filter out non-existing directories with absolute paths as they
550530 # result in a -Wincomplete-umbrella warning when mentioned in the
@@ -556,12 +536,12 @@ cc_toolchain(
556536 extra_compiler_files = ("\" %s\" ," % str (toolchain_info .extra_compiler_files )) if toolchain_info .extra_compiler_files else "" ,
557537 )
558538
559- def _convenience_targets_str (rctx , use_absolute_paths , llvm_dist_rel_path , llvm_dist_label_prefix , host_dl_ext ):
539+ def _convenience_targets_str (rctx , use_absolute_paths , llvm_dist_rel_path , llvm_dist_label_prefix , exec_dl_ext ):
560540 if use_absolute_paths :
561541 llvm_dist_label_prefix = ":"
562542 filenames = []
563543 for libname in _aliased_libs :
564- filename = "lib/{}.{}" .format (libname , host_dl_ext )
544+ filename = "lib/{}.{}" .format (libname , exec_dl_ext )
565545 filenames .append (filename )
566546 for toolname in _aliased_tools :
567547 filename = "bin/{}" .format (toolname )
@@ -575,7 +555,7 @@ def _convenience_targets_str(rctx, use_absolute_paths, llvm_dist_rel_path, llvm_
575555 template = """
576556cc_import(
577557 name = "{name}",
578- shared_library = "{{llvm_dist_label_prefix}}lib/lib{name}.{{host_dl_ext }}",
558+ shared_library = "{{llvm_dist_label_prefix}}lib/lib{name}.{{exec_dl_ext }}",
579559)""" .format (name = name )
580560 lib_target_strs .append (template )
581561
@@ -591,7 +571,7 @@ native_binary(
591571
592572 return "\n " .join (lib_target_strs + tool_target_strs ).format (
593573 llvm_dist_label_prefix = llvm_dist_label_prefix ,
594- host_dl_ext = host_dl_ext ,
574+ exec_dl_ext = exec_dl_ext ,
595575 )
596576
597577def _is_hermetic_or_exists (rctx , path , sysroot_prefix ):
0 commit comments