Skip to content

Commit 8c94e11

Browse files
katrecopybara-github
authored andcommitted
Automatic code cleanup.
PiperOrigin-RevId: 707385492 Change-Id: I250093f03bf21ed2f009ac6be9e9e2252b4f0021
1 parent cc91cae commit 8c94e11

File tree

6 files changed

+15
-18
lines changed

6 files changed

+15
-18
lines changed

cc/find_cc_toolchain.bzl

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ Bazel version is not needed), it's enough to only keep the toolchain type.
5555

5656
CC_TOOLCHAIN_TYPE = Label("@bazel_tools//tools/cpp:toolchain_type")
5757

58+
CC_TOOLCHAIN_ATTRS = {
59+
# Needed for Bazel 6.x and 7.x compatibility.
60+
"_cc_toolchain": attr.label(default = Label("@rules_cc//cc:current_cc_toolchain")),
61+
}
62+
5863
def find_cc_toolchain(ctx, *, mandatory = True):
5964
"""
6065
Returns the current `CcToolchainInfo`.

cc/toolchains/cc_flags_supplier.bzl

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"""Rule that provides the CC_FLAGS Make variable."""
1515

1616
load("//cc:action_names.bzl", "CC_FLAGS_MAKE_VARIABLE_ACTION_NAME")
17-
load("//cc:find_cc_toolchain.bzl", "find_cpp_toolchain", "use_cc_toolchain")
17+
load("//cc:find_cc_toolchain.bzl", "CC_TOOLCHAIN_ATTRS", "find_cpp_toolchain", "use_cc_toolchain")
1818
load("//cc/private/rules_impl:cc_flags_supplier_lib.bzl", "build_cc_flags")
1919

2020
def _cc_flags_supplier_impl(ctx):
@@ -27,9 +27,7 @@ def _cc_flags_supplier_impl(ctx):
2727

2828
cc_flags_supplier = rule(
2929
implementation = _cc_flags_supplier_impl,
30-
attrs = {
31-
"_cc_toolchain": attr.label(default = Label("@rules_cc//cc:current_cc_toolchain")),
32-
},
30+
attrs = CC_TOOLCHAIN_ATTRS,
3331
toolchains = use_cc_toolchain(),
3432
fragments = ["cpp"],
3533
)

cc/toolchains/compiler_flag.bzl

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@
1414

1515
"""Rule that allows select() to differentiate between compilers."""
1616

17-
load("//cc:find_cc_toolchain.bzl", "find_cpp_toolchain", "use_cc_toolchain")
17+
load("//cc:find_cc_toolchain.bzl", "CC_TOOLCHAIN_ATTRS", "find_cpp_toolchain", "use_cc_toolchain")
1818

1919
def _compiler_flag_impl(ctx):
2020
toolchain = find_cpp_toolchain(ctx)
2121
return [config_common.FeatureFlagInfo(value = toolchain.compiler)]
2222

2323
compiler_flag = rule(
2424
implementation = _compiler_flag_impl,
25-
attrs = {
26-
"_cc_toolchain": attr.label(default = Label("@rules_cc//cc:current_cc_toolchain")),
27-
},
25+
attrs = CC_TOOLCHAIN_ATTRS,
2826
toolchains = use_cc_toolchain(),
2927
)

examples/my_c_archive/my_c_archive.bzl

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""Example showing how to create a rule that rules_cc can depend on."""
1616

1717
load("@rules_cc//cc:action_names.bzl", "CPP_LINK_STATIC_LIBRARY_ACTION_NAME")
18-
load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cpp_toolchain", "use_cc_toolchain")
18+
load("@rules_cc//cc:find_cc_toolchain.bzl", "CC_TOOLCHAIN_ATTRS", "find_cpp_toolchain", "use_cc_toolchain")
1919
load("//examples/my_c_compile:my_c_compile.bzl", "MyCCompileInfo")
2020

2121
def _my_c_archive_impl(ctx):
@@ -92,8 +92,7 @@ my_c_archive = rule(
9292
attrs = {
9393
"deps": attr.label_list(providers = [CcInfo]),
9494
"object": attr.label(mandatory = True, providers = [MyCCompileInfo]),
95-
"_cc_toolchain": attr.label(default = Label("@rules_cc//cc:current_cc_toolchain")),
96-
},
95+
} | CC_TOOLCHAIN_ATTRS,
9796
fragments = ["cpp"],
9897
toolchains = use_cc_toolchain(),
9998
)

examples/my_c_compile/my_c_compile.bzl

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""Example showing how to create a rule that just compiles C sources."""
1616

1717
load("@rules_cc//cc:action_names.bzl", "C_COMPILE_ACTION_NAME")
18-
load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cpp_toolchain", "use_cc_toolchain")
18+
load("@rules_cc//cc:find_cc_toolchain.bzl", "CC_TOOLCHAIN_ATTRS", "find_cpp_toolchain", "use_cc_toolchain")
1919

2020
MyCCompileInfo = provider(doc = "", fields = ["object"])
2121

@@ -74,8 +74,7 @@ my_c_compile = rule(
7474
implementation = _my_c_compile_impl,
7575
attrs = {
7676
"src": attr.label(mandatory = True, allow_single_file = True),
77-
"_cc_toolchain": attr.label(default = Label("@rules_cc//cc:current_cc_toolchain")),
78-
},
77+
} | CC_TOOLCHAIN_ATTRS,
7978
toolchains = use_cc_toolchain(),
8079
fragments = ["cpp"],
8180
)

examples/write_cc_toolchain_cpu/write_cc_toolchain_cpu.bzl

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
"""Example showing how to get CcToolchainInfo in a custom rule."""
1616

17-
load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cpp_toolchain", "use_cc_toolchain")
17+
load("@rules_cc//cc:find_cc_toolchain.bzl", "CC_TOOLCHAIN_ATTRS", "find_cpp_toolchain", "use_cc_toolchain")
1818

1919
def _write_cc_toolchain_cpu_impl(ctx):
2020
cc_toolchain = find_cpp_toolchain(ctx)
@@ -25,8 +25,6 @@ def _write_cc_toolchain_cpu_impl(ctx):
2525
# This rule does nothing, just writes the target_cpu from the cc_toolchain used for this build.
2626
write_cc_toolchain_cpu = rule(
2727
implementation = _write_cc_toolchain_cpu_impl,
28-
attrs = {
29-
"_cc_toolchain": attr.label(default = Label("@rules_cc//cc:current_cc_toolchain")),
30-
},
28+
attrs = CC_TOOLCHAIN_ATTRS,
3129
toolchains = use_cc_toolchain(),
3230
)

0 commit comments

Comments
 (0)