diff --git a/examples/with_prebuilt_ninja_artefact/BUILD b/examples/with_prebuilt_ninja_artefact/BUILD index c1aa78235..6a1389cbc 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 18341b6cf..3aa7cae79 100644 --- a/tools/build_defs/native_tools/BUILD +++ b/tools/build_defs/native_tools/BUILD @@ -17,7 +17,7 @@ make_tool( native_tool_toolchain( name = "built_make", path = "make/bin/make", - target = ":make_tool", + targets = [":make_tool"], visibility = ["//visibility:public"], ) @@ -35,7 +35,7 @@ cmake_tool( native_tool_toolchain( name = "built_cmake", path = "cmake/bin/cmake", - target = ":cmake_tool", + targets = [":cmake_tool"], visibility = ["//visibility:public"], ) @@ -53,6 +53,6 @@ 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 6fb3f3a25..2281685c0 100644 --- a/tools/build_defs/native_tools/native_tools_toolchain.bzl +++ b/tools/build_defs/native_tools/native_tools_toolchain.bzl @@ -5,18 +5,21 @@ ToolInfo = provider( Relative path to the tool in case the tool is built as part of a build; the path should be relative 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.""", }, ) 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, )) """ Rule for defining the toolchain data of the native tools (cmake, ninja), @@ -36,7 +39,13 @@ of the built tree artifact. (Please see the example "//examples:built_cmake_tool ), "target": attr.label( mandatory = False, - doc = """If the tool is preinstalled, must be None. + doc = """DEPRECATED: use "targets" instead.""", + ), + "targets": attr.label_list( + mandatory = False, + allow_empty = True, + default = [], + doc = """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.""", ), @@ -49,5 +58,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 db1a20f53..e4f1ed4c9 100644 --- a/tools/build_defs/native_tools/tool_access.bzl +++ b/tools/build_defs/native_tools/tool_access.bzl @@ -11,9 +11,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), )