# Reference docs: https://bazel.build/run/bazelrc

# Don't use legacy toolchain resolution.
common --incompatible_enable_cc_toolchain_resolution
# https://github.com/bazelbuild/bazel/issues/8766
# there is WIP to allow users to inject constraints
# this flag is required because the default for BZLMOD is @platform//host:host
build --platforms=@internal_platforms_do_not_use//host
common --enable_workspace=true

# Improves build performance after first clean pull by
# about 1 minute on developer machines
common --experimental_remote_merkle_tree_cache

# Linter will have issues with duplicate configurations due to some of our
# install targets depending on tests that have testonly set. This flag can be removed
# if we stop installing our test targets.
common --experimental_retain_test_configuration_across_testonly

# Experimental flag to collect system network usage metrics during build
common --experimental_collect_system_network_usage

# allow multiple execution infos to be set
common --incompatible_modify_execution_info_additive

# This makes builds more hermetic by preventing environment variables from leaking into the execution of rules
common --incompatible_strict_action_env=true

# allows us to use python rules. This is needed because of the bug:
# https://github.com/bazelbuild/bazel/issues/4327
common --experimental_inprocess_symlink_creation

# cc_library transitively propagates link opts. The build uses cc_shared_library to avoid this when linking
# dynamically.
common --experimental_cc_shared_library

# Reuse sandboxes to save sandbox execution and deletion times.
common --experimental_reuse_sandbox_directories

# Seeing as we link locally, you'll end up with 99% of the files locally anyways.
# Using remote download all save some build time because it will immediately download an object
# file when it is available, where toplevel will wait until the local linking job needs it
# before starting the download.
common --remote_download_outputs=all

# Files we always want to download for debugging and error checking
common --remote_download_regex=.*\.(dwo|h|cpp)$

# Disable caching of test results by default since many of our tests are non-deterministic.
common --cache_test_results=no

# Stream the test output so users can see the test progression.
common --test_output=streamed

# when using remote asset api, fallback to the direct urls to download
common --experimental_remote_downloader_local_fallback

# Build only what is necessary to run the *_test and test_suite rules that were
# not filtered due to their size, timeout, tag, or language.
test --build_tests_only

# Pin down the OSS LLVM Clang version for MacOS builds.
common:macos --repo_env=LLVM_VERSION=19

# Pin down the Microsoft Visual compiler. If you would like to use
# the default compiler version installed in this host, comment the line.
common:windows --repo_env=BAZEL_VS="C:/Program Files/Microsoft Visual Studio/2022/Professional"
common:windows --repo_env=BAZEL_VC="C:/Program Files/Microsoft Visual Studio/2022/Professional/VC"
common:windows --repo_env=BAZEL_VC_FULL_VERSION=14.31.31103
# Pin the Windows SDK used by the Bazel MSVC toolchain. Override with
# --repo_env=BAZEL_WINSDK_FULL_VERSION=<sdk-version> on the command line.
common:windows --repo_env=BAZEL_WINSDK_FULL_VERSION=10.0.20348.0

# Default the Visual C Redistribution to v14.3 for Windows installer.
common:windows --repo_env=MONGO_VC_REDIST_FULL_VERSION=v143


# while in hybrid build state, using local unsandboxed linking should be faster. When most of our link
# targets have been converted (i.e. unittest binaries) and we can BWOB, remote linking should be faster
# in those cases:
common --strategy=CppLink=local
common --strategy=CppArchive=local
common --strategy=SolibSymlink=local
common --strategy=StripDebuginfo=local
common --strategy=ExtractDebuginfo=local
common --strategy=TestRunner=local
common --strategy=CoverageReport=local
common --strategy=CcGenerateIntermediateDwp=local
common --strategy=CcGenerateDwp=local
common --modify_execution_info=^(TestRunner|CppLink|CppArchive|SolibSymlink|ExtractDebuginfo|StripDebuginfo|CcGenerateIntermediateDwp|CcGenerateDwp)$=+no-remote-cache

# Global clang tidy flags to avoid invalidating analysis cache between clang-tidy / regular runs
common --@bazel_clang_tidy//:clang_tidy_excludes=".pb.cc,icu_init.cpp,parser_gen.cpp"
common --@bazel_clang_tidy//:clang_tidy_additional_configs=//:clang_tidy_config_files
common --@bazel_clang_tidy//:clang_tidy_config=//:clang_tidy_config_strict
common --@bazel_clang_tidy//:clang_tidy_merge_tool=//bazel:merge_tidy_configs
common --@bazel_clang_tidy//:clang_tidy_executable=//:clang_tidy
common --@bazel_clang_tidy//:clang_tidy_additional_deps=//:toolchain_files
common --@bazel_clang_tidy//:clang_tidy_plugin_deps=//src/mongo/tools/mongo_tidy_checks:mongo_tidy_checks

