Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
# Startup options
startup --experimental_remote_repo_contents_cache

# Common settings
common --deleted_packages=e2e/dnf-hermetic-lock
common --experimental_repo_remote_exec

# Bzlmod
common --enable_bzlmod

# Bazel RBE configuration profile targeting //bazel:ubuntu24_04_amd64
# The container image of remote actions can be overridden (e.g. in .bazelrc.user) with
# common --repo_env=RBE_CONTAINER_IMAGE=docker://<registry>/<image>@sha256:<digest>
build:rbe --host_platform=//bazel:ubuntu24_04_amd64
build:rbe --extra_execution_platforms=//bazel:ubuntu24_04_amd64
build:rbe --spawn_strategy=remote
build:rbe --remote_local_fallback=true
build:rbe --remote_download_outputs=minimal
build:rbe --nobuild_runfile_links
build:rbe --remote_cache_compression
build:rbe --experimental_remote_cache_chunking
build:rbe --experimental_repo_remote_exec
build:rbe --disk_cache=
build:rbe --repository_cache=
build:rbe --noslim_profile
build:rbe --experimental_profile_include_target_label
build:rbe --experimental_profile_include_primary_output
test:rbe --remote_default_exec_properties=dockerNetwork=bridge
test:rbe --remote_default_exec_properties=network=bridge
build:rbe --action_env=LC_ALL=C --action_env=LANG=en
build:rbe --host_action_env=LC_ALL=C
build:rbe --jobs=40

# CI configuration profile
common:ci --color=yes
common:ci --show_progress_rate_limit=5
test:ci --test_output=errors
test:ci --test_summary=terse

# Import user configuration if present
# Import user configuration if present (must be last)
try-import %workspace%/.bazelrc.user
31 changes: 31 additions & 0 deletions .github/actions/setup-bazel/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Bazel on a hosted runner, with the BuildBuddy remote cache and execution when
# both the endpoint and the API key are set (otherwise the GitHub Actions disk
# cache). Used by build.yaml and ci.yaml.
name: Set up Bazel
description: Installs Bazel and configures the optional BuildBuddy remote cache.

