bazel: use host platform by default (#1434)

This commit is contained in:
Malte Poll 2023-03-16 16:13:48 +01:00 committed by GitHub
parent 0fc15b2393
commit 62e2e70699
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 107 additions and 21 deletions

49
bazel/go/platform.bzl Normal file
View file

@ -0,0 +1,49 @@
"""A rule to build a single executable for a specific platform."""
def _platform_transition_impl(settings, attr):
_ignore = settings # @unused
return {
"//command_line_option:platforms": "{}".format(attr.platform),
}
_platform_transition = transition(
implementation = _platform_transition_impl,
inputs = [],
outputs = [
"//command_line_option:platforms",
],
)
def _platform_binary_impl(ctx):
out = ctx.actions.declare_file("{}_{}".format(ctx.file.target_file.basename, ctx.attr.platform))
ctx.actions.symlink(output = out, target_file = ctx.file.target_file)
return [
DefaultInfo(
executable = out,
files = depset([out]),
runfiles = ctx.runfiles(files = ctx.files.target_file),
),
]
_attrs = {
"platform": attr.string(
doc = "The platform to build the target for.",
),
"target_file": attr.label(
allow_single_file = True,
mandatory = True,
doc = "Target to build.",
),
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
}
# wrap a single exectable and build it for the specified platform.
platform_binary = rule(
implementation = _platform_binary_impl,
cfg = _platform_transition,
attrs = _attrs,
executable = True,
)