22
22
_arch = "arch" ,
23
23
_canonical_dir_path = "canonical_dir_path" ,
24
24
_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" ,
27
26
_is_absolute_path = "is_absolute_path" ,
28
27
_list_to_string = "list_to_string" ,
29
28
_os = "os" ,
@@ -63,11 +62,11 @@ def llvm_config_impl(rctx):
63
62
if not rctx .attr .toolchain_roots :
64
63
toolchain_root = ("@" if BZLMOD_ENABLED else "" ) + "@%s_llvm//" % rctx .attr .name
65
64
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" )
67
66
68
67
if not toolchain_root :
69
68
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" )
71
70
if not llvm_version :
72
71
# LLVM version missing for (os, arch)
73
72
_empty_repository (rctx )
@@ -161,30 +160,20 @@ def llvm_config_impl(rctx):
161
160
llvm_version = llvm_version ,
162
161
extra_compiler_files = rctx .attr .extra_compiler_files ,
163
162
)
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"
174
164
cc_toolchains_str , toolchain_labels_str = _cc_toolchains_str (
175
165
rctx ,
176
166
workspace_name ,
177
167
toolchain_info ,
178
168
use_absolute_paths_llvm ,
179
- host_tools_info ,
180
169
)
181
170
182
171
convenience_targets_str = _convenience_targets_str (
183
172
rctx ,
184
173
use_absolute_paths_llvm ,
185
174
llvm_dist_rel_path ,
186
175
llvm_dist_label_prefix ,
187
- host_dl_ext ,
176
+ exec_dl_ext ,
188
177
)
189
178
190
179
# Convenience macro to register all generated toolchains.
@@ -226,8 +215,7 @@ def _cc_toolchains_str(
226
215
rctx ,
227
216
workspace_name ,
228
217
toolchain_info ,
229
- use_absolute_paths_llvm ,
230
- host_tools_info ):
218
+ use_absolute_paths_llvm ):
231
219
# Since all the toolchains rely on downloading the right LLVM toolchain for
232
220
# the host architecture, we don't need to explicitly specify
233
221
# `exec_compatible_with` attribute. If the host and execution platform are
@@ -252,7 +240,6 @@ def _cc_toolchains_str(
252
240
target_arch ,
253
241
toolchain_info ,
254
242
use_absolute_paths_llvm ,
255
- host_tools_info ,
256
243
)
257
244
if cc_toolchain_str :
258
245
cc_toolchains_str = cc_toolchains_str + cc_toolchain_str
@@ -275,12 +262,11 @@ def _cc_toolchain_str(
275
262
target_os ,
276
263
target_arch ,
277
264
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
282
268
283
- host_os_bzl = _os_bzl (host_os )
269
+ exec_os_bzl = _os_bzl (exec_os )
284
270
target_os_bzl = _os_bzl (target_os )
285
271
286
272
target_pair = _os_arch_pair (target_os , target_arch )
@@ -293,20 +279,16 @@ def _cc_toolchain_str(
293
279
sysroot_label_str = ""
294
280
295
281
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 :
297
283
# 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 )
299
285
else :
300
286
# We are trying to cross-compile without a sysroot, let's bail.
301
287
# TODO: Are there situations where we can continue?
302
288
return ""
303
289
304
290
extra_files_str = "\" :internal-use-files\" "
305
291
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
-
310
292
# C++ built-in include directories.
311
293
# This contains both the includes shipped with the compiler as well as the sysroot (or host)
312
294
# include directories. While Bazel's default undeclared inclusions check does not seem to be
@@ -358,8 +340,8 @@ def _cc_toolchain_str(
358
340
359
341
cc_toolchain_config(
360
342
name = "local-{suffix}",
361
- host_arch = "{host_arch }",
362
- host_os = "{host_os }",
343
+ exec_arch = "{exec_arch }",
344
+ exec_os = "{exec_os }",
363
345
target_arch = "{target_arch}",
364
346
target_os = "{target_os}",
365
347
target_system_name = "{target_system_name}",
@@ -382,15 +364,14 @@ cc_toolchain_config(
382
364
"coverage_link_flags": {coverage_link_flags},
383
365
"unfiltered_compile_flags": {unfiltered_compile_flags},
384
366
}},
385
- host_tools_info = {host_tools_info},
386
367
cxx_builtin_include_directories = {cxx_builtin_include_directories},
387
368
)
388
369
389
370
toolchain(
390
371
name = "cc-toolchain-{suffix}",
391
372
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 }",
394
375
],
395
376
target_compatible_with = [
396
377
"@platforms//cpu:{target_arch}",
@@ -518,12 +499,12 @@ cc_toolchain(
518
499
suffix = suffix ,
519
500
target_os = target_os ,
520
501
target_arch = target_arch ,
521
- host_os = host_os ,
522
- host_arch = host_arch ,
502
+ exec_os = exec_os ,
503
+ exec_arch = exec_arch ,
523
504
target_settings = _list_to_string (_dict_value (toolchain_info .target_settings_dict , target_pair )),
524
505
target_os_bzl = target_os_bzl ,
525
506
target_system_name = target_system_name ,
526
- host_os_bzl = host_os_bzl ,
507
+ exec_os_bzl = exec_os_bzl ,
527
508
llvm_dist_label_prefix = toolchain_info .llvm_dist_label_prefix ,
528
509
llvm_dist_path_prefix = toolchain_info .llvm_dist_path_prefix ,
529
510
tools_path_prefix = toolchain_info .tools_path_prefix ,
@@ -544,7 +525,6 @@ cc_toolchain(
544
525
coverage_link_flags = _list_to_string (_dict_value (toolchain_info .coverage_link_flags_dict , target_pair )),
545
526
unfiltered_compile_flags = _list_to_string (_dict_value (toolchain_info .unfiltered_compile_flags_dict , target_pair )),
546
527
extra_files_str = extra_files_str ,
547
- host_tools_info = host_tools_info ,
548
528
cxx_builtin_include_directories = _list_to_string ([
549
529
# Filter out non-existing directories with absolute paths as they
550
530
# result in a -Wincomplete-umbrella warning when mentioned in the
@@ -556,12 +536,12 @@ cc_toolchain(
556
536
extra_compiler_files = ("\" %s\" ," % str (toolchain_info .extra_compiler_files )) if toolchain_info .extra_compiler_files else "" ,
557
537
)
558
538
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 ):
560
540
if use_absolute_paths :
561
541
llvm_dist_label_prefix = ":"
562
542
filenames = []
563
543
for libname in _aliased_libs :
564
- filename = "lib/{}.{}" .format (libname , host_dl_ext )
544
+ filename = "lib/{}.{}" .format (libname , exec_dl_ext )
565
545
filenames .append (filename )
566
546
for toolname in _aliased_tools :
567
547
filename = "bin/{}" .format (toolname )
@@ -575,7 +555,7 @@ def _convenience_targets_str(rctx, use_absolute_paths, llvm_dist_rel_path, llvm_
575
555
template = """
576
556
cc_import(
577
557
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 }}",
579
559
)""" .format (name = name )
580
560
lib_target_strs .append (template )
581
561
@@ -591,7 +571,7 @@ native_binary(
591
571
592
572
return "\n " .join (lib_target_strs + tool_target_strs ).format (
593
573
llvm_dist_label_prefix = llvm_dist_label_prefix ,
594
- host_dl_ext = host_dl_ext ,
574
+ exec_dl_ext = exec_dl_ext ,
595
575
)
596
576
597
577
def _is_hermetic_or_exists (rctx , path , sysroot_prefix ):
0 commit comments