SERVER-113428 Refactor abseil to use its own build system (#44952)

GitOrigin-RevId: 37e8183a7a77c99b628e8efba83a80299ad9e5b4
This commit is contained in:
Andrew Bradshaw 2025-12-09 13:08:20 -08:00 committed by MongoDB Bot
parent 5414040166
commit d42c2f6ce7
27 changed files with 227 additions and 2937 deletions

View File

@ -11,12 +11,12 @@ http_file = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_
http_archive(
name = "bazel_clang_tidy",
integrity = "sha256-4jSWCC9GXwk4VeqLNZl6heYZUsUqvC8EP1OO+JEVDSA=",
strip_prefix = "bazel_clang_tidy-908bf1af4e5b645a7a897b43552c5e482195ee25",
integrity = "sha256-PLwbo3dS1ZgeuSiaUctGRIU/O3ScB64+U2mEsN7fgtA=",
strip_prefix = "bazel_clang_tidy-1.7",
urls = [
# Implements retry by relisting each url multiple times to be used as a failover.
# TODO(SERVER-86719): Re-implement http_archive to allow sleeping between retries
"https://github.com/mongodb-forks/bazel_clang_tidy/archive/908bf1af4e5b645a7a897b43552c5e482195ee25.tar.gz",
"https://github.com/mongodb-forks/bazel_clang_tidy/archive/refs/tags/v1.7.tar.gz",
] * 5,
)
@ -139,7 +139,7 @@ single_version_override(
version = "1.3.1",
)
bazel_dep(name = "abseil-cpp", version = "", repo_name = "com_google_absl")
bazel_dep(name = "abseil-cpp", version = "20250512.1", repo_name = "com_google_absl")
local_path_override(
module_name = "abseil-cpp",
path = "src/third_party/abseil-cpp/dist",

View File

@ -2,7 +2,6 @@
BUILD files in the "src/" subtree.
"""
load("//bazel/toolchains/cc:mongo_defines.bzl", "MONGO_GLOBAL_DEFINES")
load(
"//bazel/toolchains/cc:mongo_errors.bzl",
"REQUIRED_SETTINGS_LIBUNWIND_ERROR_MESSAGE",
@ -214,7 +213,6 @@ DISABLE_3RD_PARTY_FEATURES = select({
})
MONGO_GLOBAL_SRC_DEPS = [
"//src/third_party/abseil-cpp:absl_base",
"//src/third_party/boost:headers",
"//src/third_party/croaring:croaring",
"//src/third_party/fmt:fmt",
@ -225,7 +223,6 @@ MONGO_GLOBAL_SRC_DEPS = [
"//src/third_party/SafeInt:headers",
"//src/third_party/sasl:windows_sasl",
"//src/third_party/valgrind:headers",
"//src/third_party/abseil-cpp:absl_local_repo_deps",
]
MONGO_GLOBAL_ADDITIONAL_LINKER_INPUTS = SYMBOL_ORDER_FILES
@ -460,7 +457,7 @@ def mongo_cc_library(
"@platforms//os:windows": True,
"//conditions:default": linkstatic,
}),
local_defines = MONGO_GLOBAL_DEFINES + local_defines,
local_defines = local_defines,
defines = defines,
includes = includes,
features = features,
@ -676,7 +673,7 @@ def _mongo_cc_binary_and_test(
"//conditions:default": [],
}),
"linkstatic": LINKSTATIC_ENABLED,
"local_defines": MONGO_GLOBAL_DEFINES + local_defines,
"local_defines": local_defines,
"defines": defines,
"includes": includes,
"features": ["-pic", "pie"] + features + select({

View File

@ -3,6 +3,7 @@ package(default_visibility = ["//visibility:public"])
load("@//bazel/config:configs.bzl", "sdkroot")
load("@//bazel/toolchains/cc/mongo_apple:mongo_apple_toolchain.bzl", "get_supported_apple_archs")
load("@//bazel/toolchains/cc/mongo_apple:mongo_apple_llvm_cc_toolchain_config.bzl", "mongo_apple_llvm_cc_toolchain_config")
load("@//bazel/toolchains/cc:mongo_defines.bzl", "MONGO_GLOBAL_DEFINES")
load(
"@//bazel/toolchains/cc:mongo_custom_features.bzl",
"FEATURES_ATTR_NAMES",
@ -97,12 +98,13 @@ feature_attrs = get_common_features_attrs()
builtin_sysroot = "@//bazel/config:sdkroot",
optimization_level = feature_attrs[FEATURES_ATTR_NAMES.OPT_LEVEL],
debug_level = DEBUG_LEVEL,
supports_start_end_lib = True,
supports_start_end_lib = False,
internal_thin_lto_enabled = INTERNAL_THIN_LTO_ENABLED,
coverage_enabled = COVERAGE_ENABLED,
compress_debug_enabled = COMPRESS_DEBUG_ENABLED,
warnings_as_errors_enabled = WARNINGS_AS_ERRORS_ENABLED,
linkstatic = LINKSTATIC_ENABLED,
global_defines = MONGO_GLOBAL_DEFINES,
)
for arch, cpu in get_supported_apple_archs().items()
]

View File

@ -906,6 +906,7 @@ def _impl(ctx):
external_include_paths_feature = feature(
name = "external_include_paths",
enabled = True,
flag_sets = [
flag_set(
actions = [
@ -1726,6 +1727,7 @@ mongo_apple_llvm_cc_toolchain_config = rule(
"compress_debug_enabled": attr.bool(default = False, mandatory = False),
"warnings_as_errors_enabled": attr.bool(default = True, mandatory = False),
"linkstatic": attr.bool(mandatory = True),
"global_defines": attr.string_list(mandatory = False),
},
fragments = ["apple", "cpp"],
provides = [CcToolchainConfigInfo],

View File

@ -435,4 +435,17 @@ def get_common_features(ctx):
),
],
),
feature(
name = "mongo_defines",
enabled = True,
flag_sets = [
flag_set(
actions = all_compile_actions,
flag_groups = [flag_group(
flags =
["-D" + define for define in ctx.attr.global_defines],
)],
),
],
),
]

View File

@ -2,21 +2,12 @@
"""
load(
"//bazel/toolchains/cc:mongo_errors.bzl",
"@//bazel/toolchains/cc:mongo_errors.bzl",
"GLIBCXX_DEBUG_ERROR_MESSAGE",
"SYSTEM_ALLOCATOR_SANITIZER_ERROR_MESSAGE",
"THREAD_SANITIZER_ERROR_MESSAGE",
)
# Defines are only visible to within //bazel directory where
# toolchains and rules are defined.
# TODO: define mongo_generate_config_header rule to hide
# all the compiler options.
visibility([
"//src/mongo/util",
"//bazel",
])
ABSEIL_DEFINES = [
"ABSL_FORCE_ALIGNED_ACCESS",
]
@ -34,29 +25,29 @@ BOOST_DEFINES = [
"BOOST_THREAD_USES_DATETIME",
"BOOST_THREAD_VERSION=5",
] + select({
"//bazel/config:linkdynamic_not_shared_archive": ["BOOST_LOG_DYN_LINK"],
"//conditions:default": [],
"@//bazel/config:linkdynamic_not_shared_archive": ["BOOST_LOG_DYN_LINK"],
"@//conditions:default": [],
})
ENTERPRISE_DEFINES = select({
"//bazel/config:build_enterprise_enabled": ["MONGO_ENTERPRISE_VERSION=1"],
"//conditions:default": [],
"@//bazel/config:build_enterprise_enabled": ["MONGO_ENTERPRISE_VERSION=1"],
"@//conditions:default": [],
}) + select({
"//bazel/config:enterprise_feature_audit_enabled": ["MONGO_ENTERPRISE_AUDIT=1"],
"//conditions:default": [],
"@//bazel/config:enterprise_feature_audit_enabled": ["MONGO_ENTERPRISE_AUDIT=1"],
"@//conditions:default": [],
}) + select({
"//bazel/config:enterprise_feature_encryptdb_enabled": ["MONGO_ENTERPRISE_ENCRYPTDB=1"],
"//conditions:default": [],
"@//bazel/config:enterprise_feature_encryptdb_enabled": ["MONGO_ENTERPRISE_ENCRYPTDB=1"],
"@//conditions:default": [],
})
FORTIFY_DEFINE = select({
"//bazel/config:opt_on_linux": ["_FORTIFY_SOURCE=3"],
"//conditions:default": [],
"@//bazel/config:opt_on_linux": ["_FORTIFY_SOURCE=3"],
"@//conditions:default": [],
})
DEBUG_DEFINES = select({
"//bazel/config:dbg_enabled": [],
"//conditions:default": ["NDEBUG"],
"@//bazel/config:dbg_enabled": [],
"@//conditions:default": ["NDEBUG"],
})
PCRE2_DEFINES = ["PCRE2_STATIC"]
@ -68,28 +59,28 @@ SAFEINT_DEFINES = ["SAFEINT_USE_INTRINSICS=0"]
# the running compiler. We do this unconditionally because abseil is basically
# pervasive via the 'base' library.
ADDRESS_SANITIZER_DEFINES = select({
"//bazel/config:sanitize_address_required_settings": ["ADDRESS_SANITIZER"],
"//bazel/config:asan_disabled": [],
"@//bazel/config:sanitize_address_required_settings": ["ADDRESS_SANITIZER"],
"@//bazel/config:asan_disabled": [],
}, no_match_error = SYSTEM_ALLOCATOR_SANITIZER_ERROR_MESSAGE)
THREAD_SANITIZER_DEFINES = select({
"//bazel/config:sanitize_thread_required_settings": ["THREAD_SANITIZER"],
"//bazel/config:tsan_disabled": [],
"@//bazel/config:sanitize_thread_required_settings": ["THREAD_SANITIZER"],
"@//bazel/config:tsan_disabled": [],
}, no_match_error = THREAD_SANITIZER_ERROR_MESSAGE)
UNDEFINED_SANITIZER_DEFINES = select({
"//bazel/config:ubsan_enabled": ["UNDEFINED_BEHAVIOR_SANITIZER"],
"//bazel/config:ubsan_disabled": [],
"@//bazel/config:ubsan_enabled": ["UNDEFINED_BEHAVIOR_SANITIZER"],
"@//bazel/config:ubsan_disabled": [],
})
GLIBCXX_DEBUG_DEFINES = select({
("//bazel/config:use_glibcxx_debug_required_settings"): ["_GLIBCXX_DEBUG"],
("//bazel/config:use_glibcxx_debug_disabled"): [],
("@//bazel/config:use_glibcxx_debug_required_settings"): ["_GLIBCXX_DEBUG"],
("@//bazel/config:use_glibcxx_debug_disabled"): [],
}, no_match_error = GLIBCXX_DEBUG_ERROR_MESSAGE)
TCMALLOC_DEFINES = select({
"//bazel/config:tcmalloc_google_enabled": ["ABSL_ALLOCATOR_NOTHROW"],
"//conditions:default": [],
"@//bazel/config:tcmalloc_google_enabled": ["ABSL_ALLOCATOR_NOTHROW"],
"@//conditions:default": [],
})
MONGO_GLOBAL_DEFINES = (

View File

@ -89,6 +89,9 @@ def _impl(ctx):
# Do not resolve our symlinked resource prefixes to real paths. This is required to
# make includes resolve correctly.
"-no-canonical-prefixes",
] if ctx.attr.compiler == COMPILERS.CLANG else [
"-no-canonical-prefixes",
"-fno-canonical-system-headers",
],
),
],
@ -209,6 +212,33 @@ def _impl(ctx):
],
)
external_include_paths_feature = feature(
name = "external_include_paths",
enabled = True,
flag_sets = [
flag_set(
actions = [
ACTION_NAMES.preprocess_assemble,
ACTION_NAMES.linkstamp_compile,
ACTION_NAMES.c_compile,
ACTION_NAMES.cpp_compile,
ACTION_NAMES.cpp_header_parsing,
ACTION_NAMES.cpp_module_compile,
ACTION_NAMES.clif_match,
ACTION_NAMES.objc_compile,
ACTION_NAMES.objcpp_compile,
],
flag_groups = [
flag_group(
flags = ["-isystem", "%{external_include_paths}"],
iterate_over = "external_include_paths",
expand_if_available = "external_include_paths",
),
],
),
],
)
library_search_directories_feature = feature(
name = "library_search_directories",
flag_sets = [
@ -1706,6 +1736,7 @@ def _impl(ctx):
"-Wno-missing-template-arg-list-after-template-kw",
"-Wno-sign-compare",
"-Wno-implicit-fallthrough",
"-Wno-shorten-64-to-32",
])],
),
],
@ -1749,6 +1780,7 @@ def _impl(ctx):
bin_dirs_feature,
default_compile_flags_feature,
include_paths_feature,
external_include_paths_feature,
library_search_directories_feature,
supports_dynamic_linker_feature,
supports_start_end_lib_feature,
@ -1910,6 +1942,7 @@ mongo_linux_cc_toolchain_config = rule(
"coverage_enabled": attr.bool(default = False, mandatory = False),
"compress_debug_enabled": attr.bool(default = False, mandatory = False),
"warnings_as_errors_enabled": attr.bool(default = False, mandatory = False),
"global_defines": attr.string_list(mandatory = False),
},
provides = [CcToolchainConfigInfo],
)

