Skip to content

Commit 9a20cc1

Browse files
committed
Adding plugins to action tools
1 parent 83dc503 commit 9a20cc1

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

ecsact/private/ecsact_codegen.bzl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ def _ecsact_codegen(ctx):
77
info = ctx.toolchains["//ecsact:toolchain_type"].ecsact_info
88

99
outputs = []
10+
tools = [] + info.tool_files
1011
outdir = ctx.actions.declare_directory(ctx.attr.name)
1112

1213
args = ctx.actions.args()
@@ -21,12 +22,15 @@ def _ecsact_codegen(ctx):
2122
out_basename = ctx.attr.name + "/" + src.basename
2223
outputs.append(ctx.actions.declare_file(out_basename + "." + plugin_info.output_extension))
2324

25+
for p in info.target_tool_path_runfiles:
26+
tools.extend(p.files.to_list())
27+
2428
ctx.actions.run(
2529
mnemonic = "EcsactCodegen",
2630
outputs = [outdir] + outputs,
2731
inputs = ctx.files.srcs,
2832
executable = info.target_tool_path,
29-
tools = info.tool_files,
33+
tools = tools,
3034
arguments = [args],
3135
)
3236

ecsact/repositories.bzl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,12 @@ load("@rules_ecsact//ecsact:toolchain.bzl", "ecsact_toolchain")
7575
7676
package(default_visibility = ["//visibility:public"])
7777
78+
exports_files(glob(["share/**/*", "bin/**/*"]))
79+
7880
ecsact_toolchain(
7981
name = "ecsact_toolchain",
8082
target_tool_path = "{target_tool_path}",
83+
target_tool_path_runfiles = [{target_tool_path_runfiles}],
8184
)
8285
"""
8386

@@ -132,6 +135,7 @@ def _ecsact_host_repo_impl(rctx):
132135
ecsact_executable_name = "ecsact" + exe_extension
133136

134137
ecsact_path = rctx.which(ecsact_executable_name)
138+
target_tool_path_runfiles = []
135139

136140
if ecsact_path == None and is_windows:
137141
pwsh = rctx.which("pwsh.exe")
@@ -143,12 +147,22 @@ def _ecsact_host_repo_impl(rctx):
143147
if ecsact_sdk_install_dir:
144148
ecsact_sdk_install_dir = ecsact_sdk_install_dir.replace("\\", "/").strip()
145149
ecsact_path = ecsact_sdk_install_dir + "/bin/ecsact.exe"
150+
ecsact_config = json.decode(rctx.execute([ecsact_path, "config"]).stdout)
151+
ecsact_plugin_dir = ecsact_config["plugin_dir"].replace("\\", "/")
152+
rctx.symlink(ecsact_path, "bin/ecsact.exe")
153+
for plugin in ecsact_config["builtin_plugins"]:
154+
plugin_filename = "ecsact_" + plugin + "_codegen.dll"
155+
plugin_abs_path = ecsact_plugin_dir + "/" + plugin_filename
156+
plugin_local_path = "share/ecsact/" + plugin_filename
157+
rctx.symlink(plugin_abs_path, plugin_local_path)
158+
target_tool_path_runfiles.append("\"" + plugin_local_path + "\"")
146159

147160
if ecsact_path == None:
148161
rctx.file("BUILD.bazel", "")
149162
else:
150163
rctx.file("BUILD.bazel", _HOST_BUILD_CONTENT.format(
151164
target_tool_path = ecsact_path,
165+
target_tool_path_runfiles = ", ".join(target_tool_path_runfiles),
152166
))
153167

154168
rctx.file("codegen_plugins/BUILD.bazel", _CODEGEN_BUILD_CONTENT)

ecsact/toolchain.bzl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ EcsactInfo = provider(
55
doc = "Information about how to invoke the tool executable.",
66
fields = {
77
"target_tool_path": "Path to the tool executable for the target platform.",
8+
"target_tool_path_runfiles": "",
89
"tool_files": """Files required in runfiles to make the tool executable available.
910
1011
May be empty if the target_tool_path points to a locally installed tool binary.""",
@@ -23,6 +24,8 @@ def _ecsact_toolchain_impl(ctx):
2324
fail("Can only set one of target_tool or target_tool_path but both were set.")
2425
if not ctx.attr.target_tool and not ctx.attr.target_tool_path:
2526
fail("Must set one of target_tool or target_tool_path.")
27+
if ctx.attr.target_tool and ctx.attr.target_tool_path_runfiles:
28+
fail("Cannot use target_tool_path_runfiles with target_tool.")
2629

2730
tool_files = []
2831
target_tool_path = ctx.attr.target_tool_path
@@ -42,6 +45,7 @@ def _ecsact_toolchain_impl(ctx):
4245
)
4346
ecsact_info = EcsactInfo(
4447
target_tool_path = target_tool_path,
48+
target_tool_path_runfiles = ctx.attr.target_tool_path_runfiles,
4549
tool_files = tool_files,
4650
)
4751

@@ -70,6 +74,11 @@ ecsact_toolchain = rule(
7074
doc = "Path to an existing executable for the target platform.",
7175
mandatory = False,
7276
),
77+
"target_tool_path_runfiles": attr.label_list(
78+
doc = "List of files needed at runtime for `target_tool_path`. Not valid with `target_tool`.",
79+
mandatory = False,
80+
allow_files = True,
81+
),
7382
},
7483
doc = """Defines a ecsact compiler/runtime toolchain.
7584

0 commit comments

Comments
 (0)