Skip to content

Commit 16566f3

Browse files
authored
Fix variant toolchains (#1466)
In #1459, `extra_toolchain` was changed from a string to a Label. This was necessary (it's no longer safe to pass labels as strings in the post-bzlmod world) but it created a problem: the ability to do ``` cmake_variant(toolchain=select({"A": "footoolchain", "B": ""})) ``` kind of worked before, and no longer does (since "" is not a valid label). This change makes it so you can pass None instead of "" and it will do roughly what "" did.
1 parent 8e29469 commit 16566f3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

foreign_cc/private/transitions.bzl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ load("@rules_cc//cc:defs.bzl", "CcInfo")
44
load("//foreign_cc:providers.bzl", "ForeignCcDepsInfo")
55

66
def _extra_toolchains_transition_impl(settings, attrs):
7-
return {"//command_line_option:extra_toolchains": [attrs.extra_toolchain] + settings["//command_line_option:extra_toolchains"]}
7+
t = getattr(attrs, "extra_toolchain", None)
8+
if not t:
9+
return {}
10+
11+
return {"//command_line_option:extra_toolchains": [t] + settings["//command_line_option:extra_toolchains"]}
812

913
_extra_toolchains_transition = transition(
1014
implementation = _extra_toolchains_transition_impl,
@@ -29,7 +33,6 @@ extra_toolchains_transitioned_foreign_cc_target = rule(
2933
# This attr is singular to make it selectable when used for add make toolchain variant.
3034
"extra_toolchain": attr.label(
3135
doc = "Additional toolchain to consider. Note, this is singular.",
32-
mandatory = True,
3336
),
3437
"target": attr.label(
3538
doc = "The target to build after considering the extra toolchains",

0 commit comments

Comments
 (0)