inputs:
buildbuddy-endpoint:
description: BuildBuddy host name (gRPC at grpcs://<host>, invocation links at https://<host>/invocation/).
required: false
default: ""
buildbuddy-api-key:
description: API key for that BuildBuddy.
required: false
default: ""

runs:
using: composite
steps:
- uses: bazel-contrib/setup-bazel@104e3eea9447cdaa4b00d0fb46191a3985d26ab3 # 0.19.1
with:
bazelisk-cache: true
repository-cache: true
disk-cache: ${{ inputs.buildbuddy-endpoint == '' || inputs.buildbuddy-api-key == '' }}
- name: Configure remote cache
if: inputs.buildbuddy-endpoint != '' && inputs.buildbuddy-api-key != ''
shell: bash
env:
BUILDBUDDY_ENDPOINT: ${{ inputs.buildbuddy-endpoint }}
BUILDBUDDY_TOKEN: ${{ inputs.buildbuddy-api-key }}
run: tools/setup_buildbuddy.sh
8 changes: 4 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:
type: string
default: ""
secrets:
BUILDBUDDY_API_KEY:
BUILDBUDDY_TOKEN:
required: false

jobs:
Expand All @@ -26,10 +26,10 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
ref: ${{ inputs.ref || github.ref }}
- uses: bazel-contrib/setup-bazel@104e3eea9447cdaa4b00d0fb46191a3985d26ab3 # 0.19.1
- uses: ./.github/actions/setup-bazel
with:
bazelisk-cache: true
repository-cache: true
buildbuddy-endpoint: ${{ vars.BUILDBUDDY_ENDPOINT }}
buildbuddy-api-key: ${{ secrets.BUILDBUDDY_TOKEN }}
- name: Build
run: |
mkdir -p dist
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/ci.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ common --show_progress_rate_limit=30
test --test_output=errors

# BuildBuddy remote cache / execution, enabled by the workflows when the
# BUILDBUDDY_ENDPOINT repository variable (host name) and the BUILDBUDDY_API_KEY
# BUILDBUDDY_ENDPOINT repository variable (host name) and the BUILDBUDDY_TOKEN
# secret are set.
# The workflow writes the endpoints derived from the host (--bes_backend,
# --remote_cache and, for buildbuddy-rbe, --remote_executor at grpcs://<host>;
# --bes_results_url at https://<host>/invocation/) and the API key
# (--remote_header) to .bazelrc.user; none of them are stored here.
common:buildbuddy --remote_timeout=3600
common:buildbuddy --noexperimental_remote_cache_chunking
common:buildbuddy-rbe --config=buildbuddy
Expand Down
20 changes: 3 additions & 17 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,12 @@ concurrency:
jobs:
test:
runs-on: ubuntu-26.04
env:
BUILDBUDDY_ENDPOINT: ${{ vars.BUILDBUDDY_ENDPOINT }}
BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: bazel-contrib/setup-bazel@104e3eea9447cdaa4b00d0fb46191a3985d26ab3 # 0.19.1
- uses: ./.github/actions/setup-bazel
with:
bazelisk-cache: true
repository-cache: true
disk-cache: ${{ env.BUILDBUDDY_ENDPOINT == '' || env.BUILDBUDDY_API_KEY == '' }}
- name: Configure remote cache
if: env.BUILDBUDDY_ENDPOINT != '' && env.BUILDBUDDY_API_KEY != ''
run: |
{
echo "common --config=buildbuddy"
echo "common:buildbuddy --bes_backend=grpcs://${BUILDBUDDY_ENDPOINT}"
echo "common:buildbuddy --bes_results_url=https://${BUILDBUDDY_ENDPOINT}/invocation/"
echo "common:buildbuddy --remote_cache=grpcs://${BUILDBUDDY_ENDPOINT}"
echo "common:buildbuddy --remote_header=x-buildbuddy-api-key=${BUILDBUDDY_API_KEY}"
} > .bazelrc.user
buildbuddy-endpoint: ${{ vars.BUILDBUDDY_ENDPOINT }}
buildbuddy-api-key: ${{ secrets.BUILDBUDDY_TOKEN }}
- name: Build
run: bazel --bazelrc=.github/workflows/ci.bazelrc build //...
- name: Test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
ref: ${{ inputs.tag_name || github.ref_name }}
version: ${{ inputs.tag_name || github.ref_name }}
secrets:
BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }}
BUILDBUDDY_TOKEN: ${{ secrets.BUILDBUDDY_TOKEN }}

release:
needs: build
Expand Down
5 changes: 5 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@
2. Commit changes to that branch.
3. Push the branch to `origin`.
4. Open a Pull Request against `main`.

## CI & BuildBuddy Protocol

- **All tests in CI must run with BuildBuddy enabled.** Any test execution in CI (including unit/smoke tests in root and e2e tests in `e2e/*`) must use `.github/actions/setup-bazel` with BuildBuddy endpoints and API keys so remote cache, remote execution (RBE), and BES invocation streaming are always active.
- **Do not delete or overwrite `.bazelrc.user`**: it is git-ignored and holds the user's remote execution credentials. Never print it either.
19 changes: 19 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ bazel_dep(name = "rules_go", version = "0.65.0", dev_dependency = True)
bazel_dep(name = "gazelle", version = "0.54.0", dev_dependency = True)
bazel_dep(name = "toolchains_llvm", version = "1.13.0", dev_dependency = True)
bazel_dep(name = "aspect_rules_py", version = "2.0.0-alpha.10", dev_dependency = True)
bazel_dep(name = "toolchains_buildbuddy", version = "0.0.4", dev_dependency = True)

buildbuddy = use_extension(
"@toolchains_buildbuddy//:extensions.bzl",
"buildbuddy",
dev_dependency = True,
)
buildbuddy.platform(
container_image = "docker://gcr.io/flame-public/rbe-ubuntu24-04@sha256:be9853fc45092d2cf2bda3abed30d22182881659a50bf35c7125161d7cfc8a75",
)
use_repo(buildbuddy, "buildbuddy_toolchain")

# The image above, unless RBE_CONTAINER_IMAGE is set with --repo_env.
rbe_container_image = use_repo_rule("//bazel:rbe.bzl", "rbe_container_image")

rbe_container_image(
name = "rbe_container_image",
dev_dependency = True,
)

