Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clippy: make Cc/Rust toolchains optional #2766

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions rust/private/clippy.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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, linkstamps = collect_deps(
deps = crate_info.deps,
Expand Down Expand Up @@ -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." +
Expand Down Expand Up @@ -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 = """\
Expand Down
7 changes: 5 additions & 2 deletions rust/private/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,19 @@ def find_toolchain(ctx):
"""
return ctx.toolchains[Label("//rust:toolchain_type")]

def find_cc_toolchain(ctx):
def find_cc_toolchain(ctx, mandatory = True):
"""Extracts a CcToolchain from the current target's context

Args:
ctx (ctx): The current target's rule context object
mandatory: If the CcToolchain is mandatory

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,
Expand Down
Loading