diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/bazel.mk | 22 | ||||
-rw-r--r-- | tools/bazeldefs/tags.bzl | 62 |
2 files changed, 51 insertions, 33 deletions
diff --git a/tools/bazel.mk b/tools/bazel.mk index a2ded7846..4d9bbf0ee 100644 --- a/tools/bazel.mk +++ b/tools/bazel.mk @@ -21,8 +21,8 @@ BRANCH_NAME := $(shell (git branch --show-current 2>/dev/null || \ # Bazel container configuration (see below). USER ?= gvisor -DOCKER_NAME ?= gvisor-bazel -DOCKER_RUN_OPTIONS ?= --privileged +DOCKER_NAME ?= gvisor-bazel-$(shell readlink -m $(CURDIR) | md5sum | cut -c1-8) +DOCKER_PRIVILEGED ?= --privileged BAZEL_CACHE := $(shell readlink -m ~/.cache/bazel/) GCLOUD_CONFIG := $(shell readlink -m ~/.config/gcloud/) DOCKER_SOCKET := /var/run/docker.sock @@ -30,18 +30,20 @@ DOCKER_SOCKET := /var/run/docker.sock # Non-configurable. UID := $(shell id -u ${USER}) GID := $(shell id -g ${USER}) +USERADD_OPTIONS := FULL_DOCKER_RUN_OPTIONS := $(DOCKER_RUN_OPTIONS) FULL_DOCKER_RUN_OPTIONS += -v "$(BAZEL_CACHE):$(BAZEL_CACHE)" FULL_DOCKER_RUN_OPTIONS += -v "$(GCLOUD_CONFIG):$(GCLOUD_CONFIG)" +FULL_DOCKER_RUN_OPTIONS += -v "/tmp:/tmp" +ifneq ($(DOCKER_PRIVILEGED),) FULL_DOCKER_RUN_OPTIONS += -v "$(DOCKER_SOCKET):$(DOCKER_SOCKET)" DOCKER_GROUP := $(shell stat -c '%g' $(DOCKER_SOCKET)) ifneq ($(GID),$(DOCKER_GROUP)) -USERADD_OPTIONS := --groups $(DOCKER_GROUP) -DOCKER_GROUP_OPTIONS := --group-add $(DOCKER_GROUP) -else -USERADD_OPTIONS := -DOCKER_GROUP_OPTIONS := +USERADD_OPTIONS += --groups $(DOCKER_GROUP) +FULL_DOCKER_RUN_OPTIONS += --group-add $(DOCKER_GROUP) +endif endif +SHELL=/bin/bash -o pipefail ## ## Bazel helpers. @@ -58,18 +60,18 @@ endif ## bazel-server-start: load-default ## Starts the bazel server. docker run -d --rm \ + --init \ --name $(DOCKER_NAME) \ --user 0:0 $(DOCKER_GROUP_OPTIONS) \ -v "$(CURDIR):$(CURDIR)" \ --workdir "$(CURDIR)" \ - --tmpfs /tmp:rw,exec \ --entrypoint "" \ $(FULL_DOCKER_RUN_OPTIONS) \ gvisor.dev/images/default \ sh -c "groupadd --gid $(GID) --non-unique $(USER) && \ useradd --uid $(UID) --non-unique --no-create-home --gid $(GID) $(USERADD_OPTIONS) -d $(HOME) $(USER) && \ bazel version && \ - while :; do sleep 3600; done" + exec tail --pid=\$$(bazel info server_pid) -f /dev/null" @while :; do if docker logs $(DOCKER_NAME) 2>/dev/null | grep "Build label:" >/dev/null; then break; fi; sleep 1; done .PHONY: bazel-server-start @@ -85,7 +87,7 @@ bazel-server: ## Ensures that the server exists. Used as an internal target. @docker exec $(DOCKER_NAME) true || $(MAKE) bazel-server-start .PHONY: bazel-server -build_paths = docker exec --user $(UID):$(GID) -i $(DOCKER_NAME) sh -c 'bazel build $(OPTIONS) $(TARGETS) 2>&1 \ +build_paths = docker exec --user $(UID):$(GID) -i $(DOCKER_NAME) sh -o pipefail -c 'bazel build $(OPTIONS) $(TARGETS) 2>&1 \ | tee /dev/fd/2 \ | grep -E "^ bazel-bin/" \ | awk "{print $$1;}"' \ diff --git a/tools/bazeldefs/tags.bzl b/tools/bazeldefs/tags.bzl index 558fb53ae..f5d7a7b21 100644 --- a/tools/bazeldefs/tags.bzl +++ b/tools/bazeldefs/tags.bzl @@ -1,40 +1,56 @@ """List of special Go suffixes.""" -go_suffixes = [ +def explode(tagset, suffixes): + """explode combines tagset and suffixes in all ways. + + Args: + tagset: Original suffixes. + suffixes: Suffixes to combine before and after. + + Returns: + The set of possible combinations. + """ + result = [t for t in tagset] + result += [s for s in suffixes] + for t in tagset: + result += [t + s for s in suffixes] + result += [s + t for s in suffixes] + return result + +archs = [ "_386", - "_386_unsafe", "_aarch64", - "_aarch64_unsafe", "_amd64", - "_amd64_unsafe", "_arm", "_arm64", - "_arm64_unsafe", - "_arm_unsafe", - "_impl", - "_impl_unsafe", - "_linux", - "_linux_unsafe", "_mips", "_mips64", - "_mips64_unsafe", "_mips64le", - "_mips64le_unsafe", - "_mips_unsafe", "_mipsle", - "_mipsle_unsafe", - "_opts", - "_opts_unsafe", "_ppc64", - "_ppc64_unsafe", "_ppc64le", - "_ppc64le_unsafe", "_riscv64", - "_riscv64_unsafe", "_s390x", - "_s390x_unsafe", "_sparc64", - "_sparc64_unsafe", - "_wasm", - "_wasm_unsafe", + "_x86", +] + +oses = [ + "_linux", ] + +generic = [ + "_impl", + "_race", + "_norace", + "_unsafe", + "_opts", +] + +# State explosion? Sure. This is approximately: +# len(archs) * (1 + 2 * len(oses) * (1 + 2 * len(generic)) +# +# This evaluates to 495 at the time of writing. So it's a lot of different +# combinations, but not so much that it will cause issues. We can probably add +# quite a few more variants before this becomes a genuine problem. +go_suffixes = explode(explode(archs, oses), generic) |