fwd/vendor/cxx/tools/buck/prelude/go/go_binary.bzl
John Doty 9c435dc440 Vendor dependencies
Let's see how I like this workflow.
2022-12-19 08:38:22 -08:00

44 lines
1.5 KiB
Python

# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.
load(
"@prelude//utils:utils.bzl",
"expect",
)
load(":compile.bzl", "compile", "get_filtered_srcs")
load(":link.bzl", "link")
def go_binary_impl(ctx: "context") -> ["provider"]:
lib = compile(ctx, "main", get_filtered_srcs(ctx, ctx.attrs.srcs), deps = ctx.attrs.deps)
(bin, runtime_files) = link(ctx, lib, deps = ctx.attrs.deps, link_mode = ctx.attrs.link_mode)
hidden = []
for resource in ctx.attrs.resources:
if type(resource) == "artifact":
hidden.append(resource)
else:
# Otherwise, this is a dependency, so extract the resource and other
# resources from the `DefaultInfo` provider.
info = resource[DefaultInfo]
expect(
len(info.default_outputs) == 1,
"expected exactly one default output from {} ({})"
.format(resource, info.default_outputs),
)
[resource] = info.default_outputs
other = info.other_outputs
hidden.append(resource)
hidden.extend(other)
return [
DefaultInfo(
default_outputs = [bin],
other_outputs = hidden + runtime_files,
),
RunInfo(args = cmd_args(bin).hidden(hidden + runtime_files)),
]