@@ -71,6 +71,10 @@ Returns the current `CcToolchainInfo`.
7171 if not CC_TOOLCHAIN_TYPE in ctx .toolchains :
7272 fail ("In order to use find_cc_toolchain, your rule has to depend on C++ toolchain. See find_cc_toolchain.bzl docs for details." )
7373 toolchain_info = ctx .toolchains [CC_TOOLCHAIN_TYPE ]
74+ if toolchain_info == None :
75+ # No cpp toolchain was found, so report an error.
76+ fail ("Unable to find a CC toolchain using toolchain resolution. Target: %s, Platform: %s, Exec platform: %s" %
77+ (ctx .label , ctx .fragments .platform .platform , ctx .fragments .platform .host_platform ))
7478 if hasattr (toolchain_info , "cc_provider_in_toolchain" ) and hasattr (toolchain_info , "cc" ):
7579 return toolchain_info .cc
7680 return toolchain_info
@@ -93,8 +97,7 @@ def find_cpp_toolchain(ctx):
9397 """
9498 return find_cc_toolchain (ctx )
9599
96- # buildifier: disable=unused-variable
97- def use_cc_toolchain (mandatory = True ):
100+ def use_cc_toolchain (mandatory = False ):
98101 """
99102 Helper to depend on the cc toolchain.
100103
@@ -107,9 +110,8 @@ def use_cc_toolchain(mandatory = True):
107110
108111 Args:
109112 mandatory: Whether or not it should be an error if the toolchain cannot be resolved.
110- Currently ignored, this will be enabled when optional toolchain types are added.
111113
112114 Returns:
113115 A list that can be used as the value for `rule.toolchains`.
114116 """
115- return [CC_TOOLCHAIN_TYPE ]
117+ return [config_common . toolchain_type ( CC_TOOLCHAIN_TYPE , mandatory = mandatory ) ]
0 commit comments