2019-01-13 16:51:34 +00:00
|
|
|
def _copy_go_binary_impl(ctx):
|
|
|
|
output = ctx.actions.declare_file(ctx.label.name)
|
2019-07-14 12:07:15 +00:00
|
|
|
for f in ctx.attr.src.files.to_list():
|
2019-01-13 16:51:34 +00:00
|
|
|
# go_binary rules have two outputs, a library and the binary itself.
|
|
|
|
# The following is a horrible hack to avoid copying the library.
|
|
|
|
if f.path.endswith(".a"):
|
|
|
|
continue
|
2019-07-14 12:07:15 +00:00
|
|
|
ctx.actions.run_shell(
|
2024-01-15 12:53:30 +00:00
|
|
|
inputs = [f],
|
|
|
|
outputs = [output],
|
|
|
|
mnemonic = "CopyGoBinary",
|
|
|
|
command = "mkdir -p %s && cp %s %s" % (output.dirname, f.path, output.path),
|
|
|
|
)
|
|
|
|
return [DefaultInfo(executable = output)]
|
2019-01-13 16:51:34 +00:00
|
|
|
|
|
|
|
copy_go_binary = rule(
|
2024-01-15 12:53:30 +00:00
|
|
|
implementation = _copy_go_binary_impl,
|
|
|
|
attrs = {
|
|
|
|
"src": attr.label(mandatory = True, allow_files = True),
|
2019-01-13 16:51:34 +00:00
|
|
|
},
|
2024-01-15 12:53:30 +00:00
|
|
|
executable = True,
|
2019-01-13 16:51:34 +00:00
|
|
|
)
|