diff --git a/rust/private/clippy.bzl b/rust/private/clippy.bzl index 9d5e6ddb69..9e7afec3b5 100644 --- a/rust/private/clippy.bzl +++ b/rust/private/clippy.bzl @@ -97,7 +97,10 @@ def _clippy_aspect_impl(target, ctx): return [ClippyInfo(output = depset([]))] toolchain = find_toolchain(ctx) - cc_toolchain, feature_configuration = find_cc_toolchain(ctx) + cc_toolchain, feature_configuration = find_cc_toolchain(ctx, mandatory = False) + + if toolchain == None or cc_toolchain == None: + return [ClippyInfo(output = depset([]))] dep_info, build_info, _ = collect_deps( deps = crate_info.deps, @@ -217,7 +220,7 @@ rust_clippy_aspect = aspect( "Required attribute to access the cc_toolchain. See [Accessing the C++ toolchain]" + "(https://docs.bazel.build/versions/master/integrating-with-rules-cc.html#accessing-the-c-toolchain)" ), - default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"), + default = Label("@bazel_tools//tools/cpp:optional_current_cc_toolchain"), ), "_clippy_flag": attr.label( doc = "Arguments to pass to clippy." + @@ -256,8 +259,8 @@ rust_clippy_aspect = aspect( [rust_common.test_crate_info], ], toolchains = [ - str(Label("//rust:toolchain_type")), - "@bazel_tools//tools/cpp:toolchain_type", + config_common.toolchain_type(str(Label("//rust:toolchain_type")), mandatory = False), + config_common.toolchain_type("@bazel_tools//tools/cpp:toolchain_type", mandatory = False), ], implementation = _clippy_aspect_impl, doc = """\ diff --git a/rust/private/utils.bzl b/rust/private/utils.bzl index a0fda352f5..5d3602bc58 100644 --- a/rust/private/utils.bzl +++ b/rust/private/utils.bzl @@ -41,17 +41,20 @@ def find_toolchain(ctx): """ return ctx.toolchains[Label("//rust:toolchain_type")] -def find_cc_toolchain(ctx, extra_unsupported_features = tuple()): +def find_cc_toolchain(ctx, mandatory = True, extra_unsupported_features = tuple()): """Extracts a CcToolchain from the current target's context Args: ctx (ctx): The current target's rule context object - extra_unsupported_features (sequence of str): Extra featrures to disable + mandatory: If the CcToolchain is mandatory + extra_unsupported_features (sequence of str): Extra features to disable Returns: tuple: A tuple of (CcToolchain, FeatureConfiguration) """ - cc_toolchain = find_rules_cc_toolchain(ctx) + cc_toolchain = find_rules_cc_toolchain(ctx, mandatory = mandatory) + if cc_toolchain == None: + return (None, None) feature_configuration = cc_common.configure_features( ctx = ctx,