aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGoogler <noreply@google.com>2024-03-07 07:39:26 -0800
committerCopybara-Service <copybara-worker@google.com>2024-03-07 07:40:02 -0800
commite658433e23a924b6c3c9503d0f22b9c965af0af6 (patch)
treee2f44550bb2506326d3e886343614677c65abb4d
parent1ff1af662e587b0913c71c4d7ad09a29975184d0 (diff)
downloadbazelbuild-rules_cc-e658433e23a924b6c3c9503d0f22b9c965af0af6.tar.gz
No public description
PiperOrigin-RevId: 613579953 Change-Id: I4aea8af1b3db8eb532c7c9296fc4dfa0c2ff9481
-rw-r--r--MODULE.bazel2
-rw-r--r--cc/toolchains/args.bzl1
-rw-r--r--cc/toolchains/impl/toolchain_config.bzl2
-rw-r--r--cc/toolchains/tool.bzl16
-rw-r--r--tests/rule_based_toolchain/tool/BUILD4
-rw-r--r--tests/rule_based_toolchain/toolchain_config/BUILD2
6 files changed, 17 insertions, 10 deletions
diff --git a/MODULE.bazel b/MODULE.bazel
index f664840..ee4789b 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -4,6 +4,7 @@ module(
compatibility_level = 1,
)
+bazel_dep(name = "bazel_skylib", version = "1.3.0")
bazel_dep(name = "platforms", version = "0.0.7")
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")
-bazel_dep(name = "bazel_skylib", version = "1.3.0", dev_dependency = True)
bazel_dep(name = "rules_testing", version = "0.6.0", dev_dependency = True)
diff --git a/cc/toolchains/args.bzl b/cc/toolchains/args.bzl
index a19c16a..b2f3660 100644
--- a/cc/toolchains/args.bzl
+++ b/cc/toolchains/args.bzl
@@ -82,6 +82,7 @@ directory as additional files.
""",
),
"args": attr.string_list(
+ mandatory = True,
doc = """Arguments that should be added to the command-line.
These are evaluated in order, with earlier args appearing earlier in the
diff --git a/cc/toolchains/impl/toolchain_config.bzl b/cc/toolchains/impl/toolchain_config.bzl
index 7a69dc0..37e5959 100644
--- a/cc/toolchains/impl/toolchain_config.bzl
+++ b/cc/toolchains/impl/toolchain_config.bzl
@@ -53,7 +53,7 @@ def _cc_toolchain_config_impl(ctx):
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:
- 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(
label = ctx.label,
diff --git a/cc/toolchains/tool.bzl b/cc/toolchains/tool.bzl
index 797ef52..fb552ca 100644
--- a/cc/toolchains/tool.bzl
+++ b/cc/toolchains/tool.bzl
@@ -21,8 +21,15 @@ load(
)
def _cc_tool_impl(ctx):
- exe = ctx.executable.executable
- runfiles = collect_data(ctx, ctx.attr.data + [ctx.attr.executable])
+ exe_info = ctx.attr.src[DefaultInfo]
+ 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(
label = ctx.label,
exe = exe,
@@ -37,7 +44,7 @@ def _cc_tool_impl(ctx):
link = ctx.actions.declare_file(ctx.label.name)
ctx.actions.symlink(
output = link,
- target_file = ctx.executable.executable,
+ target_file = exe,
is_executable = True,
)
return [
@@ -55,9 +62,8 @@ cc_tool = rule(
implementation = _cc_tool_impl,
# @unsorted-dict-items
attrs = {
- "executable": attr.label(
+ "src": attr.label(
allow_files = True,
- executable = True,
cfg = "exec",
doc = """The underlying binary that this tool represents.
diff --git a/tests/rule_based_toolchain/tool/BUILD b/tests/rule_based_toolchain/tool/BUILD
index 31c2813..d16ded6 100644
--- a/tests/rule_based_toolchain/tool/BUILD
+++ b/tests/rule_based_toolchain/tool/BUILD
@@ -6,8 +6,8 @@ load(":tool_test.bzl", "TARGETS", "TESTS")
util.helper_target(
cc_tool,
name = "tool",
+ src = "//tests/rule_based_toolchain/testdata:bin_wrapper.sh",
data = ["//tests/rule_based_toolchain/testdata:bin"],
- executable = "//tests/rule_based_toolchain/testdata:bin_wrapper.sh",
execution_requirements = ["requires-network"],
requires_any_of = ["//tests/rule_based_toolchain/features:direct_constraint"],
)
@@ -15,7 +15,7 @@ util.helper_target(
util.helper_target(
cc_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__"],
)
diff --git a/tests/rule_based_toolchain/toolchain_config/BUILD b/tests/rule_based_toolchain/toolchain_config/BUILD
index f7f194d..f2e91f5 100644
--- a/tests/rule_based_toolchain/toolchain_config/BUILD
+++ b/tests/rule_based_toolchain/toolchain_config/BUILD
@@ -142,7 +142,7 @@ util.helper_target(
util.helper_target(
cc_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"],
)