Skip to content
Draft
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
33 changes: 18 additions & 15 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# Bazel settings that apply to this repository.
# Take care to document any settings that you expect users to apply.
# Settings that apply only to CI are in .github/workflows/ci.bazelrc
import %workspace%/bazel/defaults.bazelrc

test --test_output=errors

# TODO(alex): enable
common --noenable_bzlmod
test --test_tag_filters=-manual
common --enable_bzlmod

# Define value used by tests
build --define=SOME_VAR=SOME_VALUE
Expand All @@ -15,16 +12,22 @@ common --incompatible_enable_cc_toolchain_resolution
common --per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT
common --host_per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT

# Use local rules_python
# Enable with --config=dev
common:dev --override_repository=rules_python=~/workspace/rules_python
# No external runfiles
common --nolegacy_external_runfiles
# Don't try and auto detect the cc toolchain, as we use our own gcc toolchains.
common --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
common --incompatible_enable_cc_toolchain_resolution

# Don't link against libunwind on macos as it causes linking failures (https://github.com/bazel-contrib/toolchains_llvm/pull/346)
common:macos --@toolchains_llvm//toolchain/config:libunwind=False

common:ci --toolchain_resolution_debug='@@bazel_tools//tools/cpp:toolchain_type'

common:release --stamp
common:release --compilation_mode=opt
common:release --@rules_rust//rust/settings:lto=fat

# Don’t want to push a rules author to update their deps if not needed.
# https://bazel.build/reference/command-line-reference#flag--check_direct_dependencies
# https://bazelbuild.slack.com/archives/C014RARENH0/p1691158021917459?thread_ts=1691156601.420349&cid=C014RARENH0
common --check_direct_dependencies=off
# Speed up local development by using the non-hermetic CPP toolchain.
common:nollvm --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=0
common:nollvm --noincompatible_enable_cc_toolchain_resolution

# Load any settings specific to the current user.
# .bazelrc.user should appear in .gitignore so that settings are not shared with team members
Expand Down
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ docs/virtual_deps.md linguist-generated=false
examples export-ignore

# Substitution for the _VERSION_PRIVATE placeholder
tools/version.bzl export-subst
py/private/release/version.bzl export-subst
25 changes: 18 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,36 @@ permissions:
contents: write
jobs:
build:
# We don't attempt to cross-compile rust binaries from one OS to another.
# So just spin up a runner on each OS to build its binaries.
strategy:
matrix:
# Pin to runner releases since our Rust compile is fiddly with system libs
os: [ubuntu-22.04, macos-13]
# TODO: Can we build from linux to mac? Is there an advantage to going
# in that direction?
os:
- macos-13

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4

- name: Build Rust Binaries
env:
# NB: this variable is read by tools/release/copy_release_artifacts.sh
DEST: artifacts
run: |
rm -rf ${{ env.DEST }}
mkdir -p ${{ env.DEST }}
bazel --bazelrc=.github/workflows/ci.bazelrc \
run --config=release //tools/release:copy_release_artifacts
FLAGS=(--bazelrc=.github/workflows/ci.bazelrc)

# Query for deliver verbs (see bazel/release/release.bzl)
TARGETS=$(bazel $FLAGS query 'attr(tags, "ci:verb:deliver", //...)')

# Run each one of those targets to produce and "deliver" artifacts
# into the target dir.
#
# These delivery targets are expected to lay down <asset> and <asset>.sha256
for target in $TARGETS; do
bazel $FLAGS run $target -- $(realpath ${{ env.DEST }})
done