View File

@ -19,6 +19,7 @@ load(
"SYSTEM_ALLOCATOR_SANITIZER_ERROR_MESSAGE",
"THREAD_SANITIZER_ERROR_MESSAGE",
)
load("@//bazel/toolchains/cc:mongo_defines.bzl", "MONGO_GLOBAL_DEFINES")
package(default_visibility = ["//visibility:public"])
@ -294,6 +295,7 @@ mongo_linux_cc_toolchain_config(
coverage_enabled = COVERAGE_ENABLED,
compress_debug_enabled = COMPRESS_DEBUG_ENABLED,
warnings_as_errors_enabled = WARNINGS_AS_ERRORS_ENABLED,
global_defines = MONGO_GLOBAL_DEFINES,
)
mongo_linux_cc_toolchain_config(
@ -360,6 +362,7 @@ mongo_linux_cc_toolchain_config(
coverage_enabled = COVERAGE_ENABLED,
compress_debug_enabled = COMPRESS_DEBUG_ENABLED,
warnings_as_errors_enabled = WARNINGS_AS_ERRORS_ENABLED,
global_defines = MONGO_GLOBAL_DEFINES,
)
cc_toolchain(

View File

@ -1,4 +1,5 @@
load("@//bazel/toolchains/cc/mongo_windows:mongo_windows_cc_toolchain_config.bzl", "mongo_windows_cc_toolchain_config")
load("@//bazel/toolchains/cc:mongo_defines.bzl", "MONGO_GLOBAL_DEFINES")
SMALLER_BINARY = select({
"@//bazel/config:msvc_opt": True,
@ -109,6 +110,7 @@ mongo_windows_cc_toolchain_config(
opt_size = OPT_SIZE,
dbg = DBG,
debug_symbols = DEBUG_SYMBOLS,
global_defines = MONGO_GLOBAL_DEFINES,
)
exports_files(["rc_wrapper.cmd"])

View File

@ -1063,6 +1063,7 @@ def _impl(ctx):
external_include_paths_feature = feature(
name = "external_include_paths",
enabled = True,
flag_sets = [
flag_set(
actions = [
@ -1078,7 +1079,10 @@ def _impl(ctx):
],
flag_groups = [
flag_group(
flags = ["/external:I%{external_include_paths}"],
flags = [
"/external:I%{external_include_paths}",
"/external:W0",
],
iterate_over = "external_include_paths",
expand_if_available = "external_include_paths",
),
@ -1591,6 +1595,20 @@ def _impl(ctx):
],
)
mongo_defines_feature = feature(
name = "mongo_defines",
enabled = True,
flag_sets = [
flag_set(
actions = all_compile_actions,
flag_groups = [flag_group(
flags =
["/D" + define for define in ctx.attr.global_defines],
)],
),
],
)
features = [
no_legacy_features_feature,
nologo_feature,
@ -1657,6 +1675,7 @@ def _impl(ctx):
pdb_page_size_feature,
incremental_feature,
sasl_include_feature,
mongo_defines_feature,
]
else:
targets_windows_feature = feature(
@ -1993,6 +2012,7 @@ mongo_windows_cc_toolchain_config = rule(
"opt_size": attr.bool(default = False),
"dbg": attr.bool(default = False),
"debug_symbols": attr.bool(default = False),
"global_defines": attr.string_list(mandatory = False),
},
provides = [CcToolchainConfigInfo],
)

View File

@ -66,6 +66,7 @@ buildvariants:
bazel_compile_flags: >-
--linkstatic=False
--define=MONGO_DISTMOD=rhel81
--compiler_type=gcc
compile_variant: enterprise-rhel-81-ppc64le-shared
tasks:
- name: compile_test_serial_TG

View File

@ -35,6 +35,7 @@ def _run_mod_scan(
args.add_all(compilation_context.includes, before_each = "-I")
args.add_all(compilation_context.quote_includes, before_each = "-iquote")
args.add_all(compilation_context.system_includes, before_each = "-isystem")
args.add_all(compilation_context.external_includes, before_each = "-isystem")
# add args specified by the toolchain, on the command line and rule copts
args.add_all(flags)

View File

@ -249,16 +249,18 @@ mongo_cc_library(
"//src/mongo/util:boost_assert_shim",
"//src/mongo/util:debugger",
"//src/third_party/IntelRDFPMathLib20U1:intel_decimal128",
"//src/third_party/abseil-cpp:absl_city",
"//src/third_party/abseil-cpp:absl_hash",
"//src/third_party/abseil-cpp:absl_int128",
"//src/third_party/abseil-cpp:absl_low_level_hash",
"//src/third_party/abseil-cpp:absl_raw_hash_set",
"//src/third_party/boost:boost_filesystem",
"//src/third_party/boost:boost_iostreams",
"//src/third_party/boost:boost_log",
"//src/third_party/boost:boost_program_options",
"//src/third_party/pcre2",
"@com_google_absl//absl/container:btree",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/container:node_hash_map",
"@com_google_absl//absl/container:node_hash_set",
"@com_google_absl//absl/hash:city",
"@com_google_absl//absl/numeric:int128",
] + select({
"@platforms//os:linux": ["//src/mongo/platform:throw_hook"],
"//conditions:default": [],

View File

@ -966,6 +966,7 @@ mongo_cc_library(
"//src/mongo/util:background_job",
"//src/mongo/util:elapsed_tracker",
"//src/third_party/s2",
"@com_google_absl//absl/functional:bind_front",
],
)
@ -1208,7 +1209,7 @@ mongo_cc_library(
"//src/mongo/db/query/util:stop_token",
"//src/mongo/db/traffic_recorder/utils:task_scheduler",
"//src/mongo/rpc",
"//src/third_party/abseil-cpp:absl_crc32c",
"@com_google_absl//absl/crc:crc32c",
],
)

View File

@ -113,6 +113,7 @@ mongo_cc_library(
"//src/mongo:base",
"//src/mongo/db:sbe_values",
"//src/mongo/stdx",
"@com_google_absl//absl/random:distributions",
],
)

View File

@ -240,9 +240,9 @@ mongo_cc_unit_test(
"core_test_cc_grpc",
"core_test_strip_prefix_cc_grpc",
"//src/mongo:base",
"//src/third_party/abseil-cpp:absl_status",
"//src/third_party/grpc:grpc++_reflection",
"//src/third_party/protobuf",
"@com_google_absl//absl/status",
],
)

File diff suppressed because it is too large Load Diff

View File

@ -9,20 +9,6 @@ To update abseil you should:
1. update the version/repo information in the import.py script
2. remove the existing abseil-cpp/dist directory
3. run the import.sh script
4. run the parse_libs_from_ninja.py
# Updating the BUILD.bazel generated libraries
The parse_libs_from_ninja.py will extract specifically requested libraries
from the native abseil build. This list of libraries should be a python list
defined near the top fo the parse_libs_from_ninja.py file.
Update this list if a new set of libraries is required.
Note that the script works by iteration throught he list of specified libraries,
finding the library one at a time in the ninja file, extracting source files and
dependent libraries, then reiterating untill all specific and dependent libraries
have been found. If a specified library can not be found the script will fail
with exception.
# Mongodbtoolchain dependency

View File

@ -1,228 +0,0 @@
#!/usr/bin/env python3
import os
import glob
import pathlib
import subprocess
import logging
import sys
import re
# This is the list of libraries that are desired to be extracted out of the
# ninja file
target_libs = set(
[
"absl_bad_optional_access",
"absl_bad_variant_access",
"absl_base",
"absl_city",
"absl_civil_time",
"absl_cord",
"absl_cord_internal",
"absl_cordz_functions",
"absl_cordz_handle",
"absl_cordz_info",
"absl_debugging_internal",
"absl_demangle_internal",
"absl_exponential_biased",
"absl_flags",
"absl_graphcycles_internal",
"absl_hash",
"absl_hashtablez_sampler",
"absl_int128",
"absl_log_severity",
"absl_low_level_hash",
"absl_malloc_internal",
"absl_random_distributions",
"absl_random_internal_platform",
"absl_random_internal_pool_urbg",
"absl_random_internal_randen",
"absl_random_internal_randen_hwaes",
"absl_random_internal_randen_hwaes_impl",
"absl_random_internal_randen_slow",
"absl_random_internal_seed_material",
"absl_random_seed_gen_exception",
"absl_random_seed_sequences",
"absl_raw_hash_set",
"absl_raw_logging_internal",
"absl_spinlock_wait",
"absl_stacktrace",
"absl_status",
"absl_statusor",
"absl_str_format_internal",
"absl_strings",
"absl_strings_internal",
"absl_symbolize",
"absl_synchronization",
"absl_throw_delegate",
"absl_time",
"absl_time_zone",
]
)
# this is the path for cmake to use to generate abseil native ninja file.
cmake_bin_path = "/opt/mongodbtoolchain/v4/bin/cmake"
if sys.platform == "win32" or sys.platform == "darwin":
raise Exception("This script is currently not supported on windows or macos.")
logging.basicConfig(
filename=os.path.splitext(__file__)[0] + ".log",
filemode="w",
format="%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s",
datefmt="%H:%M:%S",
level=logging.DEBUG,
)
original_target_libs = target_libs.copy()
logging.info(f"Original list: {original_target_libs}")
ninja_build_dir = pathlib.Path(__file__).parent.parent / "dist" / "gen_build"
if not os.path.exists(ninja_build_dir):
os.mkdir(ninja_build_dir)
environ = os.environ.copy()
environ["CC"] = "/opt/mongodbtoolchain/v4/bin/gcc"
environ["CXX"] = "/opt/mongodbtoolchain/v4/bin/g++"
subprocess.run(
[cmake_bin_path, "-G", "Ninja", ".."], cwd=ninja_build_dir, check=True, env=environ
)
with open(ninja_build_dir / "build.ninja") as fninja:
content = fninja.readlines()
with open(pathlib.Path(__file__).parent.parent / "BUILD.bazel", "w") as bazel:
abseil_headers = glob.glob(
str(pathlib.Path(__file__).parent.parent / "dist/absl/**/*.h"), recursive=True
) + glob.glob(
str(pathlib.Path(__file__).parent.parent / "dist/absl/**/*.inc"), recursive=True
)
abseil_headers = sorted(
[os.path.relpath(path, pathlib.Path(__file__).parent.parent) for path in abseil_headers]
)
bazel.write(f"""\
# AUTO-GENERATED FILE DO NOT MANUALLY EDIT
# generated from the parse_libs_from_ninja.py script in scripts directory via `python ./parse_libs_from_ninja.py`
load("//bazel:mongo_src_rules.bzl", "mongo_cc_library")
package(default_visibility = ["//visibility:public"])
ABSEIL_HEADERS = [
{os.linesep.join([f" '{hdr}'," for hdr in abseil_headers])}
]
ABSEIL_SKIP_GLOBAL_DEPS = [
# This is a globally injected dependency.
# Skip depending on all globally injected dependencies to avoid circular dependencies.
"allocator",
"libunwind",
]
""")
# This will loop through the ninja file looking for the specified target libs.
# A pass throught he ninja file may find one ore more libraries but must find
# at least one or else an exception is raised.
#
# For each library found, the dependent libraries are added as libraries to find, and
# so several passes the the ninja file may be required as new dependencies are found.
written_libs = set()
while written_libs != target_libs:
cur_libs_num = len(written_libs)
for line in content:
# found an interesting line with potential, ninja build edges always start with
# "build {targets}"
if line.startswith("build absl"):
found_target_lib = None
match = re.search(r"lib(absl_\w+)\.a: CXX_STATIC_LIBRARY_LINKER", line)
if match:
found_target_lib = match[1]
target_libs.add(found_target_lib)
# if the line does not contain our target lib or we already found this before
# then this line is not interesting and continue on
if not found_target_lib:
continue
if found_target_lib in written_libs:
continue
# else we have found a new library so lets parse out the source files and dependent
# libraries. Ninja format use spaces as delimiters and $ as an escape. The loop below
# while extract the spaces which should be exacped and put them in the tokens.
raw_tokens = line.split(" ")
tokens = []
index = 0
while index < len(raw_tokens):
token = raw_tokens[index]
while token.endswith("$"):
index += 1
token = token[:-1]
token += raw_tokens[index]
tokens.append(token)
index += 1
# the dependent liraries will be listed after the explicit deps separator '||'
try:
deps_token_index = tokens.index("||")
except ValueError:
deps_token_index = len(tokens)
# The source files should be after the "build" identifier, target name, and rule,
# and before the dependencies for example:
#
# build absl/base/libabsl_strerror.a: CXX_STATIC_LIBRARY_LINKER__strerror_
#
# This would fail if the build edge listed multiple output targets, but this so far has not been
# the case with abseil.
raw_source_files = tokens[3:deps_token_index]
source_files = []
# because the source files are listed object file inputs to the static lib
# we need strip the cmake output dir, and the object file extension
print(f"Found library: {found_target_lib}")
for raw_source in raw_source_files:
path_elems = raw_source.split("/")
path_elems.remove("CMakeFiles")
path_elems.remove(found_target_lib.replace("absl_", "") + ".dir")
source_files.append(os.path.splitext(os.path.join("dist", *path_elems))[0])
# now extract the library dependencies
raw_libdeps = tokens[deps_token_index + 1 :]
libdeps = []
for raw_libdep in raw_libdeps:
libdeps.append(f"{os.path.splitext(os.path.basename(raw_libdep))[0][3:]}")
# When we have found a lib add it to our list of found libs and also
# add any new dependencies we found to our target list.
written_libs.add(found_target_lib)
target_libs.update(libdeps)
logging.info(f"Found library {found_target_lib}")
logging.info(f"Libbraries left to find: {target_libs.difference(written_libs)}")
bazel.write(f"""\
{f'# {found_target_lib} added as a dependency of other abseil libraries'
if found_target_lib not in original_target_libs
else f'# {found_target_lib} is an explicit dependency to the server build'}
mongo_cc_library(
name='{found_target_lib}',
srcs = [
{os.linesep.join([f" '{source}'," for source in source_files])}
],
hdrs = ABSEIL_HEADERS,
skip_global_deps = ABSEIL_SKIP_GLOBAL_DEPS,{os.linesep + f" deps = [" + os.linesep + os.linesep.join([f" ':{libdep}'," for libdep in sorted(libdeps)]) + os.linesep +" ]," if libdeps else ""}
includes=['dist']
)
""")
if len(written_libs) == cur_libs_num:
raise Exception(
f"Did not find any more requested libs {target_libs.difference(written_libs)}, "
+ "the library must exist in the abseil build, check the build.ninja file "
+ "and the parse_lib_from_ninja.log file."
)

View File

@ -951,44 +951,23 @@ mongo_cc_library(
includes = ["dist/include"],
target_compatible_with = GRPC_TARGET_COMPATIBLE_WITH,
deps = [
"//src/third_party/abseil-cpp:absl_base",
"//src/third_party/abseil-cpp:absl_civil_time",
"//src/third_party/abseil-cpp:absl_cord",
"//src/third_party/abseil-cpp:absl_cord_internal",
"//src/third_party/abseil-cpp:absl_cordz_functions",
"//src/third_party/abseil-cpp:absl_cordz_handle",
"//src/third_party/abseil-cpp:absl_cordz_info",
"//src/third_party/abseil-cpp:absl_debugging_internal",
"//src/third_party/abseil-cpp:absl_demangle_internal",
"//src/third_party/abseil-cpp:absl_exponential_biased",
"//src/third_party/abseil-cpp:absl_flags_internal",
"//src/third_party/abseil-cpp:absl_flags_marshalling",
"//src/third_party/abseil-cpp:absl_flags_reflection",
"//src/third_party/abseil-cpp:absl_graphcycles_internal",
"//src/third_party/abseil-cpp:absl_int128",
"//src/third_party/abseil-cpp:absl_log_severity",
"//src/third_party/abseil-cpp:absl_malloc_internal",
"//src/third_party/abseil-cpp:absl_random_distributions",
"//src/third_party/abseil-cpp:absl_random_internal_platform",
"//src/third_party/abseil-cpp:absl_random_internal_randen",
"//src/third_party/abseil-cpp:absl_random_internal_randen_hwaes",
"//src/third_party/abseil-cpp:absl_random_internal_randen_hwaes_impl",
"//src/third_party/abseil-cpp:absl_random_internal_randen_slow",
"//src/third_party/abseil-cpp:absl_random_internal_seed_material",
"//src/third_party/abseil-cpp:absl_random_seed_gen_exception",
"//src/third_party/abseil-cpp:absl_random_seed_sequences",
"//src/third_party/abseil-cpp:absl_raw_logging_internal",
"//src/third_party/abseil-cpp:absl_spinlock_wait",
"//src/third_party/abseil-cpp:absl_stacktrace",
"//src/third_party/abseil-cpp:absl_status",
"//src/third_party/abseil-cpp:absl_str_format_internal",
"//src/third_party/abseil-cpp:absl_strings",
"//src/third_party/abseil-cpp:absl_strings_internal",
"//src/third_party/abseil-cpp:absl_symbolize",
"//src/third_party/abseil-cpp:absl_synchronization",
"//src/third_party/abseil-cpp:absl_throw_delegate",
"//src/third_party/abseil-cpp:absl_time",
"//src/third_party/abseil-cpp:absl_time_zone",
"@com_google_absl//absl/base",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/base:log_severity",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/functional:any_invocable",
"@com_google_absl//absl/functional:bind_front",
"@com_google_absl//absl/log",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/log:globals",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/random",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:cord",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/synchronization",
"@com_google_absl//absl/time",
],
)
@ -2760,16 +2739,16 @@ mongo_cc_library(
":upb_collections",
":upb_json",
":upb_textformat",
"//src/third_party/abseil-cpp:absl_city",
"//src/third_party/abseil-cpp:absl_hash",
"//src/third_party/abseil-cpp:absl_hashtablez_sampler",
"//src/third_party/abseil-cpp:absl_low_level_hash",
"//src/third_party/abseil-cpp:absl_random_distributions",
"//src/third_party/abseil-cpp:absl_raw_hash_set",
"//src/third_party/abseil-cpp:absl_statusor",
"//src/third_party/cares",
"//src/third_party/re2",
"//src/third_party/zlib",
"@com_google_absl//absl/container:hashtablez_sampler",
"@com_google_absl//absl/container:raw_hash_set",
"@com_google_absl//absl/hash",
"@com_google_absl//absl/hash:city",
"@com_google_absl//absl/random:bit_gen_ref",
"@com_google_absl//absl/random:distributions",
"@com_google_absl//absl/status:statusor",
],
)
@ -3454,8 +3433,8 @@ mongo_cc_library(
deps = [
"channel_arg_names",
"gpr_public_hdrs",
"//src/third_party/abseil-cpp:absl_statusor",
"//src/third_party/abseil-cpp:absl_strings",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
],
)
@ -3466,7 +3445,7 @@ mongo_cc_library(
],
hdrs = GPR_PUBLIC_HDRS,
deps = [
"//src/third_party/abseil-cpp:absl_strings",
"@com_google_absl//absl/strings",
],
)

View File

@ -51,8 +51,8 @@ mongo_cc_library(
tags = ["api"],
target_compatible_with = OTEL_TARGET_COMPATIBLE_WITH,
deps = [
"//src/third_party/abseil-cpp:absl_base",
"//src/third_party/abseil-cpp:absl_strings",
"@com_google_absl//absl/base:base",
"@com_google_absl//absl/strings:strings",
],
)

View File

@ -76,7 +76,7 @@ mongo_cc_library(
],
target_compatible_with = OTEL_TARGET_COMPATIBLE_WITH,
deps = [
"//src/third_party/abseil-cpp:absl_strings",
"@com_google_absl//absl/strings:strings",
"//src/third_party/nlohmann-json:json",
"//src/third_party/opentelemetry-cpp/api",
"//src/third_party/opentelemetry-cpp/ext/src/http/client/curl:http_client_curl",
@ -149,7 +149,7 @@ mongo_cc_library(
],
target_compatible_with = OTEL_TARGET_COMPATIBLE_WITH,
deps = [
"//src/third_party/abseil-cpp:absl_strings",
"@com_google_absl//absl/strings:strings",
"//src/third_party/nlohmann-json:json",
"//src/third_party/opentelemetry-cpp/api",
"//src/third_party/opentelemetry-cpp/sdk:headers",
@ -221,7 +221,7 @@ mongo_cc_library(
],
target_compatible_with = OTEL_TARGET_COMPATIBLE_WITH,
deps = [
"//src/third_party/abseil-cpp:absl_strings",
"@com_google_absl//absl/strings:strings",
"//src/third_party/grpc:grpc++",
"//src/third_party/nlohmann-json:json",
"//src/third_party/opentelemetry-cpp/api",

View File

@ -64,8 +64,8 @@ index dfc7d3c6450..dbc3b1d452e 100644
- "@com_google_absl//absl/base",
- "@com_google_absl//absl/strings",
- "@com_google_absl//absl/types:variant",
+ "//src/third_party/abseil-cpp:absl_base",
+ "//src/third_party/abseil-cpp:absl_strings",
+ "@com_google_absl//absl/base:base",
+ "@com_google_absl//absl/strings:strings",
],
)
@ -221,7 +221,7 @@ index a2dd8f8c650..b3ddd1924b8 100644
- "@com_github_opentelemetry_proto//:common_proto_cc",
- "@com_google_absl//absl/strings",
- "@github_nlohmann_json//:json",
+ "//src/third_party/abseil-cpp:absl_strings",
+ "@com_google_absl//absl/strings:strings",
+ "//src/third_party/nlohmann-json:json",
+ "//src/third_party/opentelemetry-cpp/api",
+ "//src/third_party/opentelemetry-cpp/ext/src/http/client/curl:http_client_curl",
@ -283,7 +283,7 @@ index a2dd8f8c650..b3ddd1924b8 100644
- "@com_github_opentelemetry_proto//:common_proto_cc",
- "@com_google_absl//absl/strings",
- "@github_nlohmann_json//:json",
+ "//src/third_party/abseil-cpp:absl_strings",
+ "@com_google_absl//absl/strings:strings",
+ "//src/third_party/nlohmann-json:json",
+ "//src/third_party/opentelemetry-cpp/api",
+ "//src/third_party/opentelemetry-cpp/sdk:headers",

View File

@ -36,7 +36,7 @@ index 0ef1a177878..db1acb27d56 100644
+ ],
+ target_compatible_with = OTEL_TARGET_COMPATIBLE_WITH,
+ deps = [
+ "//src/third_party/abseil-cpp:absl_strings",
+ "@com_google_absl//absl/strings:strings",
+ "//src/third_party/grpc:grpc++",
+ "//src/third_party/nlohmann-json:json",
+ "//src/third_party/opentelemetry-cpp/api",

View File

@ -314,21 +314,7 @@ mongo_cc_library(
includes = ["dist/third_party/utf8_range"],
target_compatible_with = PROTOBUF_TARGET_COMPATIBLE_WITH,
deps = [
"//src/third_party/abseil-cpp:absl_base",
"//src/third_party/abseil-cpp:absl_debugging_internal",
"//src/third_party/abseil-cpp:absl_die_if_null",
"//src/third_party/abseil-cpp:absl_hash",
"//src/third_party/abseil-cpp:absl_log_initialize",
"//src/third_party/abseil-cpp:absl_log_internal_check_op",
"//src/third_party/abseil-cpp:absl_log_internal_message",
"//src/third_party/abseil-cpp:absl_log_severity",
"//src/third_party/abseil-cpp:absl_raw_hash_set",
"//src/third_party/abseil-cpp:absl_status",
"//src/third_party/abseil-cpp:absl_statusor",
"//src/third_party/abseil-cpp:absl_str_format_internal",
"//src/third_party/abseil-cpp:absl_strings",
"//src/third_party/abseil-cpp:absl_synchronization",
"//src/third_party/abseil-cpp:absl_time",
"@com_google_absl//absl/strings",
],
)
@ -421,22 +407,21 @@ mongo_cc_library(
target_compatible_with = PROTOBUF_TARGET_COMPATIBLE_WITH,
deps = [
":utf8_validity",
"//src/third_party/abseil-cpp:absl_base",
"//src/third_party/abseil-cpp:absl_debugging_internal",
"//src/third_party/abseil-cpp:absl_die_if_null",
"//src/third_party/abseil-cpp:absl_hash",
"//src/third_party/abseil-cpp:absl_log_initialize",
"//src/third_party/abseil-cpp:absl_log_internal_check_op",
"//src/third_party/abseil-cpp:absl_log_internal_message",
"//src/third_party/abseil-cpp:absl_log_severity",
"//src/third_party/abseil-cpp:absl_raw_hash_set",
"//src/third_party/abseil-cpp:absl_status",
"//src/third_party/abseil-cpp:absl_statusor",
"//src/third_party/abseil-cpp:absl_str_format_internal",
"//src/third_party/abseil-cpp:absl_strings",
"//src/third_party/abseil-cpp:absl_synchronization",
"//src/third_party/abseil-cpp:absl_time",
"//src/third_party/zlib",
"@com_google_absl//absl/base",
"@com_google_absl//absl/base:dynamic_annotations",
"@com_google_absl//absl/container:btree",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/hash",
"@com_google_absl//absl/log:absl_check",
"@com_google_absl//absl/log:absl_log",
"@com_google_absl//absl/log:die_if_null",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings:internal",
"@com_google_absl//absl/synchronization",
"@com_google_absl//absl/time",
],
)
@ -563,9 +548,9 @@ mongo_cc_library(
target_compatible_with = PROTOBUF_TARGET_COMPATIBLE_WITH,
deps = [
"protobuf",
"//src/third_party/abseil-cpp:absl_base",
"//src/third_party/abseil-cpp:absl_raw_hash_set",
"//src/third_party/abseil-cpp:absl_strings",
"@com_google_absl//absl/base",
"@com_google_absl//absl/container:raw_hash_set",
"@com_google_absl//absl/strings",
],
)
@ -580,5 +565,6 @@ mongo_cc_binary(
deps = [
"protobuf",
"protoc",
"@com_google_absl//absl/log:initialize",
],
)

View File

@ -79,12 +79,12 @@ mongo_cc_library(
"//conditions:default": ["@platforms//:incompatible"],
}),
deps = [
"//src/third_party/abseil-cpp:absl_base",
"//src/third_party/abseil-cpp:absl_log_internal_check_op",
"//src/third_party/abseil-cpp:absl_log_internal_message",
"//src/third_party/abseil-cpp:absl_raw_hash_set",
"//src/third_party/abseil-cpp:absl_str_format_internal",
"//src/third_party/abseil-cpp:absl_strings",
"//src/third_party/abseil-cpp:absl_synchronization",
"@com_google_absl//absl/base",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/log:absl_check",
"@com_google_absl//absl/log:absl_log",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/synchronization",
],
)

View File

@ -174,11 +174,11 @@ mongo_cc_library(
"tcmalloc_malloc_extension",
"tcmalloc_malloc_tracing_extension",
"tcmalloc_new_extension",
"//src/third_party/abseil-cpp:absl_base",
"//src/third_party/abseil-cpp:absl_stacktrace",
"//src/third_party/abseil-cpp:absl_status",
"//src/third_party/abseil-cpp:absl_statusor",
"//src/third_party/abseil-cpp:absl_strings",
"@com_google_absl//absl/base",
"@com_google_absl//absl/debugging:stacktrace",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
],
)
@ -198,8 +198,8 @@ mongo_cc_library(
"tcmalloc_internal_logging",
"tcmalloc_internal_sysinfo",
"tcmalloc_internal_util",
"//src/third_party/abseil-cpp:absl_base",
"//src/third_party/abseil-cpp:absl_strings",
"@com_google_absl//absl/base",
"@com_google_absl//absl/strings",
],
)
@ -215,7 +215,7 @@ mongo_cc_library(
local_defines = TCMALLOC_DEFINES,
skip_global_deps = TCMALLOC_SKIP_GLOBAL_DEPS,
target_compatible_with = PLATFORM_SUPPORTED,
deps = ["//src/third_party/abseil-cpp:absl_base"],
deps = ["@com_google_absl//absl/base"],
)
mongo_cc_library(
@ -233,11 +233,11 @@ mongo_cc_library(
deps = [
"tcmalloc_internal_environment",
"tcmalloc_malloc_extension",
"//src/third_party/abseil-cpp:absl_base",
"//src/third_party/abseil-cpp:absl_stacktrace",
"//src/third_party/abseil-cpp:absl_str_format_internal",
"//src/third_party/abseil-cpp:absl_strings",
"//src/third_party/abseil-cpp:absl_time",
"@com_google_absl//absl/base",
"@com_google_absl//absl/debugging:stacktrace",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/time",
],
)
@ -257,7 +257,7 @@ mongo_cc_library(
"tcmalloc_internal_logging",
"tcmalloc_internal_page_size",
"tcmalloc_internal_util",
"//src/third_party/abseil-cpp:absl_strings",
"@com_google_absl//absl/strings",
],
)
@ -275,7 +275,7 @@ mongo_cc_library(
target_compatible_with = PLATFORM_SUPPORTED,
deps = [
"tcmalloc_internal_page_size",
"//src/third_party/abseil-cpp:absl_base",
"@com_google_absl//absl/base",
],
)
@ -296,8 +296,8 @@ mongo_cc_library(
"tcmalloc_internal_logging",
"tcmalloc_internal_percpu",
"tcmalloc_internal_util",
"//src/third_party/abseil-cpp:absl_base",
"//src/third_party/abseil-cpp:absl_strings",
"@com_google_absl//absl/base",
"@com_google_absl//absl/strings",
],
)
@ -314,7 +314,7 @@ mongo_cc_library(
skip_global_deps = TCMALLOC_SKIP_GLOBAL_DEPS,
target_compatible_with = PLATFORM_SUPPORTED,
deps = [
"//src/third_party/abseil-cpp:absl_base",
"@com_google_absl//absl/base",
],
)
@ -340,7 +340,7 @@ mongo_cc_library(
"tcmalloc_internal_logging",
"tcmalloc_internal_sysinfo",
"tcmalloc_internal_util",
"//src/third_party/abseil-cpp:absl_base",
"@com_google_absl//absl/base",
],
)
@ -358,8 +358,8 @@ mongo_cc_library(
target_compatible_with = PLATFORM_SUPPORTED,
deps = [
"tcmalloc_internal_logging",
"//src/third_party/abseil-cpp:absl_base",
"//src/third_party/abseil-cpp:absl_time",
"@com_google_absl//absl/base",
"@com_google_absl//absl/time",
],
)
@ -379,7 +379,7 @@ mongo_cc_library(
"tcmalloc_internal_mincore",
"tcmalloc_internal_percpu",
"tcmalloc_internal_sysinfo",
"//src/third_party/abseil-cpp:absl_base",
"@com_google_absl//absl/base",
],
)
@ -397,8 +397,8 @@ mongo_cc_library(
target_compatible_with = PLATFORM_SUPPORTED,
deps = [
"tcmalloc_internal_util",
"//src/third_party/abseil-cpp:absl_base",
"//src/third_party/abseil-cpp:absl_strings",
"@com_google_absl//absl/base",
"@com_google_absl//absl/strings",
],
)
@ -415,8 +415,8 @@ mongo_cc_library(
skip_global_deps = TCMALLOC_SKIP_GLOBAL_DEPS,
target_compatible_with = PLATFORM_SUPPORTED,
deps = [
"//src/third_party/abseil-cpp:absl_base",
"//src/third_party/abseil-cpp:absl_strings",
"@com_google_absl//absl/base",
"@com_google_absl//absl/strings",
],
)
@ -479,14 +479,16 @@ mongo_cc_library(
"tcmalloc_malloc_extension",
"tcmalloc_malloc_tracing_extension",
"tcmalloc_new_extension",
"//src/third_party/abseil-cpp:absl_base",
"//src/third_party/abseil-cpp:absl_hash",
"//src/third_party/abseil-cpp:absl_malloc_internal",
"//src/third_party/abseil-cpp:absl_raw_hash_set",
"//src/third_party/abseil-cpp:absl_stacktrace",
"//src/third_party/abseil-cpp:absl_strings",
"//src/third_party/abseil-cpp:absl_synchronization",
"//src/third_party/abseil-cpp:absl_time",
"@com_google_absl//absl/algorithm:container",
"@com_google_absl//absl/base",
"@com_google_absl//absl/base:malloc_internal",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/container:raw_hash_set",
"@com_google_absl//absl/debugging:stacktrace",
"@com_google_absl//absl/hash",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/synchronization",
"@com_google_absl//absl/time",
],
)
@ -505,7 +507,7 @@ mongo_cc_library(
deps = [
"tcmalloc_internal_environment",
"tcmalloc_internal_logging",
"//src/third_party/abseil-cpp:absl_strings",
"@com_google_absl//absl/strings",
],
)
@ -522,9 +524,11 @@ mongo_cc_library(
skip_global_deps = TCMALLOC_SKIP_GLOBAL_DEPS,
target_compatible_with = PLATFORM_SUPPORTED,
deps = [
"//src/third_party/abseil-cpp:absl_malloc_internal",
"//src/third_party/abseil-cpp:absl_strings",
"//src/third_party/abseil-cpp:absl_time",
"@com_google_absl//absl/base:malloc_internal",
"@com_google_absl//absl/functional:function_ref",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/time",
"@com_google_absl//absl/types:span",
],
)
@ -541,8 +545,8 @@ mongo_cc_library(
skip_global_deps = TCMALLOC_SKIP_GLOBAL_DEPS,
target_compatible_with = PLATFORM_SUPPORTED,
deps = [
"//src/third_party/abseil-cpp:absl_status",
"//src/third_party/abseil-cpp:absl_statusor",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
],
)
@ -577,5 +581,6 @@ mongo_cc_library(
target_compatible_with = PLATFORM_SUPPORTED,
deps = [
"tcmalloc_malloc_extension",
"@com_google_absl//absl/strings:str_format",
],
)