# Apply the build:<os> groups below automatically, keyed on the host OS, so the
# right C++ flags reach clang/gcc (Linux, macOS) versus MSVC (Windows) without
# every invocation having to pass --config.
common --enable_platform_specific_config

# C++17 for every C++ compile, spelled for the active compiler: clang/gcc take
# -std=c++17, MSVC takes /std:c++17.
build:linux --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
build:macos --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
build:windows --cxxopt=/std:c++17 --host_cxxopt=/std:c++17

# MSVC only does the two-phase name lookup the standard asks for under
# /permissive-, which C++17 does not turn on by default. Without it, a
# dependent call in a template is resolved against everything declared by the
# end of the translation unit rather than what the template's definition could
# see, which makes the generated per-enum encoders ambiguous with the ones the
# collection encoders reach by argument dependent lookup.
build:windows --cxxopt=/permissive- --host_cxxopt=/permissive-

# The LLVM toolchain adds -stdlib=libc++ to every C++ compile; clang treats it as
# a link-phase flag and warns it is "unused during compilation" on each .cc file
# (noisy across the third-party gtest/protobuf builds). Suppress that one benign
# warning for both the target and exec (`[for tool]`) configurations. MSVC does
# not use libc++, so Windows omits it.
build:linux --cxxopt=-Wno-unused-command-line-argument --host_cxxopt=-Wno-unused-command-line-argument
build:macos --cxxopt=-Wno-unused-command-line-argument --host_cxxopt=-Wno-unused-command-line-argument

# The clang driver searches the host GCC installs, and warns when the newest one
# has no libstdc++ headers. The build uses libc++, so the choice does not matter.
build:linux --copt=-Wno-gcc-install-dir-libstdcxx --host_copt=-Wno-gcc-install-dir-libstdcxx
build:linux --linkopt=-Wno-gcc-install-dir-libstdcxx --host_linkopt=-Wno-gcc-install-dir-libstdcxx

# Silence warnings in third-party C/C++ sources, such as protobuf and abseil
# using APIs and attributes that newer clang releases deprecate.
build:linux --per_file_copt=external/.*@-w --host_per_file_copt=external/.*@-w
build:macos --per_file_copt=external/.*@-w --host_per_file_copt=external/.*@-w

# The LLVM toolchain turns on clang's thread-safety analysis, and libc++ annotates
# std::lock_guard for it. The C++ client's RecursiveMutex carries no capability
# annotations, so each lock adopted after a try_lock reads as not held.
build:linux --copt=-Wno-thread-safety-analysis --host_copt=-Wno-thread-safety-analysis
build:macos --copt=-Wno-thread-safety-analysis --host_copt=-Wno-thread-safety-analysis

# Build and run java against the JDK bazel downloads, so the toolchain does not depend
# on what is installed. The language version is the oldest release the client can be built
# for, and so the oldest one it runs on: unix domain sockets arrived in Java 16, and 17 is
# the oldest release a toolchain is registered for. The tool_ variants say the same for
# anything built to be run by the build itself, such as the client jar staged into the
# client test harness.
build --java_runtime_version=remotejdk_25
build --java_language_version=17
build --tool_java_runtime_version=remotejdk_25
build --tool_java_language_version=17

# rules_python's default launcher is itself a python script, so every py_binary
# and py_test starts under whatever python3 sits on PATH before handing over to
# the interpreter the build fetched. The script launcher goes straight to that
# one, which leaves no system python in the build at all -- and none to find on
# a Windows runner, which has no python3 on PATH to start with.
common --@rules_python//python/config_settings:bootstrap_impl=script

# Python packages carry their own __init__.py files, so rules_python does not
# create them. This covers the py targets in other modules too.
common --incompatible_default_to_explicit_init_py

# Pin the locale for build actions and tests. Several tools change behaviour with
# it: the code generators read and write UTF-8 sources, C and Lua case folding and
# number formatting go through the C library, and .NET formats numbers using the
# ambient culture. Without this the output depends on whoever runs the build, and
# CI (which has no LANG set, so runs under POSIX) disagrees with a developer
# machine that does.
build --action_env=LC_ALL=C.UTF-8
build --host_action_env=LC_ALL=C.UTF-8
test --test_env=LC_ALL=C.UTF-8

# Windows: rules_dotnet (and the symlink-based staging rules) need real symlinks
# and runfiles trees. The startup flag is a no-op off Windows; the windows config
# group is auto-selected on Windows hosts (and CI also passes --config=windows).
startup --windows_enable_symlinks
common:windows --enable_runfiles

# rules_cc misdetects recent MSVC toolchains as supporting /DEBUG:FASTLINK and
# links fastbuild binaries with it, warning LNK4315 on every link as it falls
# back to /DEBUG:FULL. Build in dbg mode, whose debug flag is the supported
# /DEBUG:FULL, so the warning never fires. The Windows job only builds and
# smoke-tests, so the mode does not matter otherwise.
build:windows --compilation_mode=dbg

# Build the C/C++ clients against a system LLVM instead of downloading the ~2 GB
# hermetic LLVM release. Selects system clang-tidy/clang-format/libc++ (via the
# flag) and the system C++ compiler toolchain (via --extra_toolchains, which
# outranks the registered hermetic toolchain). Requires an LLVM install at the
# path in MODULE.bazel's llvm.toolchain_root (present in the buildenv image).
# CI activates this in the container bazelrc; dev can pass it to reproduce CI.
common:system-llvm --//tools/build/llvm:toolchain=system
common:system-llvm --extra_toolchains=@llvm_system//:all
