summaryrefslogtreecommitdiffhomepage
path: root/tools/bazeldefs/defs.bzl
diff options
context:
space:
mode:
Diffstat (limited to 'tools/bazeldefs/defs.bzl')
-rw-r--r--tools/bazeldefs/defs.bzl46
1 files changed, 44 insertions, 2 deletions
diff --git a/tools/bazeldefs/defs.bzl b/tools/bazeldefs/defs.bzl
index c2f94bb9c..7875bbaea 100644
--- a/tools/bazeldefs/defs.bzl
+++ b/tools/bazeldefs/defs.bzl
@@ -5,8 +5,9 @@ load("@bazel_skylib//:bzl_library.bzl", _bzl_library = "bzl_library")
build_test = _build_test
bzl_library = _bzl_library
-rbe_platform = native.platform
-rbe_toolchain = native.toolchain
+more_shards = 4
+most_shards = 8
+version = "//tools/bazeldefs:version"
def short_path(path):
return path
@@ -37,3 +38,44 @@ def default_net_util():
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)