# Optimized build with symbolized, reliable call stacks for sampling profilers.
build:profiling --compilation_mode=opt
build:profiling --strip=never
build:profiling --copt=-g
build:profiling --copt=-fno-omit-frame-pointer
build:profiling --copt=-fno-optimize-sibling-calls

# AddressSanitizer: use-after-free, heap/stack overflow and leaks.
# Usage: bazel test --config=asan //test:all
build:asan --strip=never
# gRPC and googleapis both expose generated UPB globals. Loading their dynamic
# copies together makes ASan report ODR violations before a test can start.
build:asan --dynamic_mode=off
build:asan --copt=-fsanitize=address
build:asan --copt=-g
build:asan --copt=-fno-omit-frame-pointer
build:asan --linkopt=-fsanitize=address
build:asan --test_env=ASAN_OPTIONS=abort_on_error=1
build:asan --test_timeout=900

# ThreadSanitizer: data races across the agent's worker threads, queues and caches.
# Usage: bazel test --config=tsan //test:all
build:tsan --strip=never
build:tsan --copt=-fsanitize=thread
build:tsan --copt=-g
build:tsan --copt=-fno-omit-frame-pointer
build:tsan --linkopt=-fsanitize=thread
build:tsan --test_env=TSAN_OPTIONS=halt_on_error=1:suppressions=scripts/tsan.supp
build:tsan --test_timeout=900

# UndefinedBehaviorSanitizer: UB such as out-of-range float->int casts and signed
# overflow. Halts on the first error (-fno-sanitize-recover) so CI fails loudly.
# Usage: bazel test --config=ubsan //test:all
build:ubsan --repo_env=CC=clang
build:ubsan --repo_env=CXX=clang++
build:ubsan --action_env=CC=clang
build:ubsan --action_env=CXX=clang++
build:ubsan --strip=never
build:ubsan --copt=-fsanitize=undefined
build:ubsan --copt=-fno-sanitize-recover=undefined
build:ubsan --copt=-g
build:ubsan --copt=-fno-omit-frame-pointer
build:ubsan --linkopt=-fsanitize=undefined
# compiler-rt supplies builtins ARM64 libgcc is missing, but selecting it leaves
# Clang with no unwinder by default while the sanitizer runtime calls _Unwind_*,
# so name the unwinder too. Unlike the CMake build this cannot be arch-gated in
# a bazelrc; naming libgcc is a no-op where it was already the default.
build:ubsan --linkopt=--rtlib=compiler-rt
build:ubsan --linkopt=--unwindlib=libgcc
build:ubsan --linkopt=-fsanitize-link-c++-runtime
build:ubsan --test_env=UBSAN_OPTIONS=halt_on_error=1:print_stacktrace=1
build:ubsan --test_timeout=900
