When using find_cpp_toolchain, make sure the relevant attribute, '_cc_toolchain' exists on the ctx being passed to this function. (I broke TAP once because I forgot to add the attribute. Perhaps not that helpful this late in the migration but doesn't hurt.) RELNOTES: None. PiperOrigin-RevId: 203947282
diff --git a/tools/cpp/toolchain_utils.bzl b/tools/cpp/toolchain_utils.bzl index e879299..be6f665 100644 --- a/tools/cpp/toolchain_utils.bzl +++ b/tools/cpp/toolchain_utils.bzl
@@ -33,6 +33,8 @@ Returns: A CcToolchainProvider. """ + if not hasattr(ctx.attr, "_cc_toolchain"): + fail("In order to use find_cpp_toolchain, you must define the '_cc_toolchain' attribute on your rule or aspect.") if Label("@bazel_tools//tools/cpp:toolchain_type") in ctx.fragments.platform.enabled_toolchain_types: return ctx.toolchains["@bazel_tools//tools/cpp:toolchain_type"]