1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
"""Meta and miscellaneous rules."""
load("@bazel_skylib//rules:build_test.bzl", _build_test = "build_test")
load("@bazel_skylib//:bzl_library.bzl", _bzl_library = "bzl_library")
build_test = _build_test
bzl_library = _bzl_library
more_shards = 4
most_shards = 8
version = "//tools/bazeldefs:version"
def short_path(path):
return path
def proto_library(name, has_services = None, **kwargs):
native.proto_library(
name = name,
**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,
}
if default:
values["//conditions:default"] = default
return select(values, **kwargs)
def select_system(linux = ["__linux__"], **kwargs):
return linux # Only Linux supported.
def default_installer():
return None
def default_net_util():
return [] # Nothing needed.
def coreutil():
return [] # Nothing needed.
def select_native_vs_cross(native = [], amd64 = [], arm64 = [], cross = []):
values = {
"//tools/bazeldefs:linux_arm64_cross": arm64 + cross,
"//tools/bazeldefs:linux_amd64_cross": amd64 + cross,
"//conditions:default": native,
}
return select(values)
def arch_genrule(name, srcs, outs, cmd, tools):
"""Runs a gen command on the target architecture.
If the target architecture isn't match the host architecture, it will build
a command for the target architecture and run it via qemu.
The native genrule runs the command on the host architecture.
Args:
name: name of generated target.
srcs: A list of inputs for this rule.
cmd: The command to run. It has to contain " QEMU " before executed binaries.
outs: A list of files generated by this rule.
tools: A list of tool dependencies for this rule.
"""
qemu_arm64 = "qemu-aarch64-static"
qemu_amd64 = "qemu-x86_64-static"
srcs = select_native_vs_cross(
cross = srcs + tools,
native = srcs,
)
tools = select_native_vs_cross(
cross = [],
native = tools,
)
cmd = select_native_vs_cross(
arm64 = cmd.replace("QEMU", qemu_arm64),
amd64 = cmd.replace("QEMU", qemu_amd64),
native = cmd.replace("QEMU", ""),
cross = "",
)
native.genrule(name = name, srcs = srcs, outs = outs, cmd = cmd, tools = tools)
|