@@ -19,7 +19,7 @@ load(":toolchain_types.bzl", "UV_TOOLCHAIN_TYPE")
1919def toolchains_hub (
2020 * ,
2121 name = None ,
22- names ,
22+ toolchains ,
2323 implementations ,
2424 target_compatible_with ,
2525 target_settings ):
@@ -29,40 +29,38 @@ def toolchains_hub(
2929 TODO @aignas 2025-03-09: see if this can be reused in the python toolchains.
3030
3131 Args:
32- name: Unused.
33- names: The names for toolchain targets. The later occurring items take
34- precedence over the previous items if they match the target platform.
32+ name: The prefix to all of the targets, which goes after a numeric prefix.
33+ toolchains: The toolchain names for the targets defined by this macro.
34+ The earlier occurring items take precedence over the later items if
35+ they match the target platform and target settings.
3536 implementations: The name to label mapping.
3637 target_compatible_with: The name to target_compatible_with list mapping.
3738 target_settings: The name to target_settings list mapping.
3839 """
39- if len (names ) != len (implementations ):
40+ if len (toolchains ) != len (implementations ):
4041 fail ("Each name must have an implementation" )
4142
42- # We are setting the order of the toolchains so that the later coming
43- # toolchains override the previous definitions using the toolchain
44- # resolution properties:
43+ # We are defining the toolchains so that the order of toolchain matching is
44+ # the same as the order of the toolchains, because:
4545 # * the toolchains are matched by target settings and target_compatible_with
4646 # * the first toolchain satisfying the above wins
4747 #
4848 # this means we need to register the toolchains prefixed with a number of
4949 # format 00xy, where x and y are some digits and the leading zeros to
5050 # ensure lexicographical sorting.
51- prefix_len = len (str (len (names )))
51+ #
52+ # Add 1 so that there is always a leading zero
53+ prefix_len = len (str (len (toolchains ))) + 1
5254 prefix = "0" * (prefix_len - 1 )
5355
54- # reverse the names list so that the later items override earlier toolchain
55- # registrations.
56- names = [n for _ , n in sorted (enumerate (names ), key = lambda x : - x [0 ])]
57-
58- for i , name in enumerate (names ):
56+ for i , toolchain in enumerate (toolchains ):
5957 # prefix with a prefix and then truncate the string.
6058 number_prefix = "{}{}" .format (prefix , i )[- prefix_len :]
6159
6260 native .toolchain (
63- name = "{}_{}" .format (number_prefix , name ),
64- target_compatible_with = target_compatible_with .get (name , []),
65- target_settings = target_settings .get (name , []),
66- toolchain = implementations [name ],
61+ name = "{}_{}_{} " .format (number_prefix , name , toolchain ),
62+ target_compatible_with = target_compatible_with .get (toolchain , []),
63+ target_settings = target_settings .get (toolchain , []),
64+ toolchain = implementations [toolchain ],
6765 toolchain_type = UV_TOOLCHAIN_TYPE ,
6866 )
0 commit comments