SERVER-102939: Cleanup of the bazel cc toolchain (#34644)

GitOrigin-RevId: 00afe1e1eb3399479d1ca0dbed288f29accb96b7
This commit is contained in:
patricearruda84 2025-04-07 08:55:21 -04:00 committed by MongoDB Bot
parent 7d3e912236
commit 843aeff8b7
26 changed files with 104 additions and 99 deletions

View File

@ -1,7 +1,7 @@
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@aspect_rules_js//npm:defs.bzl", "npm_link_package")
load("//bazel/install_rules:install_rules.bzl", "TEST_TAGS", "mongo_install")
load("//bazel/toolchains/cc:mongo_toolchain.bzl", "setup_mongo_toolchain_aliases")
load("//bazel/toolchains/cc/mongo_linux:mongo_toolchain.bzl", "setup_mongo_toolchain_aliases")
load("//bazel/config:render_template.bzl", "render_template")
load("@npm//:eslint/package_json.bzl", eslint_bin = "bin")
load("//bazel:mongo_js_rules.bzl", "mongo_js_library")

9
MODULE.bazel.lock generated
View File

@ -59,7 +59,7 @@
"moduleExtensions": {
"//bazel:bzlmod.bzl%setup_mongo_python_toolchains": {
"general": {
"bzlTransitiveDigest": "hJjUHd8gYJ+UhUuc0EhGnjmPEIJWFeFqwY2XLEMFLG4=",
"bzlTransitiveDigest": "SVoEAY77WWPJ+9GloaKfza9WLdxM2NnwYLr4MY3svP4=",
"usagesDigest": "bUxjq9n+hj2YwYT/lcSP4lHyQ2GVy5JpFgSmddUqUZg=",
"recordedFileInputs": {},
"recordedDirentsInputs": {},
@ -76,7 +76,6 @@
"attributes": {
"arch": "aarch64",
"os": "linux",
"build_tpl": "@@//bazel/toolchains/python:python_toolchain.BUILD",
"sha256": "3e26a672df17708c4dc928475a5974c3fb3a34a9b45c65fb4bd1e50504cc84ec",
"urls": [
"https://github.com/indygreg/python-build-standalone/releases/download/20231002/cpython-3.11.6+20231002-aarch64-unknown-linux-gnu-install_only.tar.gz"
@ -89,7 +88,6 @@
"attributes": {
"arch": "amd64",
"os": "linux",
"build_tpl": "@@//bazel/toolchains/python:python_toolchain.BUILD",
"sha256": "ee37a7eae6e80148c7e3abc56e48a397c1664f044920463ad0df0fc706eacea8",
"urls": [
"https://github.com/indygreg/python-build-standalone/releases/download/20231002/cpython-3.11.6+20231002-x86_64-unknown-linux-gnu-install_only.tar.gz"
@ -102,7 +100,6 @@
"attributes": {
"arch": "ppc64le",
"os": "linux",
"build_tpl": "@@//bazel/toolchains/python:python_toolchain.BUILD",
"sha256": "7937035f690a624dba4d014ffd20c342e843dd46f89b0b0a1e5726b85deb8eaf",
"urls": [
"https://github.com/indygreg/python-build-standalone/releases/download/20231002/cpython-3.11.6+20231002-ppc64le-unknown-linux-gnu-install_only.tar.gz"
@ -115,7 +112,6 @@
"attributes": {
"arch": "s390x",
"os": "linux",
"build_tpl": "@@//bazel/toolchains/python:python_toolchain.BUILD",
"sha256": "f9f19823dba3209cedc4647b00f46ed0177242917db20fb7fb539970e384531c",
"urls": [
"https://github.com/indygreg/python-build-standalone/releases/download/20231002/cpython-3.11.6+20231002-s390x-unknown-linux-gnu-install_only.tar.gz"
@ -128,7 +124,6 @@
"attributes": {
"arch": "amd64",
"os": "windows",
"build_tpl": "@@//bazel/toolchains/python:python_toolchain.BUILD",
"interpreter_path": "dist/python.exe",
"sha256": "35458ef3163a2705cd0952ba1df6012acb42b043349dcb31ab49afec341369cf",
"urls": [
@ -142,7 +137,6 @@
"attributes": {
"arch": "aarch64",
"os": "macos",
"build_tpl": "@@//bazel/toolchains/python:python_toolchain.BUILD",
"sha256": "916c35125b5d8323a21526d7a9154ca626453f63d0878e95b9f613a95006c990",
"urls": [
"https://github.com/indygreg/python-build-standalone/releases/download/20231002/cpython-3.11.6+20231002-aarch64-apple-darwin-install_only.tar.gz"
@ -155,7 +149,6 @@
"attributes": {
"arch": "amd64",
"os": "macos",
"build_tpl": "@@//bazel/toolchains/python:python_toolchain.BUILD",
"sha256": "178cb1716c2abc25cb56ae915096c1a083e60abeba57af001996e8bc6ce1a371",
"urls": [
"https://github.com/indygreg/python-build-standalone/releases/download/20231002/cpython-3.11.6+20231002-x86_64-apple-darwin-install_only.tar.gz"

View File

@ -1,5 +1,5 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("//bazel/toolchains/cc:mongo_toolchain.bzl", "setup_mongo_toolchains")
load("//bazel/toolchains/cc/mongo_linux:mongo_toolchain.bzl", "setup_mongo_toolchains")
http_archive(
name = "aspect_rules_lint",

View File

@ -1,7 +1,7 @@
load("@bazel_features//:deps.bzl", _bazel_features_deps = "bazel_features_deps")
load("//bazel/platforms:local_config_platform.bzl", "setup_local_config_platform")
load("//bazel/toolchains/python:python_toolchain.bzl", _setup_mongo_python_toolchains = "setup_mongo_python_toolchains")
load("//bazel/toolchains/cc:mongo_toolchain.bzl", _setup_mongo_toolchains = "setup_mongo_toolchains")
load("//bazel/toolchains/cc/mongo_linux:mongo_toolchain.bzl", _setup_mongo_toolchains = "setup_mongo_toolchains")
def _bazel_features_deps_impl(_ctx):
_bazel_features_deps()

View File

@ -8,7 +8,7 @@ load(
"REQUIRED_SETTINGS_LIBUNWIND_ERROR_MESSAGE",
)
load(
"//bazel/toolchains/cc:mongo_compiler_flags.bzl",
"//bazel/toolchains/cc/mongo_linux:mongo_compiler_flags.bzl",
"MONGO_LINUX_CC_COPTS",
"MONGO_LINUX_CC_LINKFLAGS",
)

View File

@ -1,6 +1,6 @@
load("//bazel/platforms:remote_execution_containers.bzl", "REMOTE_EXECUTION_CONTAINERS")
load("//bazel/platforms:normalize.bzl", "ARCH_TO_PLATFORM_MAP", "OS_TO_PLATFORM_MAP")
load("//bazel/toolchains/cc:mongo_toolchain_version.bzl", "TOOLCHAIN_MAP")
load("//bazel/toolchains/cc/mongo_linux:mongo_toolchain_version.bzl", "TOOLCHAIN_MAP")
load("//bazel:utils.bzl", "get_host_distro_major_version")
def _setup_local_config_platform(ctx):

View File

@ -333,7 +333,7 @@ mongo_apple_toolchain_setup = repository_rule(
doc = "Host architecture.",
),
"build_tpl": attr.label(
default = "//bazel/toolchains/cc/mongo_apple:mongo_apple_toolchain.BUILD",
default = "//bazel/toolchains/cc/mongo_apple:mongo_apple_toolchain.BUILD.tmpl",
doc = "Label denoting the BUILD file template that get's installed in the repo.",
),
},

View File

@ -0,0 +1,15 @@
"""This module provides a list of defines that is passed in to compiling.
"""
visibility(["//bazel/toolchains/cc"])
MACOS_DEFINES = select({
"@platforms//os:macos": [
# TODO SERVER-54659 - ASIO depends on std::result_of which was removed
# in C++ 20. xcode15 does not have backwards compatibility.
"ASIO_HAS_STD_INVOKE_RESULT",
# This is needed to compile boost on the newer xcodes
"BOOST_NO_CXX98_FUNCTION_BASE",
],
"//conditions:default": [],
})

View File

@ -8,6 +8,9 @@ load(
"SYSTEM_ALLOCATOR_SANITIZER_ERROR_MESSAGE",
"THREAD_SANITIZER_ERROR_MESSAGE",
)
load("//bazel/toolchains/cc/mongo_apple:mongo_defines.bzl", "MACOS_DEFINES")
load("//bazel/toolchains/cc/mongo_linux:mongo_defines.bzl", "LINUX_DEFINES")
load("//bazel/toolchains/cc/mongo_windows:mongo_defines.bzl", "WINDOWS_DEFINES")
# Defines are only visible to within //bazel directory where
# toolchains and rules are defined.
@ -18,65 +21,6 @@ visibility([
"//bazel",
])
WINDOWS_DEFINES = select({
"@platforms//os:windows": [
# This tells the Windows compiler not to link against the .lib files and
# to use boost as a bunch of header-only libraries.
"BOOST_ALL_NO_LIB",
"_UNICODE",
"UNICODE",
# Temporary fixes to allow compilation with VS2017.
"_SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING",
"_SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING",
"_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING",
# TODO(SERVER-60151): Until we are fully in C++20 mode, it is easier to
# simply suppress C++20 deprecations. After we have switched over we
# should address any actual deprecated usages and then remove this flag.
"_SILENCE_ALL_CXX20_DEPRECATION_WARNINGS",
"_CONSOLE",
"_CRT_SECURE_NO_WARNINGS",
"_ENABLE_EXTENDED_ALIGNED_STORAGE",
"_SCL_SECURE_NO_WARNINGS",
],
"//conditions:default": [],
})
LINUX_DEFINES = select({
"@platforms//os:linux": [
# On linux, C code compiled with gcc/clang -std=c11 causes
# __STRICT_ANSI__ to be set, and that drops out all of the feature test
# definitions, resulting in confusing errors when we run C language
# configure checks and expect to be able to find newer POSIX things.
# Explicitly enabling _XOPEN_SOURCE fixes that, and should be mostly
# harmless as on Linux, these macros are cumulative. The C++ compiler
# already sets _XOPEN_SOURCE, and, notably, setting it again does not
# disable any other feature test macros, so this is safe to do. Other
# platforms like macOS and BSD have crazy rules, so don't try this
# there.
#
# Furthermore, as both C++ compilers appear to define _GNU_SOURCE
# unconditionally (because libstdc++ requires it), it seems prudent to
# explicitly add that too, so that C language checks see a consistent
# set of definitions.
"_XOPEN_SOURCE=700",
"_GNU_SOURCE",
],
"//conditions:default": [],
})
MACOS_DEFINES = select({
"@platforms//os:macos": [
# TODO SERVER-54659 - ASIO depends on std::result_of which was removed
# in C++ 20. xcode15 does not have backwards compatibility.
"ASIO_HAS_STD_INVOKE_RESULT",
# This is needed to compile boost on the newer xcodes
"BOOST_NO_CXX98_FUNCTION_BASE",
],
"//conditions:default": [],
})
ABSEIL_DEFINES = [
"ABSL_FORCE_ALIGNED_ACCESS",
]
@ -96,9 +40,6 @@ BOOST_DEFINES = [
] + select({
"//bazel/config:linkdynamic_not_shared_archive": ["BOOST_LOG_DYN_LINK"],
"//conditions:default": [],
}) + select({
"@platforms//os:windows": ["BOOST_ALL_NO_LIB"],
"//conditions:default": [],
})
ENTERPRISE_DEFINES = select({
@ -165,16 +106,16 @@ TCMALLOC_DEFINES = select({
})
MONGO_GLOBAL_DEFINES = (
MACOS_DEFINES +
LINUX_DEFINES +
WINDOWS_DEFINES +
DEBUG_DEFINES +
LIBCXX_DEFINES +
ADDRESS_SANITIZER_DEFINES +
THREAD_SANITIZER_DEFINES +
UNDEFINED_SANITIZER_DEFINES +
GLIBCXX_DEBUG_DEFINES +
WINDOWS_DEFINES +
MACOS_DEFINES +
TCMALLOC_DEFINES +
LINUX_DEFINES +
GCC_OPT_DEFINES +
BOOST_DEFINES +
ABSEIL_DEFINES +

View File

@ -0,0 +1,27 @@
"""This module provides a list of defines that is passed in to compiling.
"""
visibility(["//bazel/toolchains/cc"])
LINUX_DEFINES = select({
"@platforms//os:linux": [
# On linux, C code compiled with gcc/clang -std=c11 causes
# __STRICT_ANSI__ to be set, and that drops out all of the feature test
# definitions, resulting in confusing errors when we run C language
# configure checks and expect to be able to find newer POSIX things.
# Explicitly enabling _XOPEN_SOURCE fixes that, and should be mostly
# harmless as on Linux, these macros are cumulative. The C++ compiler
# already sets _XOPEN_SOURCE, and, notably, setting it again does not
# disable any other feature test macros, so this is safe to do. Other
# platforms like macOS and BSD have crazy rules, so don't try this
# there.
#
# Furthermore, as both C++ compilers appear to define _GNU_SOURCE
# unconditionally (because libstdc++ requires it), it seems prudent to
# explicitly add that too, so that C language checks see a consistent
# set of definitions.
"_XOPEN_SOURCE=700",
"_GNU_SOURCE",
],
"//conditions:default": [],
})

View File

@ -1,6 +1,6 @@
# This file exists to describe "mongo_toolchain", the http_archive defined in WORKSPACE.bazel
load("@//bazel/toolchains/cc:mongo_linux_cc_toolchain_config.bzl", "mongo_linux_cc_toolchain_config")
load("@//bazel/toolchains/cc/mongo_linux:mongo_linux_cc_toolchain_config.bzl", "mongo_linux_cc_toolchain_config")
load("@mongo_toolchain_{version}//:mongo_toolchain_flags.bzl",
"CLANG_INCLUDE_DIRS",
"COMMON_BINDIRS",

View File

@ -1,6 +1,6 @@
load("//bazel:utils.bzl", "get_host_distro_major_version", "retry_download_and_extract")
load("//bazel/platforms:normalize.bzl", "ARCH_NORMALIZE_MAP")
load("//bazel/toolchains/cc:mongo_toolchain_version.bzl", "TOOLCHAIN_MAP")
load("//bazel/toolchains/cc/mongo_linux:mongo_toolchain_version.bzl", "TOOLCHAIN_MAP")
def _generate_noop_toolchain(ctx, substitutions):
# BUILD file is required for a no-op
@ -128,7 +128,7 @@ toolchain_download = repository_rule(
mandatory = True,
),
"build_tpl": attr.label(
default = "//bazel/toolchains/cc:mongo_toolchain.BUILD",
default = "//bazel/toolchains/cc/mongo_linux:mongo_toolchain.BUILD.tmpl",
doc = "Label denoting the BUILD file template that gets installed in the repo.",
),
},
@ -138,13 +138,13 @@ def setup_mongo_toolchains():
toolchain_download(
name = "mongo_toolchain_v4",
version = "v4",
flags_tpl = "//bazel/toolchains/cc:mongo_toolchain_flags_v4.bzl",
flags_tpl = "//bazel/toolchains/cc/mongo_linux:mongo_toolchain_flags_v4.bzl",
)
toolchain_download(
name = "mongo_toolchain_v5",
version = "v5",
flags_tpl = "//bazel/toolchains/cc:mongo_toolchain_flags_v5.bzl",
flags_tpl = "//bazel/toolchains/cc/mongo_linux:mongo_toolchain_flags_v5.bzl",
)
native.register_toolchains(

View File

@ -0,0 +1,7 @@
load("//bazel/toolchains/cc/mongo_linux:mongo_toolchain_version_v4.bzl", "TOOLCHAIN_MAP_V4")
load("//bazel/toolchains/cc/mongo_linux:mongo_toolchain_version_v5.bzl", "TOOLCHAIN_MAP_V5")
TOOLCHAIN_MAP = {
"v4": TOOLCHAIN_MAP_V4,
"v5": TOOLCHAIN_MAP_V5,
}

View File

@ -1,7 +0,0 @@
load("//bazel/toolchains/cc:mongo_toolchain_version_v4.bzl", "TOOLCHAIN_MAP_V4")
load("//bazel/toolchains/cc:mongo_toolchain_version_v5.bzl", "TOOLCHAIN_MAP_V5")
TOOLCHAIN_MAP = {
"v4": TOOLCHAIN_MAP_V4,
"v5": TOOLCHAIN_MAP_V5,
}

View File

@ -0,0 +1,36 @@
"""This module provides a list of defines that is passed in to compiling.
"""
visibility(["//bazel/toolchains/cc"])
WIN_BOOST_DEFINES = select({
"@platforms//os:windows": ["BOOST_ALL_NO_LIB"],
"//conditions:default": [],
})
WINDOWS_DEFAULT_DEFINES = select({
"@platforms//os:windows": [
# This tells the Windows compiler not to link against the .lib files and
# to use boost as a bunch of header-only libraries.
"BOOST_ALL_NO_LIB",
"_UNICODE",
"UNICODE",
# Temporary fixes to allow compilation with VS2017.
"_SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING",
"_SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING",
"_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING",
# TODO(SERVER-60151): Until we are fully in C++20 mode, it is easier to
# simply suppress C++20 deprecations. After we have switched over we
# should address any actual deprecated usages and then remove this flag.
"_SILENCE_ALL_CXX20_DEPRECATION_WARNINGS",
"_CONSOLE",
"_CRT_SECURE_NO_WARNINGS",
"_ENABLE_EXTENDED_ALIGNED_STORAGE",
"_SCL_SECURE_NO_WARNINGS",
],
"//conditions:default": [],
})
WINDOWS_DEFINES = WIN_BOOST_DEFINES + WINDOWS_DEFAULT_DEFINES

View File

@ -185,7 +185,7 @@ py_download = repository_rule(
doc = "Path you'd expect the python interpreter binary to live.",
),
"build_tpl": attr.label(
default = "//bazel/toolchains/python:python_toolchain.BUILD",
default = "//bazel/toolchains/python:python_toolchain.BUILD.tmpl",
doc = "Label denoting the BUILD file template that get's installed in the repo.",
),
},
@ -204,7 +204,6 @@ def setup_mongo_python_toolchains():
name = "py_linux_arm64",
arch = "aarch64",
os = "linux",
build_tpl = "//bazel/toolchains/python:python_toolchain.BUILD",
sha256 = URLS_MAP["linux_aarch64"]["sha"],
urls = [URLS_MAP["linux_aarch64"]["url"]],
)
@ -213,7 +212,6 @@ def setup_mongo_python_toolchains():
name = "py_linux_x86_64",
arch = "amd64",
os = "linux",
build_tpl = "//bazel/toolchains/python:python_toolchain.BUILD",
sha256 = URLS_MAP["linux_amd64"]["sha"],
urls = [URLS_MAP["linux_amd64"]["url"]],
)
@ -222,7 +220,6 @@ def setup_mongo_python_toolchains():
name = "py_linux_ppc64le",
arch = "ppc64le",
os = "linux",
build_tpl = "//bazel/toolchains/python:python_toolchain.BUILD",
sha256 = URLS_MAP["linux_ppc64le"]["sha"],
urls = [URLS_MAP["linux_ppc64le"]["url"]],
)
@ -231,7 +228,6 @@ def setup_mongo_python_toolchains():
name = "py_linux_s390x",
arch = "s390x",
os = "linux",
build_tpl = "//bazel/toolchains/python:python_toolchain.BUILD",
sha256 = URLS_MAP["linux_s390x"]["sha"],
urls = [URLS_MAP["linux_s390x"]["url"]],
)
@ -240,7 +236,6 @@ def setup_mongo_python_toolchains():
name = "py_windows_x86_64",
arch = "amd64",
os = "windows",
build_tpl = "//bazel/toolchains/python:python_toolchain.BUILD",
interpreter_path = "dist/python.exe",
sha256 = URLS_MAP["windows_amd64"]["sha"],
urls = [URLS_MAP["windows_amd64"]["url"]],
@ -250,7 +245,6 @@ def setup_mongo_python_toolchains():
name = "py_macos_arm64",
arch = "aarch64",
os = "macos",
build_tpl = "//bazel/toolchains/python:python_toolchain.BUILD",
sha256 = URLS_MAP["macos_aarch64"]["sha"],
urls = [URLS_MAP["macos_aarch64"]["url"]],
)
@ -259,7 +253,6 @@ def setup_mongo_python_toolchains():
name = "py_macos_x86_64",
arch = "amd64",
os = "macos",
build_tpl = "//bazel/toolchains/python:python_toolchain.BUILD",
sha256 = URLS_MAP["macos_x86_64"]["sha"],
urls = [URLS_MAP["macos_x86_64"]["url"]],
)