Skip to content

Commit

Permalink
Replace 'target' attribute with 'targets'.
Browse files Browse the repository at this point in the history
This is so that multiple labels could be provided to a toolchain as
sources. An example is `emcmake`, which needs both `emscripten` and
`binaryen` to run.

Another reason for this is to pass in config files that might be needed
for the toolchain. The config files can be passed in as a label and will
be available in ${EXT_BUILD_DEPS}/bin, just like any other directory.
  • Loading branch information
Attila Oláh committed Feb 5, 2021
1 parent 466c32c commit 162e308
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/with_prebuilt_ninja_artefact/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)

Expand Down
6 changes: 3 additions & 3 deletions tools/build_defs/native_tools/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)

Expand All @@ -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"],
)

Expand All @@ -57,7 +57,7 @@ ninja_tool(
native_tool_toolchain(
name = "built_ninja",
path = "ninja/ninja",
target = ":ninja_tool",
targets = [":ninja_tool"],
visibility = ["//visibility:public"],
)

Expand Down
25 changes: 17 additions & 8 deletions tools/build_defs/native_tools/native_tools_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@ 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."
),
},
)

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(
Expand All @@ -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.""",
),
},
)

Expand All @@ -59,5 +68,5 @@ def access_tool(toolchain_type_, ctx, tool_name):
return tool_toolchain.data
return ToolInfo(
path = tool_name,
target = None,
targets = [],
)
4 changes: 2 additions & 2 deletions tools/build_defs/native_tools/tool_access.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
Expand Down

0 comments on commit 162e308

Please sign in to comment.