# =============================================================================
# Common Settings
# =============================================================================
# Re-enable autoloading for BCR deps (e.g. googletest 1.17.0) that still rely
# on the legacy native cc_library/cc_test globals removed in Bazel 9.
build --incompatible_autoload_externally=+@rules_cc,+@rules_python,+@rules_shell

common --enable_platform_specific_config

# Do NOT auto-synthesize empty __init__.py files into Python runfiles. The
# legacy behavior turns every directory (including each wheel's `sphinxcontrib/`)
# into a regular package, which shadows the PEP 420 `sphinxcontrib` namespace
# shared across the `sphinxcontrib-*` wheels Sphinx depends on.
build --incompatible_default_to_explicit_init_py

# =============================================================================
# C++ Compiler Settings
# =============================================================================
build --cxxopt=-std=c++20
build --host_cxxopt=-std=c++20

# =============================================================================
# Release Config (opt + strip)
# =============================================================================
# Without an explicit compilation_mode, Bazel defaults to `fastbuild` (-O0).
# Make optimized builds the default here too. Use --config=debug to opt out.
build:release --compilation_mode=opt
build:release --copt=-O3
build:release --copt=-DNDEBUG
build:release --strip=always

build --config=release
test  --config=release
run   --config=release

# =============================================================================
# Debug Config (Opt-in: --config=debug)
# =============================================================================
build:debug --compilation_mode=dbg
build:debug --copt=-O0
build:debug --copt=-g3
build:debug --strip=never
build:debug --copt=-fno-omit-frame-pointer
build:debug --verbose_failures

# =============================================================================
# Developer Experience
# =============================================================================
build --color=yes
build --show_timestamps
build --announce_rc
test  --test_output=errors

# =============================================================================
# Sandbox (macOS needs /var/tmp mounted into the sandbox for some toolchains)
# =============================================================================
build:macos --sandbox_add_mount_pair=/var/tmp
build:linux --sandbox_add_mount_pair=/tmp
build:windows --sandbox_add_mount_pair=C:\Temp

# =============================================================================
# Hermetic Cross-Compilation Config (Opt-in: --config=hermetic)
# =============================================================================
# Use --config=hermetic to enable hermetic cross-compilation with Zig.
# This allows building Linux wheels from macOS and vice versa.
build:hermetic --extra_toolchains=@zig_sdk//toolchain:linux_amd64_gnu.2.28
build:hermetic --extra_toolchains=@zig_sdk//toolchain:linux_arm64_gnu.2.28
build:hermetic --extra_toolchains=@zig_sdk//toolchain:darwin_amd64
build:hermetic --extra_toolchains=@zig_sdk//toolchain:darwin_arm64
build:hermetic --extra_toolchains=@zig_sdk//toolchain:windows_amd64
build:hermetic --extra_toolchains=@zig_sdk//toolchain:windows_arm64

# =============================================================================
# Import Local Settings
# =============================================================================
try-import %workspace%/.bazelrc.local