# Aliases for config flags
common --flag_alias=linkstatic=//bazel/config:linkstatic
common --flag_alias=compiler_type=//bazel/config:compiler_type
common --flag_alias=linker=//bazel/config:linker
common --flag_alias=use_gdbserver=//bazel/config:use_gdbserver
common --flag_alias=libunwind=//bazel/config:libunwind
common --flag_alias=spider_monkey_dbg=//bazel/config:spider_monkey_dbg
common --flag_alias=allocator=//bazel/config:allocator
common --flag_alias=use_lldbserver=//bazel/config:use_lldbserver
common --flag_alias=opt=//bazel/config:opt
common --flag_alias=dbg=//bazel/config:dbg
common --flag_alias=debug_symbols=//bazel/config:debug_symbols
common --flag_alias=thin_lto=//bazel/config:thin_lto
common --flag_alias=separate_debug=//bazel/config:separate_debug
common --flag_alias=use_wait_for_debugger=//bazel/config:use_wait_for_debugger
common --flag_alias=use_ocsp_stapling=//bazel/config:use_ocsp_stapling
common --flag_alias=use_disable_ref_track=//bazel/config:use_disable_ref_track
common --flag_alias=use_wiredtiger=//bazel/config:use_wiredtiger
common --flag_alias=use_glibcxx_debug=//bazel/config:use_glibcxx_debug
common --flag_alias=use_tracing_profiler=//bazel/config:use_tracing_profiler
common --flag_alias=detect_odr_violations=//bazel/config:detect_odr_violations
common --flag_alias=shared_archive=//bazel/config:shared_archive
common --flag_alias=skip_archive=//bazel/config:skip_archive
common --flag_alias=streams_release_build=//bazel/config:streams_release_build
common --flag_alias=disable_streams=//bazel/config:disable_streams
common --flag_alias=release=//bazel/config:release
common --flag_alias=build_enterprise=//bazel/config:build_enterprise
common --flag_alias=visibility_support=//bazel/config:visibility_support
common --flag_alias=disable_warnings_as_errors=//bazel/config:disable_warnings_as_errors
common --flag_alias=gcov=//bazel/config:gcov
common --flag_alias=pgo_profile=//bazel/config:pgo_profile
common --flag_alias=server_js=//bazel/config:server_js
common --flag_alias=ssl=//bazel/config:ssl
common --flag_alias=js_engine=//bazel/config:js_engine
common --flag_alias=use_sasl_client=//bazel/config:use_sasl_client
common --flag_alias=enterprise_feature_all=//bazel/config:enterprise_feature_all
common --flag_alias=link_timeout=//bazel/config:link_timeout
common --flag_alias=compress_debug_compile=//bazel/config:compress_debug_compile
common --flag_alias=include_mongot=//bazel/config:include_mongot
# This flag will only work if you pass it on the command line as it is parsed by bazelisk pre-bazel script
common --flag_alias=include_autogenerated_targets=//bazel/config:include_autogenerated_targets
common --flag_alias=bolt=//bazel/config:bolt
common --flag_alias=dwarf_version=//bazel/config:dwarf_version
common --flag_alias=http_client=//bazel/config:http_client
common --flag_alias=asan=//bazel/config:asan
common --flag_alias=fsan=//bazel/config:fsan
common --flag_alias=msan=//bazel/config:msan
common --flag_alias=lsan=//bazel/config:lsan
common --flag_alias=tsan=//bazel/config:tsan
common --flag_alias=ubsan=//bazel/config:ubsan
common --flag_alias=dbg_level=//bazel/config:dbg_level
common --flag_alias=mongo_toolchain_version=//bazel/config:mongo_toolchain_version
common --flag_alias=simple_build_id=//bazel/config:simple_build_id
common --flag_alias=create_dwp=//bazel/config:create_dwp
common --flag_alias=win_min_version=//bazel/config:win_min_version

# code ownership configuration
common --define codeowners_add_auto_approve_user=True

# Don't detect the native toolchain on linux, only use the hermetic toolchains.
# Opt out of this by passing --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=0 on the command line.
common:linux --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1

# Avoid failing builds when BES metadata fails to upload.
common --bes_upload_mode=fully_async

# Default distmod if not specified.
common --define=MONGO_DISTMOD=""

# Default if .git directory is not present
common --define=GIT_COMMIT_HASH="nogitversion"

# TODO(WT-12780): delete this once wiredtiger switches to /.bazelrc.evergreen.
try-import %workspace%/.bazelrc.evergreen_engflow_creds

# Evergreen settings, ex. in evergreen this will set the key/cert options for access to the cluster
try-import %workspace%/.bazelrc.evergreen

# local default dev settings
try-import %workspace%/.bazelrc.common_bes

# local default dev settings
try-import %workspace%/.bazelrc.mongo_variables

import %workspace%/.bazelrc.psmdb

# Used for build profiles and any settings a user wants to consistently use
try-import %workspace%/.bazelrc.local

# Flag as built with bazelisk
try-import %workspace%/.bazelrc.bazelisk

test --test_timeout=900

common:macos --copt=-DBOOST_NO_CXX98_FUNCTION_BASE

# Default mongo version
try-import %workspace%/.bazelrc.target_mongo_version

# local git version info (after target_mongo_version so its MONGO_VERSION override wins)
try-import %workspace%/.bazelrc.git

common --flag_alias=use_diagnostic_latches=//bazel/config:use_diagnostic_latches
