2
0
Fork 0
mirror of https://github.com/bazelbuild/rules_cc synced 2024-11-27 20:43:26 +00:00

No public description

PiperOrigin-RevId: 613579953
Change-Id: I4aea8af1b3db8eb532c7c9296fc4dfa0c2ff9481
This commit is contained in:
Googler 2024-03-07 07:39:26 -08:00 committed by Copybara-Service
parent 1ff1af662e
commit e658433e23
6 changed files with 17 additions and 10 deletions

View file

@ -4,6 +4,7 @@ module(
compatibility_level = 1, compatibility_level = 1,
) )
bazel_dep(name = "bazel_skylib", version = "1.3.0")
bazel_dep(name = "platforms", version = "0.0.7") bazel_dep(name = "platforms", version = "0.0.7")
cc_configure = use_extension("@bazel_tools//tools/cpp:cc_configure.bzl", "cc_configure_extension") cc_configure = use_extension("@bazel_tools//tools/cpp:cc_configure.bzl", "cc_configure_extension")
@ -11,5 +12,4 @@ use_repo(cc_configure, "local_config_cc_toolchains")
register_toolchains("@local_config_cc_toolchains//:all") register_toolchains("@local_config_cc_toolchains//:all")
bazel_dep(name = "bazel_skylib", version = "1.3.0", dev_dependency = True)
bazel_dep(name = "rules_testing", version = "0.6.0", dev_dependency = True) bazel_dep(name = "rules_testing", version = "0.6.0", dev_dependency = True)

View file

@ -82,6 +82,7 @@ directory as additional files.
""", """,
), ),
"args": attr.string_list( "args": attr.string_list(
mandatory = True,
doc = """Arguments that should be added to the command-line. doc = """Arguments that should be added to the command-line.
These are evaluated in order, with earlier args appearing earlier in the These are evaluated in order, with earlier args appearing earlier in the

View file

@ -53,7 +53,7 @@ def _cc_toolchain_config_impl(ctx):
fail("Features is a reserved attribute in bazel. Did you mean 'toolchain_features'") fail("Features is a reserved attribute in bazel. Did you mean 'toolchain_features'")
if not ctx.attr._enabled[BuildSettingInfo].value and not ctx.attr.skip_experimental_flag_validation_for_test: if not ctx.attr._enabled[BuildSettingInfo].value and not ctx.attr.skip_experimental_flag_validation_for_test:
fail("Rule based toolchains are experimental. To use it, please add --//cc/toolchains:experimental_enable_rule_based_toolchains to your bazelrc") fail("Rule based toolchains are experimental. To use it, please add --@rules_cc//cc/toolchains:experimental_enable_rule_based_toolchains to your bazelrc")
toolchain_config = toolchain_config_info( toolchain_config = toolchain_config_info(
label = ctx.label, label = ctx.label,

View file

@ -21,8 +21,15 @@ load(
) )
def _cc_tool_impl(ctx): def _cc_tool_impl(ctx):
exe = ctx.executable.executable exe_info = ctx.attr.src[DefaultInfo]
runfiles = collect_data(ctx, ctx.attr.data + [ctx.attr.executable]) if exe_info.files_to_run != None and exe_info.files_to_run.executable != None:
exe = exe_info.files_to_run.executable
elif len(exe_info.files.to_list()) == 1:
exe = exe_info.files.to_list()[0]
else:
fail("Expected cc_tool's src attribute to be either an executable or a single file")
runfiles = collect_data(ctx, ctx.attr.data + [ctx.attr.src])
tool = ToolInfo( tool = ToolInfo(
label = ctx.label, label = ctx.label,
exe = exe, exe = exe,
@ -37,7 +44,7 @@ def _cc_tool_impl(ctx):
link = ctx.actions.declare_file(ctx.label.name) link = ctx.actions.declare_file(ctx.label.name)
ctx.actions.symlink( ctx.actions.symlink(
output = link, output = link,
target_file = ctx.executable.executable, target_file = exe,
is_executable = True, is_executable = True,
) )
return [ return [
@ -55,9 +62,8 @@ cc_tool = rule(
implementation = _cc_tool_impl, implementation = _cc_tool_impl,
# @unsorted-dict-items # @unsorted-dict-items
attrs = { attrs = {
"executable": attr.label( "src": attr.label(
allow_files = True, allow_files = True,
executable = True,
cfg = "exec", cfg = "exec",
doc = """The underlying binary that this tool represents. doc = """The underlying binary that this tool represents.

View file

@ -6,8 +6,8 @@ load(":tool_test.bzl", "TARGETS", "TESTS")
util.helper_target( util.helper_target(
cc_tool, cc_tool,
name = "tool", name = "tool",
src = "//tests/rule_based_toolchain/testdata:bin_wrapper.sh",
data = ["//tests/rule_based_toolchain/testdata:bin"], data = ["//tests/rule_based_toolchain/testdata:bin"],
executable = "//tests/rule_based_toolchain/testdata:bin_wrapper.sh",
execution_requirements = ["requires-network"], execution_requirements = ["requires-network"],
requires_any_of = ["//tests/rule_based_toolchain/features:direct_constraint"], requires_any_of = ["//tests/rule_based_toolchain/features:direct_constraint"],
) )
@ -15,7 +15,7 @@ util.helper_target(
util.helper_target( util.helper_target(
cc_tool, cc_tool,
name = "wrapped_tool", name = "wrapped_tool",
executable = "//tests/rule_based_toolchain/testdata:bin_wrapper", src = "//tests/rule_based_toolchain/testdata:bin_wrapper",
visibility = ["//tests/rule_based_toolchain:__subpackages__"], visibility = ["//tests/rule_based_toolchain:__subpackages__"],
) )

View file

@ -142,7 +142,7 @@ util.helper_target(
util.helper_target( util.helper_target(
cc_tool, cc_tool,
name = "requires_all_simple_tool", name = "requires_all_simple_tool",
executable = "//tests/rule_based_toolchain/testdata:bin_wrapper.sh", src = "//tests/rule_based_toolchain/testdata:bin_wrapper.sh",
requires_any_of = [":all_simple_features"], requires_any_of = [":all_simple_features"],
) )