bazel__book/rc.md

2.3 KiB

RC files

RC files define configuration about how to interpret the contents of MODULE.bazel

They are loaded in order of precedence: the lates version of a declaration wins.

  1. /etc/bazel.bazelrc (Linux/macOS) or %ProgramData%\baze.bazelrc (Windows).
    • Machine-wide settings, like remote cache endpoints for all users on a build agent
    • Can be skipped with --nosystem_rc
  2. Workspace RC file: $workspace/.bazelrc, next to $workspace/MODULE.bazel.
    • The source of truth for the project, committed to VCS
    • Can be skipped with --noworkspace_rc
  3. Home RC file: $HOME/.bazelrc. User-specific settings, like:
    • name for workspace_status
    • enabling --announce_rc
    • Can be skipped with --nohome_rc
  4. Command line flags.
    • --bazelrc=/dev/null is a trick to disable all RC files
# --- RESOURCE TUNING ---
# Apple Silicon (M2/M3/M4) has high core counts; 
# adjust jobs to 1.5x your performance cores for optimal throughput
# 8 performance cores on M1 Max -> 12 jobs
build --jobs=12 

# --- LOCAL TESTING ---
# Useful for debugging MongoDB or Go tests locally without timeouts
test --test_verbose_timeout_warnings
test --test_output=errors

# --- FRENCH DEVELOPER CONTEXT ---
# If your internal proxy/registry requires specific local certs or env vars
# build --action_env=HTTPS_PROXY=http://localhost:8080
# --- MODULE RESOLUTION ---
# Point to your internal registry first, then fallback to BCR
common --registry=https://bazel-registry.internal.corp
common --registry=https://bcr.bazel.build     # Default: made explicit for clarity

# --- STRICTNESS & HERMETICITY ---
# Enforce strict environment variables (avoids "works on my machine" bugs)
build --incompatible_strict_action_env
common --enable_bzlmod # Force Bzlmod (redundant in Bazel 9 but good for documentation)  

# --- CACHING ---
# Enable local disk cache (separate from the install base)
# Possibly better: move it to the ~/.bazelrc to reuse artifacts across projects
# Avoid using `~`.
build --disk_cache=${HOME}/.cache/bazel-disk-cache

# --- UI & LOGGING ---n
common --color=yes
common --show_progress_rate_limit=5

# --- LOCAL OVERRIDES ---
# This allows you to have a personal file that isn't tracked by Git
try-import %workspace%/user.bazelrc