Use arch_genrule for arch-specific VDSO data.

Note that the select_arch macro changed in order to allow for its use within
a rule below arch_genrule. The command line settings were being manipulated in
a way that did not correctly propagate the select_arch select constraints.

PiperOrigin-RevId: 499651425
This commit is contained in:
Adin Scannell
2023-01-04 18:36:14 -08:00
committed by gVisor bot
parent 0926a58934
commit 0781095639
5 changed files with 14 additions and 66 deletions
+7 -18
View File
@@ -1,4 +1,4 @@
load("//tools:defs.bzl", "go_add_tags", "go_embed_data", "go_library")
load("//tools:defs.bzl", "arch_genrule", "go_embed_data", "go_library")
package(licenses = ["notice"])
@@ -9,28 +9,17 @@ go_embed_data(
var = "Binary",
)
[
# Generate multiple tagged files. Note that the contents of all files
# will be the same (i.e. vdso_arm64.go will contain the amd64 vdso), but
# the build tags will ensure only one is selected. When we generate the
# "Go" branch, we select all archiecture files from the relevant build.
# This is a hack around some limitations for "out" being a configurable
# attribute and selects for srcs. See also tools/go_branch.sh.
go_add_tags(
name = "vdso_%s" % arch,
src = ":vdso_bin",
out = "vdso_%s.go" % arch,
go_tags = [arch],
)
for arch in ("amd64", "arm64")
]
arch_genrule(
name = "vdso_arch",
src = ":vdso_bin",
template = "vdso_%s.go",
)
go_library(
name = "vdsodata",
srcs = [
"vdsodata.go",
":vdso_amd64",
":vdso_arm64",
":vdso_arch",
],
marshal = False,
stateify = False,
+4 -12
View File
@@ -24,21 +24,13 @@ bzl_library(
)
config_setting(
name = "linux_arm64_cross",
values = {
"cpu": "aarch64",
"host_cpu": "k8",
},
visibility = ["//visibility:private"],
name = "amd64",
values = {"cpu": "k8"},
)
config_setting(
name = "linux_amd64_cross",
values = {
"cpu": "k8",
"host_cpu": "aarch64",
},
visibility = ["//visibility:private"],
name = "arm64",
values = {"cpu": "aarch64"},
)
genrule(
+2 -2
View File
@@ -23,8 +23,8 @@ def proto_library(name, has_services = None, **kwargs):
def select_arch(amd64 = "amd64", arm64 = "arm64", default = None, **kwargs):
values = {
"@bazel_tools//src/conditions:linux_x86_64": amd64,
"@bazel_tools//src/conditions:linux_aarch64": arm64,
"//tools/bazeldefs:amd64": amd64,
"//tools/bazeldefs:arm64": arm64,
}
if default:
values["//conditions:default"] = default
+1 -30
View File
@@ -10,7 +10,7 @@ load("//tools/go_marshal:defs.bzl", "go_marshal", "marshal_deps", "marshal_test_
load("//tools/nogo:defs.bzl", "nogo_test")
load("//tools/bazeldefs:defs.bzl", _BuildSettingInfo = "BuildSettingInfo", _amd64_config = "amd64_config", _arch_config = "arch_config", _arm64_config = "arm64_config", _bool_flag = "bool_flag", _bpf_program = "bpf_program", _build_test = "build_test", _bzl_library = "bzl_library", _coreutil = "coreutil", _default_net_util = "default_net_util", _more_shards = "more_shards", _most_shards = "most_shards", _proto_library = "proto_library", _select_arch = "select_arch", _select_system = "select_system", _short_path = "short_path", _transition_allowlist = "transition_allowlist", _version = "version")
load("//tools/bazeldefs:cc.bzl", _cc_binary = "cc_binary", _cc_flags_supplier = "cc_flags_supplier", _cc_grpc_library = "cc_grpc_library", _cc_library = "cc_library", _cc_proto_library = "cc_proto_library", _cc_test = "cc_test", _cc_toolchain = "cc_toolchain", _gbenchmark = "gbenchmark", _gbenchmark_internal = "gbenchmark_internal", _grpcpp = "grpcpp", _gtest = "gtest", _vdso_linker_option = "vdso_linker_option")
load("//tools/bazeldefs:go.bzl", _gazelle = "gazelle", _go_binary = "go_binary", _go_embed_data = "go_embed_data", _go_grpc_and_proto_libraries = "go_grpc_and_proto_libraries", _go_library = "go_library", _go_path = "go_path", _go_proto_library = "go_proto_library", _go_rule = "go_rule", _go_test = "go_test", _gotsan_flag_values = "gotsan_flag_values", _gotsan_values = "gotsan_values", _select_goarch = "select_goarch", _select_goos = "select_goos")
load("//tools/bazeldefs:go.bzl", _gazelle = "gazelle", _go_binary = "go_binary", _go_embed_data = "go_embed_data", _go_grpc_and_proto_libraries = "go_grpc_and_proto_libraries", _go_library = "go_library", _go_path = "go_path", _go_proto_library = "go_proto_library", _go_test = "go_test", _gotsan_flag_values = "gotsan_flag_values", _gotsan_values = "gotsan_values", _select_goarch = "select_goarch", _select_goos = "select_goos")
load("//tools/bazeldefs:pkg.bzl", _pkg_deb = "pkg_deb", _pkg_tar = "pkg_tar")
load("//tools/bazeldefs:platforms.bzl", _default_platform = "default_platform", _platform_capabilities = "platform_capabilities", _platforms = "platforms")
load("//tools/bazeldefs:tags.bzl", "go_suffixes")
@@ -64,35 +64,6 @@ default_platform = _default_platform
platforms = _platforms
platform_capabilities = _platform_capabilities
def _go_add_tags(ctx):
""" Adds tags to the given source file. """
output = ctx.outputs.out
runner = ctx.actions.declare_file(ctx.label.name + ".sh")
lines = ["#!/bin/bash"]
lines += ["echo '// +build %s' >> %s" % (tag, output.path) for tag in ctx.attr.go_tags]
lines.append("echo '' >> %s" % output.path)
lines += ["cat %s >> %s" % (f.path, output.path) for f in ctx.files.src]
lines.append("")
ctx.actions.write(runner, "\n".join(lines), is_executable = True)
ctx.actions.run(
inputs = ctx.files.src,
outputs = [output],
executable = runner,
)
return [DefaultInfo(
files = depset([output]),
)]
go_add_tags = _go_rule(
rule,
implementation = _go_add_tags,
attrs = {
"go_tags": attr.string_list(doc = "Go build tags to be added.", mandatory = True),
"src": attr.label(doc = "Source file.", allow_single_file = True, mandatory = True),
"out": attr.output(doc = "Output file.", mandatory = True),
},
)
def go_binary(name, nogo = True, pure = False, static = False, x_defs = None, **kwargs):
"""Wraps the standard go_binary.
-4
View File
@@ -36,10 +36,6 @@ genrule(
# VDSO has no hooks to handle failures.
"-fno-stack-protector " +
vdso_linker_option +
select_arch(
amd64 = "-m64 ",
arm64 = "",
) +
"-shared " +
"-nostdlib " +
"-Wl,-soname=linux-vdso.so.1 " +