common --action_env=BAZEL_CXXOPTS=-std=c++20
common --cxxopt='-std=c++20'
common --copt=-fdiagnostics-color=always
common --test_output=errors
common --test_summary=terse
common --enable_platform_specific_config

# compilation_mode options below are `dbg` (debug symbols) `fastbuild`
# (build as quickly as possible), and `opt` (turn on all optimizations)
common -c fastbuild
common --enable_bzlmod

# prevents changes to PATH from causing a full rebuild
common --incompatible_strict_action_env

# extra flags for hermetic LLVM toolchain
common --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
common --repo_env=BAZEL_DO_NOT_DETECT_SWIFT_TOOLCHAIN=1
common --repo_env=BAZEL_NO_APPLE_CPP_TOOLCHAIN=1
common --@rules_python//python/config_settings:bootstrap_impl=script
# Needed to silence hermetic LLVM build warnings, until this is enabled by
# default in bazel 9
startup --host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1

# BuildBuddy
build --bes_results_url=https://heir.buildbuddy.io/invocation/
build --bes_backend=grpcs://heir.buildbuddy.io
build --workspace_status_command=./scripts/workspace_status.sh
common --noremote_upload_local_results # Uploads logs & artifacts without writing to cache
common --remote_cache=grpcs://heir.buildbuddy.io
common --remote_cache_compression
common --remote_header=x-buildbuddy-api-key=IqGGzfrvMgDJh927qtrw
common --remote_timeout=10m
# Helps prevent disconnects when GHA-hosted runners talk to BuildBuddy
common --grpc_keepalive_time=30s

# Force downloading of TableGen-generated files (.inc) for local debugging and
# IDE autocompletion support.
build --remote_download_regex=".*\.inc$"

# This enables remote build execution and writing to the remote cache, which
# dramatically speeds up builds. Add a .bazelrc.user file with:
#
#     common --remote_header=x-buildbuddy-api-key=<YOUR_API_KEY>
#     common --config=remote
#
# Note this requires a buildbuddy.io account and API key. The default
# API key used above is read-only.
common:remote --extra_execution_platforms=@llvm//:rbe_platform
common:remote --jobs=500
common:remote --remote_executor=grpcs://remote.buildbuddy.io

# CI executions are always remote, and have extra build metadata
common:ci --build_metadata=ROLE=CI
common:ci --build_metadata=VISIBILITY=PUBLIC

# Only show warnings for targets defined in HEIR code.
# Warnings for external repos and generated code is (mostly) hidden; see #2616
build --output_filter="^//(benchmark|frontend|lib|tests|tools)/"

# use lld for faster linking
build:linux --linkopt="-fuse-ld=lld"

# This is needed for golang targets with the hermetic build, when a golang
# target links with a C++ lib.
build:linux --linkopt="-Wl,-no-pie"

# CHEDDAR GPU FHE backend (opt-in, requires CUDA). CHEDDAR's CUDA sources are
# compiled with the hermetic clang toolchain via rules_cuda.
build:cheddar --//:enable_cheddar=1
build:cheddar --extra_toolchains=@cuda//toolchain:all
build:cheddar --@rules_cuda//cuda:compiler=clang
# Compile CUDA with the hermetic clang from the configured cc_toolchain
# (instead of rules_cuda's `which clang` fallback).
build:cheddar --repo_env=CUDA_COMPILER_USE_CC_TOOLCHAIN=true
build:cheddar --@rules_cuda//cuda:copts=-D_ALLOW_UNSUPPORTED_LIBCPP
build:cheddar --@rules_cuda//cuda:copts=-D_LIBCPP_NO_ABI_TAG
build:cheddar --@rules_cuda//cuda:copts=-D_VSTD=std
build:cheddar --@rules_cuda//cuda:copts=-DSPDLOG_FMT_EXTERNAL
build:cheddar --@rules_cuda//cuda:archs=sm_60,sm_61,sm_70,sm_75,sm_80,sm_86,sm_89,sm_90

# macos specific options
# openmp is not supported in apple clang
build:macos --@openfhe//:enable_openmp=False
build:macos --no@fuzztest//fuzztest:use_riegeli

# MacOS arm64 config
build:macos_arm64 --cpu=darwin_arm64
build:macos_arm64 --macos_minimum_os=11.0
# openmp is not supported in apple clang
build:macos_arm64 --@openfhe//:enable_openmp=False

# run with --config=asan to enable
build:asan --strip=never
build:asan --copt -fsanitize=address
build:asan --copt -DADDRESS_SANITIZER
build:asan --copt -O1
build:asan --copt -g
build:asan --copt -fno-omit-frame-pointer
build:asan --linkopt -fsanitize=address

# Redirect pocketfft's flaky gitlab.mpcdf.mpg.de download to the byte-identical
# GitHub mirror. See bazel/download_config.cfg.
common --downloader_config=bazel/download_config.cfg

try-import %workspace%/fuzztest.bazelrc

# Load any settings specific to the current user.
# .bazelrc.user should appear in .gitignore so that settings are not shared with team members
# This needs to be last statement in this
# config, as the user configuration should be able to overwrite flags from this file.
# See https://docs.bazel.build/versions/master/best-practices.html#bazelrc
try-import %workspace%/.bazelrc.user
