Skip to content

Instantly share code, notes, and snippets.

View alexeagle's full-sized avatar
🌿
Making a better Bazel

Alex Eagle alexeagle

🌿
Making a better Bazel
View GitHub Profile
@alexeagle
alexeagle / bazel-input-weight.sh
Last active July 14, 2026 18:28
Rank a Bazel test target's action inputs by on-disk size, grouped by owning package/repo — find which deps bloat runfiles (slow remote-cache downloads)
#!/usr/bin/env bash
# Rank a Bazel target's output artifacts by size, grouped by owning package/repo,
# so a product engineer sees WHICH deps bloat their test's inputs/runfiles — the
# thing that makes EngFlow remote-cache downloads slow.
#
# Sizes come from the CAS digests in the Build Event Protocol, NOT from disk:
# every BEP file entry has a `bytestream://<host>/blobs/<hash>/<SIZE>` URI, and a
# Bazel Digest is {hash, size_bytes} — the size IS the last path segment. So this
# works under `--remote_download_minimal` (build-without-the-bytes) with zero byte
# downloads and no local stat. (CAS has no "size of hash X" RPC; you read the size
@alexeagle
alexeagle / lint.sh
Created December 21, 2025 16:09
Wrap 'bazel build' to run linting aspects, without using Aspect CLI
#!/usr/bin/env bash
#
# Shows an end-to-end workflow for linting without failing the build.
# This is meant to mimic the behavior of the `aspect lint` command that you'd have
# by using the Aspect CLI [lint task](https://github.com/aspect-build/rules_lint/blob/main/lint/lint.axl).
#
# To make the build fail when a linter warning is present, run with `--fail-on-violation`.
# To auto-fix violations, run with `--fix` (or `--fix --dry-run` to just print the patches)
set -o errexit -o pipefail -o nounset
action_cache
action_env
adb
adb_arg
all
allow_analysis_cache_discard
allow_analysis_failures
allow_yanked_versions
allowed_cpu_values
analysis_testing_deps_limit
#!/bin/bash
set -euo pipefail
bazel 2>/dev/null build --build_runfile_links @yq
YQ=$(bazel 2>/dev/null info execution_root)/$(bazel 2>/dev/null cquery --output=files @yq)
for pkg in $($YQ eval '
(.importers.".".dependencies // {}
+ .importers.".".devDependencies // {}
+ .importers.".".optionalDependencies // {})
| to_entries
@alexeagle
alexeagle / BUILD.in
Created March 5, 2025 23:39
Gazelle test fixture
# empty
load("@deps-test//my:rules.bzl", "x_lib")
x_lib(
name = "a_lib",
testonly = True,
srcs = ["a.json"],
deps = [
":b_lib",
"//lib:l_lib",
],
BZL_LIBRARY = "bzl_library"
LANG_NAME = "starlark"
BZL_EXT = ".bzl"
aspect.register_rule_kind(BZL_LIBRARY, {
"From": "@bazel_skylib//:bzl_library.bzl",
"NonEmptyAttrs": ["srcs"],
"MergeableAttrs": ["srcs"],
"ResolveAttrs": ["deps"],
"""
rules_kotlin support for 'aspect configure'
"""
KT_JVM_LIBRARY = "kt_jvm_library"
KT_JVM_BINARY = "kt_jvm_binary"
RULES_KOTLIN_REPO_NAME = "io_bazel_rules_kotlin"
PROVIDER_NAME = "kt"
LANG_NAME = "kotlin"
"""
rules_kotlin support for 'aspect configure'
"""
KT_JVM_LIBRARY = "kt_jvm_library"
KT_JVM_BINARY = "kt_jvm_binary"
RULES_KOTLIN_REPO_NAME = "io_bazel_rules_kotlin"
PROVIDER_NAME = "kt"
LANG_NAME = "kotlin"
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
# Bash installation script for https://github.com/choffmeister/git-describe-semver utility
# for use in --workspace_status command. We can't carry a bazel run dependency on this tool
# since we need to use it in --workspace_status.
git_describe_semver_url_base="https://github.com/choffmeister/git-describe-semver/releases/download"
git_describe_semver_version=0.3.9