summaryrefslogtreecommitdiffhomepage
path: root/tools/bazeldefs
diff options
context:
space:
mode:
Diffstat (limited to 'tools/bazeldefs')
-rw-r--r--tools/bazeldefs/BUILD67
-rw-r--r--tools/bazeldefs/cc.bzl12
-rw-r--r--tools/bazeldefs/defs.bzl46
-rw-r--r--tools/bazeldefs/go.bzl4
-rw-r--r--tools/bazeldefs/pkg.bzl3
5 files changed, 85 insertions, 47 deletions
diff --git a/tools/bazeldefs/BUILD b/tools/bazeldefs/BUILD
index 27e85a75e..ebe90dfec 100644
--- a/tools/bazeldefs/BUILD
+++ b/tools/bazeldefs/BUILD
@@ -1,46 +1,7 @@
-load("//tools:defs.bzl", "bzl_library", "rbe_platform", "rbe_toolchain")
+load("//tools:defs.bzl", "bzl_library")
package(licenses = ["notice"])
-# We need to define a bazel platform and toolchain to specify dockerPrivileged
-# and dockerRunAsRoot options, they are required to run tests on the RBE
-# cluster in Kokoro.
-rbe_platform(
- name = "rbe_ubuntu1604",
- constraint_values = [
- "@bazel_tools//platforms:x86_64",
- "@bazel_tools//platforms:linux",
- "@bazel_tools//tools/cpp:clang",
- "@bazel_toolchains//constraints:xenial",
- "@bazel_toolchains//constraints/sanitizers:support_msan",
- ],
- remote_execution_properties = """
- properties: {
- name: "container-image"
- value:"docker://gcr.io/cloud-marketplace/google/rbe-ubuntu16-04@sha256:b516a2d69537cb40a7c6a7d92d0008abb29fba8725243772bdaf2c83f1be2272"
- }
- properties: {
- name: "dockerAddCapabilities"
- value: "SYS_ADMIN"
- }
- properties: {
- name: "dockerPrivileged"
- value: "true"
- }
- """,
-)
-
-rbe_toolchain(
- name = "cc-toolchain-clang-x86_64-default",
- exec_compatible_with = [],
- tags = [
- "manual",
- ],
- target_compatible_with = [],
- toolchain = "@bazel_toolchains//configs/ubuntu16_04_clang/11.0.0/bazel_3.1.0/cc:cc-compiler-k8",
- toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
-)
-
bzl_library(
name = "platforms_bzl",
srcs = ["platforms.bzl"],
@@ -58,3 +19,29 @@ bzl_library(
srcs = ["defs.bzl"],
visibility = ["//visibility:private"],
)
+
+config_setting(
+ name = "linux_arm64_cross",
+ values = {
+ "cpu": "aarch64",
+ "host_cpu": "k8",
+ },
+ visibility = ["//visibility:private"],
+)
+
+config_setting(
+ name = "linux_amd64_cross",
+ values = {
+ "cpu": "k8",
+ "host_cpu": "aarch64",
+ },
+ visibility = ["//visibility:private"],
+)
+
+genrule(
+ name = "version",
+ outs = ["version.txt"],
+ cmd = "cat bazel-out/stable-status.txt | grep STABLE_VERSION | cut -d' ' -f2- >$@",
+ stamp = True,
+ visibility = ["//:sandbox"],
+)
diff --git a/tools/bazeldefs/cc.bzl b/tools/bazeldefs/cc.bzl
index 7f41a0142..2831eac5f 100644
--- a/tools/bazeldefs/cc.bzl
+++ b/tools/bazeldefs/cc.bzl
@@ -1,11 +1,9 @@
"""C++ rules."""
-load("@bazel_tools//tools/cpp:cc_flags_supplier.bzl", _cc_flags_supplier = "cc_flags_supplier")
load("@rules_cc//cc:defs.bzl", _cc_binary = "cc_binary", _cc_library = "cc_library", _cc_proto_library = "cc_proto_library", _cc_test = "cc_test")
load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", _cc_grpc_library = "cc_grpc_library")
cc_library = _cc_library
-cc_flags_supplier = _cc_flags_supplier
cc_proto_library = _cc_proto_library
cc_test = _cc_test
cc_toolchain = "@bazel_tools//tools/cpp:current_cc_toolchain"
@@ -14,6 +12,16 @@ gbenchmark = "@com_google_benchmark//:benchmark"
grpcpp = "@com_github_grpc_grpc//:grpc++"
vdso_linker_option = "-fuse-ld=gold "
+def _cc_flags_supplier_impl(ctx):
+ variables = platform_common.TemplateVariableInfo({
+ "CC_FLAGS": "",
+ })
+ return [variables]
+
+cc_flags_supplier = rule(
+ implementation = _cc_flags_supplier_impl,
+)
+
def cc_grpc_library(name, **kwargs):
_cc_grpc_library(name = name, grpc_only = True, **kwargs)
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)
diff --git a/tools/bazeldefs/go.bzl b/tools/bazeldefs/go.bzl
index 661c9727e..bcd8cffe7 100644
--- a/tools/bazeldefs/go.bzl
+++ b/tools/bazeldefs/go.bzl
@@ -28,7 +28,7 @@ def go_proto_library(name, **kwargs):
def go_grpc_and_proto_libraries(name, **kwargs):
_go_proto_or_grpc_library(_go_grpc_library, name, **kwargs)
-def go_binary(name, static = False, pure = False, x_defs = None, **kwargs):
+def go_binary(name, static = False, pure = False, x_defs = None, system_malloc = False, **kwargs):
"""Build a go binary.
Args:
@@ -52,7 +52,7 @@ def go_importpath(target):
"""Returns the importpath for the target."""
return target[GoLibrary].importpath
-def go_library(name, **kwargs):
+def go_library(name, arch_deps = [], **kwargs):
_go_library(
name = name,
importpath = "gvisor.dev/gvisor/" + native.package_name(),
diff --git a/tools/bazeldefs/pkg.bzl b/tools/bazeldefs/pkg.bzl
index 56317d93f..ccc9bdeef 100644
--- a/tools/bazeldefs/pkg.bzl
+++ b/tools/bazeldefs/pkg.bzl
@@ -1,6 +1,7 @@
"""Packaging rules."""
-load("@rules_pkg//:pkg.bzl", _pkg_deb = "pkg_deb", _pkg_tar = "pkg_tar")
+# N.B. We refer to pkg_deb_impl to avoid the macro, which cannot use select.
+load("@rules_pkg//:pkg.bzl", _pkg_deb = "pkg_deb_impl", _pkg_tar = "pkg_tar")
pkg_deb = _pkg_deb
pkg_tar = _pkg_tar