SERVER-96685 Add first implementation of bazel profiles (#29480)

GitOrigin-RevId: 91a35c5400db7820fbbac664aa85d98bac18c92f
This commit is contained in:
Andrew Bradshaw 2024-12-06 15:40:07 -08:00 committed by MongoDB Bot
parent 5b3e68a06c
commit 4c9314cb6c
7 changed files with 271 additions and 10 deletions

View File

@ -82,6 +82,99 @@ build --flag_alias=msan=//bazel/config:msan
build --flag_alias=lsan=//bazel/config:lsan
build --flag_alias=tsan=//bazel/config:tsan
build --flag_alias=ubsan=//bazel/config:ubsan
build --flag_alias=dbg_level=//bazel/config:dbg_level
#############################################################################################################################
# BUILD 'PROFILES' - this is the area to set up configurations of flags to be used by developers
# It is above more hardware specific configurations so hardware limitations can override some options
# in these profiles. These represent the only supported flag configurations, and should be the only thing
# passed on the command line in most scenarios.
# Every profile should explicitly specify every option used by every other profile, with the exception of the
# profile modifiers
# The base profiles are fast, opt and debug - these reflect the output directories artifacts will get placed into
# and match the bazel compilation modes
# Should a profile modify another profile, it should be named {original_profile}_{modifier_name} - example fast_static
# Current Profiles:
# fastbuild
# dbg
# dbg_san
# dbg_tsan
# opt
# The 'default' build profile - should match all the settings of a profile, currently fastbuild
build -c fastbuild
build --//bazel/config:opt=off
build --//bazel/config:dbg=True
build --//bazel/config:dbg_level=1
build --//bazel/config:debug_symbols=True
build --//bazel/config:separate_debug=False
build --//bazel/config:compiler_type=clang
build --//bazel/config:linkstatic=True
build --//bazel/config:build_enterprise=True
build --//bazel/config:release=False
# Profile for building fast with minimal debuggability - the build is fast ##################################################
build:fastbuild -c fastbuild
build:fastbuild --//bazel/config:opt=off
build:fastbuild --//bazel/config:dbg=True
build:fastbuild --//bazel/config:dbg_level=1
build:fastbuild --//bazel/config:debug_symbols=True
build:fastbuild --//bazel/config:separate_debug=False
build:fastbuild --//bazel/config:compiler_type=clang
build:fastbuild --//bazel/config:linkstatic=True
build:fastbuild --//bazel/config:build_enterprise=True
build:fastbuild --//bazel/config:release=False
# Profile for building highly debuggable code - the build is slow, the code is slow, the binaries are large #################
build:dbg -c dbg
build:dbg --//bazel/config:opt=debug
build:dbg --//bazel/config:dbg=True
build:dbg --//bazel/config:dbg_level=2
build:dbg --//bazel/config:debug_symbols=True
build:dbg --//bazel/config:separate_debug=False
build:dbg --//bazel/config:compiler_type=clang
build:dbg --//bazel/config:linkstatic=True
build:dbg --//bazel/config:build_enterprise=True
build:dbg --//bazel/config:release=False
# Build with address and undefined sanitizers
build:dbg_aubsan --config=dbg
build:dbg_aubsan --//bazel/config:linkstatic=False
build:dbg_aubsan --//bazel/config:allocator=system
build:dbg_aubsan --//bazel/config:asan=True
build:dbg_aubsan --//bazel/config:ubsan=True
# Build with thread sanitizers
build:dbg_tsan --config=dbg
build:dbg_tsan --//bazel/config:linkstatic=False
build:dbg_tsan --//bazel/config:allocator=system
build:dbg_tsan --//bazel/config:tsan=True
build:dbg_tsan --//bazel/config:libunwind=off
# Profile for building optimized code - the build is slow, the code is fast #################################################
build:opt -c opt
build:opt --//bazel/config:opt=on
build:opt --//bazel/config:dbg=False
build:opt --//bazel/config:dbg_level=2
build:opt --//bazel/config:debug_symbols=True
build:opt --//bazel/config:separate_debug=False
build:opt --//bazel/config:compiler_type=clang
build:opt --//bazel/config:linkstatic=True
build:opt --//bazel/config:build_enterprise=True
build:opt --//bazel/config:release=False
# TODO: Build the code as we would release it
# build:opt_release --config=opt
# build:opt_release --//bazel/config:separate_debug=True
# build:opt_release --//bazel/config:build_enterprise=True
# build:opt_release --//bazel/config:release=True
# TODO: Open Source community build flags
# build:community
#############################################################################################################################
--config=remote_link
build:remote_link --strategy=CppLink=remote
@ -137,8 +230,9 @@ common --remote_upload_local_results=False
# Settings specific for clang-tidy
--config=clang-tidy
build:clang-tidy --config=dbg
build:clang-tidy --build_tag_filters=-third_party,-mongo-tidy-tests
build:clang-tidy --//bazel/config:compiler_type=clang
build:clang-tidy --build_tag_filters=-mongo-tidy-tests
build:clang-tidy --aspects @bazel_clang_tidy//clang_tidy:clang_tidy.bzl%clang_tidy_aspect
build:clang-tidy --output_groups=report
build:clang-tidy --@bazel_clang_tidy//:clang_tidy_config=//:clang_tidy_config

View File

@ -8,6 +8,7 @@ load(
"build_grpc",
"compiler_type",
"dbg",
"dbg_level",
"debug_symbols",
"detect_odr_violations",
"developer_dir",
@ -405,6 +406,75 @@ config_setting(
},
)
# ==========
# dbg_level
# ==========
dbg_level(
name = "dbg_level",
build_setting_default = "2",
)
config_setting(
name = "dbg_level_0",
flag_values = {
"//bazel/config:dbg_level": "0",
},
)
config_setting(
name = "dbg_level_1",
flag_values = {
"//bazel/config:dbg_level": "1",
},
)
config_setting(
name = "dbg_level_2",
flag_values = {
"//bazel/config:dbg_level": "2",
},
)
config_setting(
name = "dbg_level_3",
flag_values = {
"//bazel/config:dbg_level": "3",
},
)
selects.config_setting_group(
name = "gcc_or_clang_dbg_level_0",
match_all = [
":gcc_or_clang",
":dbg_level_0",
],
)
selects.config_setting_group(
name = "gcc_or_clang_dbg_level_1",
match_all = [
":gcc_or_clang",
":dbg_level_1",
],
)
selects.config_setting_group(
name = "gcc_or_clang_dbg_level_2",
match_all = [
":gcc_or_clang",
":dbg_level_2",
],
)
selects.config_setting_group(
name = "gcc_or_clang_dbg_level_3",
match_all = [
":gcc_or_clang",
":dbg_level_3",
],
)
# =========
# debug symbols
# =========

View File

@ -393,6 +393,28 @@ dbg = rule(
build_setting = config.bool(flag = True),
)
# ==========
# dbg_level
# ==========
dbg_level_values = ["0", "1", "2", "3"]
dbg_level_provider = provider(
doc = "Sets the level of debug information generated.",
fields = ["level"],
)
def dbg_level_support_impl(ctx):
dbg_level_value = ctx.build_setting_value
if dbg_level_value not in dbg_level_values:
fail(str(ctx.label) + "dbg_level allowed to take values {" + ", ".join(dbg_level_values) + "} but was set to unallowed value " + dbg_level_value)
return dbg_level_provider(level = dbg_level_value)
dbg_level = rule(
implementation = dbg_level_support_impl,
build_setting = config.string(flag = True),
)
# =========
# debug symbols
# =========

View File

@ -658,6 +658,23 @@ DWARF_VERSION_FEATURES = select({
"//conditions:default": [],
})
# Set the debug level for copts and linker
DEBUG_LEVEL_FEATURES = select({
"//bazel/config:gcc_or_clang_dbg_level_0": [
"g0",
],
"//bazel/config:gcc_or_clang_dbg_level_1": [
"g1",
],
"//bazel/config:gcc_or_clang_dbg_level_2": [
"g2",
],
"//bazel/config:gcc_or_clang_dbg_level_3": [
"g3",
],
"//conditions:default": [],
})
# SERVER-9761: Ensure early detection of missing symbols in dependent libraries
# at program startup. For non-release dynamic builds we disable this behavior in
# the interest of improved mongod startup times. Xcode15 removed bind_at_load
@ -1348,7 +1365,7 @@ MONGO_GLOBAL_LINKFLAGS = (
MONGO_GLOBAL_ADDITIONAL_LINKER_INPUTS = SYMBOL_ORDER_FILES
MONGO_GLOBAL_FEATURES = GDWARF_FEATURES + DWARF_VERSION_FEATURES + OVERLOADED_VIRTUAL_FEATURES + DISABLE_DEBUGGING_SYMBOLS_FEATURE
MONGO_GLOBAL_FEATURES = GDWARF_FEATURES + DWARF_VERSION_FEATURES + DEBUG_LEVEL_FEATURES + OVERLOADED_VIRTUAL_FEATURES + DISABLE_DEBUGGING_SYMBOLS_FEATURE
MONGO_COPTS_THIRD_PARTY = UBSAN_OPTS_THIRD_PARTY
@ -1505,6 +1522,9 @@ def mongo_cc_library(
else:
enterprise_compatible = []
if "third_party" in native.package_name():
tags = tags + ["third_party"]
if "compile_requires_large_memory_gcc" in tags:
exec_properties |= select({
"//bazel/config:gcc_x86_64": {

View File

@ -504,13 +504,45 @@ def _impl(ctx):
],
)
enable_debug_info_feature = feature(
name = "enable_debug_info",
dbg_level_0_feature = feature(
name = "g0",
enabled = False,
flag_sets = [
flag_set(
actions = all_non_assembly_compile_actions,
flag_groups = [
flag_group(
flags = [
"-g0",
],
),
],
),
],
)
dbg_level_1_feature = feature(
name = "g1",
enabled = False,
flag_sets = [
flag_set(
actions = all_non_assembly_compile_actions,
flag_groups = [
flag_group(
flags = [
"-g1",
],
),
],
),
],
)
dbg_level_2_feature = feature(
name = "g2",
enabled = True,
flag_sets = [
flag_set(
# This needs to only be set in the cpp compile actions to avoid generating debug info when
# building assembly files since the assembler doesn't support gdwarf64.
actions = all_non_assembly_compile_actions,
flag_groups = [
flag_group(
@ -521,7 +553,24 @@ def _impl(ctx):
],
with_features = [
with_feature_set(
not_features = ["disable_debug_symbols"],
not_features = ["g0", "g1", "g3", "disable_debug_symbols"],
),
],
),
],
)
dbg_level_3_feature = feature(
name = "g3",
enabled = False,
flag_sets = [
flag_set(
actions = all_non_assembly_compile_actions,
flag_groups = [
flag_group(
flags = [
"-g3",
],
),
],
),
@ -737,11 +786,16 @@ def _impl(ctx):
includes_feature,
dependency_file_feature,
verbose_feature,
enable_debug_info_feature,
dwarf4_feature,
dwarf5_feature,
dwarf32_feature,
dwarf64_feature,
# Debug level should be passed after dwarf
# as many dwarf flags will just set g2
dbg_level_0_feature,
dbg_level_1_feature,
dbg_level_2_feature,
dbg_level_3_feature,
disable_debug_symbols_feature,
no_warn_non_virtual_destructor_feature,
no_deprecated_enum_enum_conversion_feature,

View File

@ -33,8 +33,8 @@ BAZEL_BINARY=bazel
# Print command being run to file that can be uploaded
echo "python buildscripts/install_bazel.py" > bazel-invocation.txt
echo "bazel coverage --verbose_failures $LOCAL_ARG ${args} ${target}" >> bazel-invocation.txt
echo "bazel coverage --verbose_failures --config=dbg $LOCAL_ARG ${args} ${target}" >> bazel-invocation.txt
eval $BAZEL_BINARY coverage --verbose_failures $LOCAL_ARG ${args} ${target}
eval $BAZEL_BINARY coverage --verbose_failures --config=dbg $LOCAL_ARG ${args} ${target}
exit $RET

View File

@ -1105,6 +1105,7 @@ def generate(env: SCons.Environment.Environment) -> None:
distro_or_os = distro_id
bazel_internal_flags = [
"--config=dbg",
f"--compiler_type={env.ToolchainName()}",
f'--opt={env.GetOption("opt")}',
f'--dbg={env.GetOption("dbg") == "on"}',