Skip to content

Commit 942ddda

Browse files
fmeumcopybara-github
authored andcommitted
Prepare backwards compatible usage of optional C++ toolchain
By adding an alias and a no-op keyword argument now, rulesets can start using the new optional form of `find_cpp_toolchain` now and benefit from the toolchain actually being optional once that has been implemented in a future version of Bazel. Work towards bazelbuild#16966 Closes bazelbuild#17308. PiperOrigin-RevId: 504501621 Change-Id: I549fea6290195aadad4ccbd045c0aa3c180946d2
1 parent c162166 commit 942ddda

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

tools/cpp/BUILD.tools

+8
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ constraint_value(
5757

5858
cc_toolchain_alias(name = "current_cc_toolchain")
5959

60+
# In future versions of Bazel, this target will not fail if no C++ toolchain is
61+
# available. Instead, it will not advertise the cc_common.CcToolchainInfo
62+
# provider.
63+
alias(
64+
name = "optional_current_cc_toolchain",
65+
actual = ":current_cc_toolchain",
66+
)
67+
6068
cc_host_toolchain_alias(name = "current_cc_host_toolchain")
6169

6270
cc_libc_top_alias(name = "current_libc_top")

tools/cpp/toolchain_utils.bzl

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Utilities to help work with c++ toolchains.
1919

2020
CPP_TOOLCHAIN_TYPE = "@bazel_tools//tools/cpp:toolchain_type"
2121

22-
def find_cpp_toolchain(ctx):
22+
def find_cpp_toolchain(ctx, *, mandatory = True):
2323
"""
2424
Finds the c++ toolchain.
2525
@@ -29,6 +29,9 @@ def find_cpp_toolchain(ctx):
2929
3030
Args:
3131
ctx: The rule context for which to find a toolchain.
32+
mandatory: This is currently a no-op. In future releases of Bazel, if this
33+
is set to False, this function will return None rather than fail if no
34+
toolchain is found.
3235
3336
Returns:
3437
A CcToolchainProvider.

0 commit comments

Comments
 (0)