- uses: actions/upload-artifact@v4
with:
Expand All @@ -49,6 +59,7 @@ jobs:
artifacts-*/*
rules_py-*.tar.gz
tag_name: ${{ github.ref_name }}

publish:
needs: release
uses: ./.github/workflows/publish.yaml
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release_prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ git archive --format=tar --prefix=${PREFIX}/ ${TAG} > $ARCHIVE_TMP
# Now that we've run `git archive` we are free to pollute the working directory.

# Delete the placeholder file
tar --file $ARCHIVE_TMP --delete ${PREFIX}/tools/integrity.bzl
tar --file $ARCHIVE_TMP --delete ${PREFIX}/py/private/release/integrity.bzl

mkdir -p ${PREFIX}/tools
cat >${PREFIX}/tools/integrity.bzl <<EOF
Expand All @@ -32,7 +32,7 @@ RELEASED_BINARY_INTEGRITY = $(jq \
EOF

# Append that generated file back into the archive
tar --file $ARCHIVE_TMP --append ${PREFIX}/tools/integrity.bzl
tar --file $ARCHIVE_TMP --append ${PREFIX}/py/private/release/integrity.bzl

# END patch up the archive
############
Expand Down
2 changes: 1 addition & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
load("@gazelle//:def.bzl", "gazelle", "gazelle_binary")
load("@pypi//:requirements.bzl", "all_whl_requirements")
load("@rules_python//python/pip_install:requirements.bzl", "compile_pip_requirements")
load("@rules_python_gazelle_plugin//:def.bzl", "GAZELLE_PYTHON_RUNTIME_DEPS")
Expand Down
103 changes: 25 additions & 78 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,25 @@ module(
# py_image_layer requires 2.x for the `tar` rule.
# py_image_layer needs compute_unused_inputs attribute
# py_image_layer needs repo_mapping fix.
bazel_dep(name = "aspect_bazel_lib", version = "2.16.0")
bazel_dep(name = "aspect_tools_telemetry", version = "0.2.6")
bazel_dep(name = "bazel_skylib", version = "1.4.2")
bazel_dep(name = "rules_python", version = "0.29.0")
bazel_dep(name = "platforms", version = "0.0.7")
bazel_dep(name = "bazelrc-preset.bzl", version = "1.2.0")

bazel_lib = use_extension("@aspect_bazel_lib//lib:extensions.bzl", "toolchains")
bazel_lib.expand_template()
include("//bazel/include:bazel-lib.MODULE.bazel")

tel = use_extension("@aspect_tools_telemetry//:extension.bzl", "telemetry")
use_repo(tel, "aspect_tools_telemetry_report")
include("//bazel/include:llvm.MODULE.bazel")

# Custom python version for testing only
python = use_extension("@rules_python//python/extensions:python.bzl", "python", dev_dependency = True)
python.toolchain(
is_default = False,
python_version = "3.9",
)
include("//bazel/include:musl.MODULE.bazel")

include("//bazel/include:oci.MODULE.bazel")

include("//bazel/include:rust.MODULE.bazel")

include("//bazel/include:telemetry.MODULE.bazel")

include("//bazel/include:rules-python.MODULE.bazel")

include("//bazel/include:release.MODULE.bazel")

tools = use_extension("//py:extensions.bzl", "py_tools")
tools.rules_py_tools()
Expand All @@ -45,72 +46,18 @@ register_toolchains(
"@aspect_rules_py//py/private/toolchain/shim/...",
)

# To allow Rust binaries in /py/tools to be built from source
# NOTE: when publishing to BCR, we patch these to be dev_dependency, as we publish pre-built binaries
# along with our releases.

bazel_dep(
name = "rules_rust",
version = "0.53.0",
# In released versions: dev_dependency = True
)

rust = use_extension(
"@rules_rust//rust:extensions.bzl",
"rust",
# In released versions: dev_dependency = True
name = "gazelle",
version = "0.45.0",
dev_dependency = True,
)
rust.toolchain(
edition = "2021",
versions = ["1.81.0"],
)
use_repo(rust, "rust_toolchains")

register_toolchains(
"@rust_toolchains//:all",
# In released versions: dev_dependency = True
)

crate = use_extension(
"@rules_rust//crate_universe:extension.bzl",
"crate",
# In released versions: dev_dependency = True
)
crate.from_cargo(
name = "crate_index",
cargo_lockfile = "//:Cargo.lock",
# Apparently not needed under bzlmod?
# lockfile = "//:Cargo.Bazel.lock",
manifests = [
"//:Cargo.toml",
"//py/tools/py:Cargo.toml",
"//py/tools/unpack_bin:Cargo.toml",
"//py/tools/venv_bin:Cargo.toml",
"//py/tools/venv_shim:Cargo.toml",
"//py/tools/runfiles:Cargo.toml",
],
)
use_repo(crate, "crate_index")

# For building test images with py_image_layer
bazel_dep(name = "container_structure_test", version = "1.19.3", dev_dependency = True)
git_override(
module_name = "container_structure_test",
commit = "56c7201716d770c0f820a9c19207ba2ea77c34f8",
remote = "https://github.com/GoogleContainerTools/container-structure-test.git",
bazel_dep(
name = "buildifier_prebuilt",
version = "8.2.0.2",
dev_dependency = True,
)

bazel_dep(name = "rules_oci", version = "2.0.1", dev_dependency = True)

oci = use_extension("@rules_oci//oci:extensions.bzl", "oci", dev_dependency = True)
oci.pull(
name = "ubuntu",
digest = "sha256:80dd3c3b9c6cecb9f1667e9290b3bc61b78c2678c02cbdae5f0fea92cc6734ab",
image = "ubuntu",
platforms = [
"linux/arm64/v8",
"linux/amd64",
],
tag = "latest",
bazel_dep(
name = "bazel_skylib_gazelle_plugin",
version = "1.8.1",
dev_dependency = True,
)
use_repo(oci, "ubuntu", "ubuntu_linux_amd64", "ubuntu_linux_arm64_v8")
Loading
Loading