python = use_extension("@aspect_rules_py//py:extensions.bzl", "python_interpreters", dev_dependency = True)
python.toolchain(python_version = "3.13")
Expand Down
38 changes: 34 additions & 4 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions bazel/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package(default_visibility = ["//visibility:public"])

# Remote execution platform: Ubuntu 24.04 container image provided by
# toolchains_buildbuddy, overridable with
# --repo_env=RBE_CONTAINER_IMAGE=docker://<image>@sha256:<digest> (see rbe.bzl).
# Only the container image is inherited; the
# BuildBuddy-specific properties are cleared (an empty value drops an inherited
# key) so the platform also works on other REAPI backends.
platform(
name = "ubuntu24_04_amd64",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
exec_properties = {
"Arch": "",
"OSFamily": "",
"dockerNetwork": "",
},
parents = ["@rbe_container_image//:platform"],
)
29 changes: 29 additions & 0 deletions bazel/rbe.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Remote execution container image, overridable with --repo_env."""

_BUILD = """\
# Generated by //bazel:rbe.bzl.
platform(
name = "platform",
exec_properties = {exec_properties},
parents = ["@buildbuddy_toolchain//:platform_linux_x86_64"],
visibility = ["//visibility:public"],
)
"""

def _rbe_container_image_impl(rctx):
image = rctx.getenv("RBE_CONTAINER_IMAGE", "")
exec_properties = {"container-image": image} if image else {}
rctx.file("BUILD.bazel", _BUILD.format(exec_properties = repr(exec_properties)))

rbe_container_image = repository_rule(
implementation = _rbe_container_image_impl,
doc = """Platform that sets the container image of remote actions.

It inherits from the toolchains_buildbuddy platform (whose image is configured
in MODULE.bazel) and, when the RBE_CONTAINER_IMAGE repository environment
variable is set, overrides `container-image` with its value, e.g.:

common --repo_env=RBE_CONTAINER_IMAGE=docker://registry.example.com/rbe@sha256:<digest>
""",
environ = ["RBE_CONTAINER_IMAGE"],
)
5 changes: 4 additions & 1 deletion e2e/dnf-hermetic-lock/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Startup options
startup --experimental_remote_repo_contents_cache

# Bzlmod
common --enable_bzlmod

Expand All @@ -6,4 +9,4 @@ test:ci --test_output=errors
test:ci --test_summary=terse

# User configuration if present
try-import %workspace%/../../.bazelrc.user
try-import %workspace%/.bazelrc.user
47 changes: 47 additions & 0 deletions tools/setup_buildbuddy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
set -euo pipefail

# Unifies the creation of .bazelrc.user containing BuildBuddy configuration
# for the root workspace and nested workspaces (e2e/*).

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
cd "${REPO_ROOT}"

ENDPOINT="${1:-${BUILDBUDDY_ENDPOINT:-}}"
ENDPOINT="${ENDPOINT%/}"
API_KEY="${2:-${BUILDBUDDY_TOKEN:-${BUILDBUDDY_API_KEY:-}}}"

if [ -z "${ENDPOINT}" ] || [ -z "${API_KEY}" ]; then
echo "Usage: $0 [<endpoint> <api-key>] (or set BUILDBUDDY_ENDPOINT and BUILDBUDDY_TOKEN)" >&2
exit 1
fi

config_profile="buildbuddy-rbe"
if [ "$(uname -s)" != "Linux" ]; then
config_profile="buildbuddy"
fi

write_buildbuddy_rc() {
local target_file="$1"
local profile="$2"

cat <<EOF > "${target_file}"
common --config=${profile}
common:buildbuddy --bes_backend=grpcs://${ENDPOINT}
common:buildbuddy --bes_results_url=https://${ENDPOINT}/invocation/
common:buildbuddy --remote_cache=grpcs://${ENDPOINT}
EOF
if [ "${profile}" = "buildbuddy-rbe" ]; then
echo "common:buildbuddy-rbe --remote_executor=grpcs://${ENDPOINT}" >> "${target_file}"
fi
echo "common:buildbuddy --remote_header=x-buildbuddy-api-key=${API_KEY}" >> "${target_file}"
}

write_buildbuddy_rc ".bazelrc.user" "${config_profile}"

for suite in e2e/*; do
if [ -d "${suite}" ]; then
write_buildbuddy_rc "${suite}/.bazelrc.user" "buildbuddy"
fi
done