diff --git a/examples/with_prebuilt_ninja_artefact/BUILD b/examples/with_prebuilt_ninja_artefact/BUILD index f1f9040a2..bc9b746c9 100644 --- a/examples/with_prebuilt_ninja_artefact/BUILD +++ b/examples/with_prebuilt_ninja_artefact/BUILD @@ -9,7 +9,7 @@ native_tool_toolchain( # In the path, we also start with the name of the directory, # in this case the external repository. path = "ninja_artefact/ninja", - target = "@ninja_artefact//:all", + targets = ["@ninja_artefact//:all"], visibility = ["//visibility:public"], ) diff --git a/tools/build_defs/native_tools/BUILD b/tools/build_defs/native_tools/BUILD index 3e481a828..d0b2500ff 100644 --- a/tools/build_defs/native_tools/BUILD +++ b/tools/build_defs/native_tools/BUILD @@ -19,7 +19,7 @@ make_tool( native_tool_toolchain( name = "built_make", path = "make/bin/make", - target = ":make_tool", + targets = [":make_tool"], visibility = ["//visibility:public"], ) @@ -38,7 +38,7 @@ cmake_tool( native_tool_toolchain( name = "built_cmake", path = "cmake/bin/cmake", - target = ":cmake_tool", + targets = [":cmake_tool"], visibility = ["//visibility:public"], ) @@ -57,7 +57,7 @@ ninja_tool( native_tool_toolchain( name = "built_ninja", path = "ninja/ninja", - target = ":ninja_tool", + targets = [":ninja_tool"], visibility = ["//visibility:public"], ) diff --git a/tools/build_defs/native_tools/native_tools_toolchain.bzl b/tools/build_defs/native_tools/native_tools_toolchain.bzl index 9027187fc..7a0895ed5 100644 --- a/tools/build_defs/native_tools/native_tools_toolchain.bzl +++ b/tools/build_defs/native_tools/native_tools_toolchain.bzl @@ -8,8 +8,8 @@ ToolInfo = provider( "to the bazel-genfiles, i.e. it should start with the name of the top directory of the built tree " + "artifact. (Please see the example `//examples:built_cmake_toolchain`)" ), - "target": ( - "If the tool is preinstalled, must be None. " + + "targets": ( + "If the tool is preinstalled, must be an empty list. " + "If the tool is built as part of the build, the corresponding build target, which should produce " + "the tree artifact with the binary to call." ), @@ -17,11 +17,14 @@ ToolInfo = provider( ) def _native_tool_toolchain(ctx): - if not ctx.attr.path and not ctx.attr.target: - fail("Either path or target (and path) should be defined for the tool.") + if not ctx.attr.path and not ctx.attr.target and not ctx.attr.targets: + fail("Either path or targets (and path) should be defined for the tool.") + targets = ctx.attr.targets + if not targets and ctx.attr.target: + targets = [ctx.attr.target] return platform_common.ToolchainInfo(data = ToolInfo( path = ctx.attr.path, - target = ctx.attr.target, + targets = targets, )) native_tool_toolchain = rule( @@ -42,14 +45,20 @@ native_tool_toolchain = rule( "of the built tree artifact. (Please see the example `//examples:built_cmake_toolchain`)" ), ), - "target": attr.label( + "targets": attr.label_list( mandatory = False, + allow_empty = True, + default = [], doc = ( - "If the tool is preinstalled, must be None. " + + "If the tool is preinstalled, must be an empty list. " + "If the tool is built as part of the build, the corresponding build target, " + "which should produce the tree artifact with the binary to call." ), ), + "target": attr.label( + mandatory = False, + doc = """DEPRECATED: use `targets` instead.""", + ), }, ) @@ -59,5 +68,5 @@ def access_tool(toolchain_type_, ctx, tool_name): return tool_toolchain.data return ToolInfo( path = tool_name, - target = None, + targets = [], ) diff --git a/tools/build_defs/native_tools/tool_access.bzl b/tools/build_defs/native_tools/tool_access.bzl index 3c1775d7d..77ea2a40f 100644 --- a/tools/build_defs/native_tools/tool_access.bzl +++ b/tools/build_defs/native_tools/tool_access.bzl @@ -12,9 +12,9 @@ def get_make_data(ctx): def _access_and_expect_label_copied(toolchain_type_, ctx, tool_name): tool_data = access_tool(toolchain_type_, ctx, tool_name) - if tool_data.target: + if tool_data.targets: return struct( - deps = [tool_data.target], + deps = tool_data.targets, # as the tool will be copied into tools directory path = "$EXT_BUILD_DEPS/bin/{}".format(tool_data.path), )