Move examples from deprecated @rules_cc//cc:find_cpp_toolchain -> @bazel_tools//tools/cpp:toolchain_utils.bzl

This commit is contained in:
Christopher Peterson Sauer 2022-04-11 16:33:03 -07:00
parent ab8b67a0ab
commit e0dad88a07
5 changed files with 11 additions and 11 deletions

View File

@ -13,12 +13,12 @@
# limitations under the License. # limitations under the License.
"""Rule that provides the CC_FLAGS Make variable.""" """Rule that provides the CC_FLAGS Make variable."""
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load("//cc:action_names.bzl", "CC_FLAGS_MAKE_VARIABLE_ACTION_NAME") load("//cc:action_names.bzl", "CC_FLAGS_MAKE_VARIABLE_ACTION_NAME")
load("//cc:find_cc_toolchain.bzl", "find_cc_toolchain")
load("//cc/private/rules_impl:cc_flags_supplier_lib.bzl", "build_cc_flags") load("//cc/private/rules_impl:cc_flags_supplier_lib.bzl", "build_cc_flags")
def _cc_flags_supplier_impl(ctx): def _cc_flags_supplier_impl(ctx):
cc_toolchain = find_cc_toolchain(ctx) cc_toolchain = find_cpp_toolchain(ctx)
cc_flags = build_cc_flags(ctx, cc_toolchain, CC_FLAGS_MAKE_VARIABLE_ACTION_NAME) cc_flags = build_cc_flags(ctx, cc_toolchain, CC_FLAGS_MAKE_VARIABLE_ACTION_NAME)
variables = platform_common.TemplateVariableInfo({ variables = platform_common.TemplateVariableInfo({
"CC_FLAGS": cc_flags, "CC_FLAGS": cc_flags,

View File

@ -14,16 +14,16 @@
"""Rule that allows select() to differentiate between compilers.""" """Rule that allows select() to differentiate between compilers."""
load("//cc:find_cc_toolchain.bzl", "find_cc_toolchain") load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
def _compiler_flag_impl(ctx): def _compiler_flag_impl(ctx):
toolchain = find_cc_toolchain(ctx) toolchain = find_cpp_toolchain(ctx)
return [config_common.FeatureFlagInfo(value = toolchain.compiler)] return [config_common.FeatureFlagInfo(value = toolchain.compiler)]
compiler_flag = rule( compiler_flag = rule(
implementation = _compiler_flag_impl, implementation = _compiler_flag_impl,
attrs = { attrs = {
"_cc_toolchain": attr.label(default = Label("//cc:current_cc_toolchain")), "_cc_toolchain": attr.label(default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")),
}, },
toolchains = [ toolchains = [
"@bazel_tools//tools/cpp:toolchain_type", # copybara-use-repo-external-label "@bazel_tools//tools/cpp:toolchain_type", # copybara-use-repo-external-label

View File

@ -14,12 +14,12 @@
"""Example showing how to create a rule that rules_cc can depend on.""" """Example showing how to create a rule that rules_cc can depend on."""
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load("@rules_cc//cc:action_names.bzl", "CPP_LINK_STATIC_LIBRARY_ACTION_NAME") load("@rules_cc//cc:action_names.bzl", "CPP_LINK_STATIC_LIBRARY_ACTION_NAME")
load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain")
load("//examples/my_c_compile:my_c_compile.bzl", "MyCCompileInfo") load("//examples/my_c_compile:my_c_compile.bzl", "MyCCompileInfo")
def _my_c_archive_impl(ctx): def _my_c_archive_impl(ctx):
cc_toolchain = find_cc_toolchain(ctx) cc_toolchain = find_cpp_toolchain(ctx)
object_file = ctx.attr.object[MyCCompileInfo].object object_file = ctx.attr.object[MyCCompileInfo].object
output_file = ctx.actions.declare_file(ctx.label.name + ".a") output_file = ctx.actions.declare_file(ctx.label.name + ".a")

View File

@ -14,8 +14,8 @@
"""Example showing how to create a rule that just compiles C sources.""" """Example showing how to create a rule that just compiles C sources."""
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load("@rules_cc//cc:action_names.bzl", "C_COMPILE_ACTION_NAME") load("@rules_cc//cc:action_names.bzl", "C_COMPILE_ACTION_NAME")
load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain")
MyCCompileInfo = provider(doc = "", fields = ["object"]) MyCCompileInfo = provider(doc = "", fields = ["object"])
@ -24,7 +24,7 @@ DISABLED_FEATURES = [
] ]
def _my_c_compile_impl(ctx): def _my_c_compile_impl(ctx):
cc_toolchain = find_cc_toolchain(ctx) cc_toolchain = find_cpp_toolchain(ctx)
source_file = ctx.file.src source_file = ctx.file.src
output_file = ctx.actions.declare_file(ctx.label.name + ".o") output_file = ctx.actions.declare_file(ctx.label.name + ".o")
feature_configuration = cc_common.configure_features( feature_configuration = cc_common.configure_features(

View File

@ -14,10 +14,10 @@
"""Example showing how to get CcToolchainInfo in a custom rule.""" """Example showing how to get CcToolchainInfo in a custom rule."""
load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain") load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
def _write_cc_toolchain_cpu_impl(ctx): def _write_cc_toolchain_cpu_impl(ctx):
cc_toolchain = find_cc_toolchain(ctx) cc_toolchain = find_cpp_toolchain(ctx)
output = ctx.actions.declare_file(ctx.label.name + "_cpu") output = ctx.actions.declare_file(ctx.label.name + "_cpu")
ctx.actions.write(output, cc_toolchain.cpu) ctx.actions.write(output, cc_toolchain.cpu)
return [DefaultInfo(files = depset([output]))] return [DefaultInfo(files = depset([output]))]