SERVER-97633 Make bazel toolchain configurable via variables files (#30331)

GitOrigin-RevId: 1729ad24a87a09b2ea2fb3f799d578303903edf2
This commit is contained in:
Ryan Berryhill 2024-12-20 13:08:14 -05:00 committed by MongoDB Bot
parent fefcf8a0b5
commit 6c86981d33
24 changed files with 677 additions and 375 deletions

View File

@ -188,6 +188,10 @@ build:remote_link --strategy=ExtractDebugInfo=remote
build:remote_link --strategy=StripDebugInfo=remote
build:remote_link --features=-thin_archive
# 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.
build:linux --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
# Disable the default compiler flags to avoid certain flags that conflict with flags we setup.
build:windows --features=-smaller_binary
build:windows --features=-frame_pointer
@ -240,10 +244,19 @@ build:clang-tidy --//bazel/config:compiler_type=clang
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
build:clang-tidy --@bazel_clang_tidy//:clang_tidy_executable=@mongo_toolchain//:clang_tidy
build:clang-tidy --@bazel_clang_tidy//:clang_tidy_additional_deps=@mongo_toolchain//:all
build:clang-tidy --@bazel_clang_tidy//:clang_tidy_executable=//:clang_tidy
build:clang-tidy --@bazel_clang_tidy//:clang_tidy_additional_deps=//:toolchain_files
build:clang-tidy --@bazel_clang_tidy//:clang_tidy_plugin_deps=//src/mongo/tools/mongo_tidy_checks:mongo_tidy_checks
# clang-tidy config using the v4 toolchain
--config=clang-tidy-v4
build:clang-tidy-v4 --config=clang-tidy
build:clang-tidy --//bazel/config:mongo_toolchain_version=v4
# clang-tidy config using the v5 toolchain
--config=clang-tidy-v5
build:clang-tidy-v5 --config=clang-tidy
build:clang-tidy-v5 --//bazel/config:mongo_toolchain_version=v5
# if you don't have access to the remote execution cluster above, use the local config
# described below.

View File

@ -1,5 +1,6 @@
load("@hedron_compile_commands//:refresh_compile_commands.bzl", "refresh_compile_commands")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("//bazel/toolchains:mongo_toolchain.bzl", "setup_mongo_toolchain_aliases")
package(default_visibility = ["//visibility:public"])
@ -21,6 +22,8 @@ alias(
actual = "//buildscripts:codeowners",
)
setup_mongo_toolchain_aliases()
# This rule makes it possible to set the clang-tidy configuration setting:
genrule(
name = "clang_tidy_config",

View File

@ -148,10 +148,10 @@ add_option(
help="Configures the path to the evergreen configured tmp directory.",
default=None,
)
# Preload to perform early fetch fo repositories
tool = Tool("integrate_bazel")
tool.exists(DefaultEnvironment())
mongo_toolchain_execroot = DefaultEnvironment().PrefetchToolchain()
integrate_bazel = Tool("integrate_bazel")
integrate_bazel.exists(DefaultEnvironment())
mongo_toolchain_execroot = DefaultEnvironment().BazelExecroot()
build_profile = build_profiles.get_build_profile(get_option("build-profile"))
@ -755,31 +755,6 @@ add_option(
help="Name a toolchain root for use with toolchain selection Variables files in etc/scons",
)
if mongo_toolchain_execroot:
bin_dir = os.path.join(mongo_toolchain_execroot, "external/mongo_toolchain/v4/bin")
gcc_path = os.path.dirname(
os.path.realpath(os.path.join(bin_dir, os.readlink(os.path.join(bin_dir, "g++"))))
)
clang_path = os.path.dirname(
os.path.realpath(os.path.join(bin_dir, os.readlink(os.path.join(bin_dir, "clang++"))))
)
else:
gcc_path = ""
clang_path = ""
add_option(
"bazel-toolchain-clang",
default=clang_path,
help="used in Variables files to help find the real bazel toolchain location.",
)
add_option(
"bazel-toolchain-gcc",
default=gcc_path,
help="used in Variables files to help find the real bazel toolchain location.",
)
add_option(
"msvc-debugging-format",
choices=["codeview", "pdb"],
@ -1194,6 +1169,12 @@ env_vars.Add(
help="Path to the dsymutil utility",
)
env_vars.Add(
"MONGO_TOOLCHAIN_VERSION",
default="v4",
help="Version of the mongo toolchain to use in bazel.",
)
def validate_dwarf_version(key, val, env):
if val == "4" or val == "5" or val == "":
@ -1813,6 +1794,7 @@ if ARGUMENTS.get("CC") and ARGUMENTS.get("CXX"):
# Early load to setup env functions
tool = Tool("integrate_bazel")
tool.exists(env)
env.PrefetchToolchain(env.get("MONGO_TOOLCHAIN_VERSION"))
# The placement of this is intentional. Here we setup an atexit method to store tooling metrics.
# We should only register this function after env, env_vars and the parser have been properly initialized.
@ -4483,7 +4465,11 @@ def doConfigure(myenv):
llvm_symbolizer = env["LLVM_SYMBOLIZER"]
if not os.path.isabs(llvm_symbolizer):
llvm_symbolizer = myenv.WhereIs(llvm_symbolizer)
# WhereIs looks at the path, but not the PWD. If it fails, try assuming
# the path is relative to the PWD.
llvm_symbolizer = myenv.WhereIs(llvm_symbolizer) or os.path.realpath(
llvm_symbolizer
)
if not myenv.File(llvm_symbolizer).exists():
myenv.FatalError(f"Symbolizer binary at path {llvm_symbolizer} does not exist")

View File

@ -1,4 +1,5 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("//bazel/toolchains:mongo_toolchain.bzl", "setup_mongo_toolchains")
# Apple cc toolchain needs to be loaded before regular cc toolchain or else Apple will just use regular cc toolchain
http_archive(
@ -19,7 +20,6 @@ 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:mongo_toolchain.bzl", "toolchain_download")
http_archive(
name = "bazel_clang_tidy",
@ -38,7 +38,7 @@ http_archive(
setup_local_config_platform(name = "internal_platforms_do_not_use")
toolchain_download(name = "mongo_toolchain")
setup_mongo_toolchains()
http_archive(
name = "windows_sasl",
@ -65,8 +65,6 @@ filegroup(
url = "https://s3.amazonaws.com/boxes.10gen.com/build/windows_cyrus_sasl-2.1.28.zip",
)
register_toolchains("@mongo_toolchain//:mongo_toolchain")
load("//bazel/toolchains:python_toolchain.bzl", "setup_mongo_python_toolchains")
[register_toolchains(toolchain) for toolchain in setup_mongo_python_toolchains()]

View File

@ -23,6 +23,7 @@ load(
"linker",
"linkstatic",
"lsan",
"mongo_toolchain_version",
"msan",
"opt",
"pgo_profile",
@ -289,6 +290,29 @@ selects.config_setting_group(
],
)
# --------------------------------------
# mongo_toolchain_version options
# --------------------------------------
mongo_toolchain_version(
name = "mongo_toolchain_version",
build_setting_default = "v4",
)
config_setting(
name = "mongo_toolchain_v4",
flag_values = {
"//bazel/config:mongo_toolchain_version": "v4",
},
)
config_setting(
name = "mongo_toolchain_v5",
flag_values = {
"//bazel/config:mongo_toolchain_version": "v5",
},
)
# ==========
# opt
# ==========

View File

@ -14,6 +14,20 @@ compiler_type = rule(
build_setting = config.string(flag = True),
)
# =========
# mongo_toolchain_version
# =========
mongo_toolchain_version_provider = provider(
doc = "Select the mongo toolchain version (e.g.: v4)",
fields = {"mongo_toolchain_version": "Choose one of [v4, v5]"},
)
mongo_toolchain_version = rule(
implementation = lambda ctx: mongo_toolchain_version_provider(mongo_toolchain_version = ctx.build_setting_value),
build_setting = config.string(flag = True),
)
# ==========
# linker
# ==========

View File

@ -1,21 +1,8 @@
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:mongo_toolchain_version.bzl", "TOOLCHAIN_MAP")
load("//bazel:utils.bzl", "get_host_distro_major_version")
_OS_MAP = {
"macos": "@platforms//os:osx",
"linux": "@platforms//os:linux",
"windows": "@platforms//os:windows",
}
_ARCH_MAP = {
"amd64": "@platforms//cpu:x86_64",
"aarch64": "@platforms//cpu:arm64",
"x86_64": "@platforms//cpu:x86_64",
"ppc64le": "@platforms//cpu:ppc",
"s390x": "@platforms//cpu:s390x",
}
def _setup_local_config_platform(ctx):
"""
Generates our own local_config_platform, overriding bazel's built in generation.
@ -33,8 +20,8 @@ def _setup_local_config_platform(ctx):
arch = ctx.os.arch
os_constraint = _OS_MAP[os]
arch_constraint = _ARCH_MAP[arch]
os_constraint = OS_TO_PLATFORM_MAP[os]
arch_constraint = ARCH_TO_PLATFORM_MAP[arch]
constraints = [os_constraint, arch_constraint]
@ -51,6 +38,12 @@ def _setup_local_config_platform(ctx):
remote_execution_pool = "x86_64" if arch == "amd64" else "default"
result = None
toolchain_key = "{distro}_{arch}".format(distro = distro, arch = arch)
toolchain_exists = False
for version in TOOLCHAIN_MAP:
if toolchain_key in TOOLCHAIN_MAP[version]:
toolchain_exists = True
break
if ctx.os.environ.get("USE_NATIVE_TOOLCHAIN"):
exec_props = ""
result = {"USE_NATIVE_TOOLCHAIN": "1"}
@ -68,7 +61,7 @@ def _setup_local_config_platform(ctx):
},
""" % (container_url, remote_execution_pool)
result = {"DISTRO": distro}
elif distro != None and distro in TOOLCHAIN_MAP:
elif distro != None and toolchain_exists:
constraints_str += ',\n "@//bazel/platforms:use_mongo_toolchain"'
result = {"DISTRO": distro}
exec_props = ""

View File

@ -0,0 +1,23 @@
ARCH_NORMALIZE_MAP = {
"amd64": "x86_64",
"x86_64": "x86_64",
"arm64": "aarch64",
"aarch64": "aarch64",
"ppc64le": "ppc64le",
"s390x": "s390x",
}
ARCH_TO_PLATFORM_MAP = {
"amd64": "@platforms//cpu:x86_64",
"x86_64": "@platforms//cpu:x86_64",
"arm64": "@platforms//cpu:arm64",
"aarch64": "@platforms//cpu:arm64",
"ppc64le": "@platforms//cpu:ppc",
"s390x": "@platforms//cpu:s390x",
}
OS_TO_PLATFORM_MAP = {
"macos": "@platforms//os:osx",
"linux": "@platforms//os:linux",
"windows": "@platforms//os:windows",
}

View File

@ -1,16 +1,27 @@
# This file exists to describe "mongo_toolchain", the http_archive defined in WORKSPACE.bazel
load("@//bazel/toolchains:mongo_cc_toolchain_config.bzl", "mongo_cc_toolchain_config")
load("@mongo_toolchain//:mongo_toolchain_flags.bzl", "CLANG_INCLUDE_DIRS", "COMMON_BINDIRS", "COMMON_BUILTIN_INCLUDE_DIRECTORIES", "COMMON_INCLUDE_DIRECTORIES", "COMMON_LINK_FLAGS", "GCC_INCLUDE_DIRS")
load("@mongo_toolchain_{version}//:mongo_toolchain_flags.bzl", "CLANG_INCLUDE_DIRS", "COMMON_BINDIRS", "COMMON_BUILTIN_INCLUDE_DIRECTORIES", "COMMON_INCLUDE_DIRECTORIES", "COMMON_LINK_FLAGS", "GCC_INCLUDE_DIRS")
package(default_visibility = ["//visibility:public"])
# Helper target for the toolchain (see below):
filegroup(
name = "all",
name = "all_files",
srcs = glob(["**/*"]),
)
# Export headers used for clang-tidy checks.
cc_library(
name = "llvm_headers",
hdrs = glob([
"stow/llvm-{version}/include/**/*.h",
"stow/llvm-{version}/include/**/*.inc",
"stow/llvm-{version}/include/**/*.def",
]),
visibility = ["//visibility:public"],
)
# A note on toolchains: this is complicated! Bazel requires multiple layers of indirection.
#
# In this case, we have:
@ -47,21 +58,21 @@ mongo_cc_toolchain_config(
# Note: You might assume that the specification of `compiler_name` (above) would be sufficient to make Bazel
# use the correct binary. This is incorrect; Bazel appears to unconditionally use the `gcc` tool_path. As a result,
# we have to conditionally set the value pointed to by `gcc`.
"gcc": "v4/bin/gcc",
"g++": "v4/bin/g++",
"cpp": "v4/bin/cpp",
"ar": "v4/bin/ar",
"nm": "v4/bin/nm",
"ld": "v4/bin/ld",
"as": "v4/bin/as",
"dwp": "v4/bin/dwp",
"objcopy": "v4/bin/llvm-objcopy",
"objdump": "v4/bin/objdump",
"gcov": "v4/bin/gcov",
"strip": "v4/bin/strip",
"gcc": "{version}/bin/gcc",
"g++": "{version}/bin/g++",
"cpp": "{version}/bin/cpp",
"ar": "{version}/bin/ar",
"nm": "{version}/bin/nm",
"ld": "{version}/bin/ld",
"as": "{version}/bin/as",
"dwp": "{version}/bin/dwp",
"objcopy": "{version}/bin/llvm-objcopy",
"objdump": "{version}/bin/objdump",
"gcov": "{version}/bin/gcov",
"strip": "{version}/bin/strip",
"llvm-cov": "/bin/false", # /bin/false = we're not using llvm-cov
},
toolchain_identifier = "gcc_v4_toolchain",
toolchain_identifier = "gcc_toolchain",
verbose = True,
)
@ -72,41 +83,43 @@ mongo_cc_toolchain_config(
cpu = "{bazel_toolchain_cpu}",
cxx_builtin_include_directories = COMMON_BUILTIN_INCLUDE_DIRECTORIES,
extra_ldflags = LINK_FLAGS,
includes = CLANG_INCLUDE_DIRS + COMMON_INCLUDE_DIRECTORIES + COMMON_BUILTIN_INCLUDE_DIRECTORIES,
# Note that CLANG_INCLUDE_DIRS needs to be searched after the common ones, otherwise some files
# will have include_next chains going backwards from the intended order.
includes = COMMON_INCLUDE_DIRECTORIES + COMMON_BUILTIN_INCLUDE_DIRECTORIES + CLANG_INCLUDE_DIRS,
tool_paths = {
# Note: You might assume that the specification of `compiler_name` (above) would be sufficient to make Bazel
# use the correct binary. This is incorrect; Bazel appears to unconditionally use the `gcc` tool_path. As a result,
# we have to conditionally set the value pointed to by `gcc`.
# TODO(SERVER-87211): The two lines below are using the absolute path to help clang find the sanitizer .a
# files. Switch these to the v4/bin/* paths once EngFlow fixes the issue where symlinks are fully resolved
# files. Switch these to the {version}/bin/* paths once EngFlow fixes the issue where symlinks are fully resolved
# when copied to the remote execution system.
"gcc": "stow/llvm-v4/bin/clang",
"g++": "stow/llvm-v4/bin/clang++",
"cpp": "v4/bin/cpp",
"ar": "v4/bin/ar",
"nm": "v4/bin/nm",
"ld": "v4/bin/ld",
"as": "v4/bin/as",
"dwp": "v4/bin/dwp",
"objcopy": "v4/bin/llvm-objcopy",
"objdump": "v4/bin/objdump",
"gcov": "v4/bin/gcov",
"strip": "v4/bin/strip",
"gcc": "{version}/bin/clang",
"g++": "{version}/bin/clang++",
"cpp": "{version}/bin/cpp",
"ar": "{version}/bin/ar",
"nm": "{version}/bin/nm",
"ld": "{version}/bin/ld",
"as": "{version}/bin/as",
"dwp": "{version}/bin/dwp",
"objcopy": "{version}/bin/llvm-objcopy",
"objdump": "{version}/bin/objdump",
"gcov": "{version}/bin/gcov",
"strip": "{version}/bin/strip",
"llvm-cov": "/bin/false", # /bin/false = we're not using llvm-cov
},
toolchain_identifier = "clang_v4_toolchain",
toolchain_identifier = "clang_toolchain",
verbose = True,
)
cc_toolchain(
name = "cc_mongo_toolchain",
all_files = ":all",
ar_files = ":all",
compiler_files = ":all",
dwp_files = ":all",
linker_files = ":all",
objcopy_files = ":all",
strip_files = ":all",
all_files = ":all_files",
ar_files = ":all_files",
compiler_files = ":all_files",
dwp_files = ":all_files",
linker_files = ":all_files",
objcopy_files = ":all_files",
strip_files = ":all_files",
toolchain_config = select({
"@//bazel/config:compiler_type_clang": ":cc_clang_toolchain_config",
"@//bazel/config:compiler_type_gcc": ":cc_gcc_toolchain_config",
@ -125,6 +138,9 @@ toolchain(
"@platforms//cpu:{bazel_toolchain_cpu}",
"@//bazel/platforms:use_mongo_toolchain",
],
target_settings = [
"@//bazel/config:mongo_toolchain_{version}",
],
toolchain = ":cc_mongo_toolchain",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)
@ -134,6 +150,6 @@ toolchain(
filegroup(
name = "clang_tidy",
srcs = [
"v4/bin/clang-tidy",
"{version}/bin/clang-tidy",
],
)

View File

@ -1,19 +1,18 @@
load("//bazel:utils.bzl", "get_host_distro_major_version", "retry_download_and_extract")
load("//bazel/platforms:normalize.bzl", "ARCH_NORMALIZE_MAP")
load("//bazel/toolchains:mongo_toolchain_version.bzl", "TOOLCHAIN_MAP")
load("//bazel/toolchains:mongo_toolchain_flags.bzl", "ARCH_NORMALIZE_MAP")
_OS_MAP = {
"macos": "@platforms//os:osx",
"linux": "@platforms//os:linux",
"windows": "@platforms//os:windows",
}
_ARCH_MAP = {
"aarch64": "@platforms//cpu:arm64",
"x86_64": "@platforms//cpu:x86_64",
"ppc64le": "@platforms//cpu:ppc",
"s390x": "@platforms//cpu:s390x",
}
def _generate_noop_toolchain(ctx, substitutions):
# BUILD file is required for a no-op
ctx.file(
"BUILD.bazel",
"# {} toolchain not supported on this platform".format(ctx.attr.version),
)
ctx.template(
"mongo_toolchain_flags.bzl",
ctx.attr.flags_tpl,
substitutions = substitutions,
)
def _toolchain_download(ctx):
if ctx.attr.os:
@ -28,23 +27,16 @@ def _toolchain_download(ctx):
arch = ARCH_NORMALIZE_MAP[arch]
version = ctx.attr.version
if os != "linux":
# BUILD file is required for a no-op
substitutions = {
"{platforms_arch}": "arm64",
"{bazel_toolchain_cpu}": arch,
"{arch}": arch,
"{version}": version,
}
ctx.template(
"BUILD.bazel",
ctx.attr.build_tpl,
substitutions = substitutions,
)
ctx.template(
"mongo_toolchain_flags.bzl",
ctx.attr.flags_tpl,
substitutions = substitutions,
)
_generate_noop_toolchain(ctx, substitutions)
ctx.report_progress("mongo toolchain not supported on " + os + " and " + arch)
return None
@ -53,24 +45,28 @@ def _toolchain_download(ctx):
"{platforms_arch}": "arm64",
"{bazel_toolchain_cpu}": arch,
"{arch}": arch,
"{version}": version,
}
elif arch == "x86_64":
substitutions = {
"{platforms_arch}": "x86_64",
"{bazel_toolchain_cpu}": "x86_64",
"{arch}": arch,
"{version}": version,
}
elif arch == "ppc64le":
substitutions = {
"{platforms_arch}": "ppc64le",
"{bazel_toolchain_cpu}": "ppc",
"{arch}": arch,
"{version}": version,
}
elif arch == "s390x":
substitutions = {
"{platforms_arch}": "s390x",
"{bazel_toolchain_cpu}": arch,
"{arch}": arch,
"{version}": version,
}
distro = get_host_distro_major_version(ctx)
@ -79,8 +75,8 @@ def _toolchain_download(ctx):
toolchain_key = "{distro}_{arch}".format(distro = distro, arch = arch)
if toolchain_key in TOOLCHAIN_MAP:
toolchain_info = TOOLCHAIN_MAP[toolchain_key]
if toolchain_key in TOOLCHAIN_MAP[version]:
toolchain_info = TOOLCHAIN_MAP[version][toolchain_key]
urls = toolchain_info["url"]
sha = toolchain_info["sha"]
@ -93,8 +89,7 @@ def _toolchain_download(ctx):
sha256 = sha,
)
ctx.report_progress("generating toolchain build file")
ctx.report_progress("generating toolchain " + version + " build file")
ctx.template(
"BUILD.bazel",
ctx.attr.build_tpl,
@ -105,8 +100,10 @@ def _toolchain_download(ctx):
ctx.attr.flags_tpl,
substitutions = substitutions,
)
else:
fail("Mongo toolchain not supported on " + distro + " and " + arch + ". Toolchain key not found: " + toolchain_key)
_generate_noop_toolchain(ctx, substitutions)
ctx.report_progress("Mongo toolchain " + version + " not supported on " + distro + " and " + arch + ". Toolchain key not found: " + toolchain_key)
return None
@ -121,13 +118,64 @@ toolchain_download = repository_rule(
values = ["amd64", "aarch64", "amd64", "x86_64", "ppc64le", "s390x"],
doc = "Host architecture.",
),
"build_tpl": attr.label(
default = "//bazel/toolchains:mongo_toolchain.BUILD",
doc = "Label denoting the BUILD file template that get's installed in the repo.",
"version": attr.string(
values = ["v4", "v5"],
doc = "Mongodbtoolchain version.",
mandatory = True,
),
"flags_tpl": attr.label(
default = "//bazel/toolchains:mongo_toolchain_flags.bzl",
doc = "Label denoting the toolchain flags template.",
mandatory = True,
),
"build_tpl": attr.label(
default = "//bazel/toolchains:mongo_toolchain.BUILD",
doc = "Label denoting the BUILD file template that gets installed in the repo.",
),
},
)
def setup_mongo_toolchains():
toolchain_download(
name = "mongo_toolchain_v4",
version = "v4",
flags_tpl = "//bazel/toolchains:mongo_toolchain_flags_v4.bzl",
)
toolchain_download(
name = "mongo_toolchain_v5",
version = "v5",
flags_tpl = "//bazel/toolchains:mongo_toolchain_flags_v5.bzl",
)
native.register_toolchains(
"@mongo_toolchain_v4//:all",
"@mongo_toolchain_v5//:all",
)
# Defines aliases for key targets inside the toolchain the user has chosen via
# //bazel/config:mongo_toolchain_version. For example, clang_tidy is a target inside the
# toolchains, so this function defines an alias called clang_tidy that points to
# @mongo_toolchain_vN//:clang_tidy, where N depends on the config value. This lets us use
# the name //:clang_tidy to refer to the clang_tidy of the configured toolchain.
def setup_mongo_toolchain_aliases():
# Map from target's name inside the toolchain to the name we want to alias it to.
toolchain_targets = {
"clang_tidy": "clang_tidy",
"mongo_toolchain": "mongo_toolchain",
"all_files": "toolchain_files",
}
selects = {}
for target in toolchain_targets:
selects[target] = {}
for version in ("v4", "v5"):
toolchain_name = "mongo_toolchain_{}".format(version)
option_name = "//bazel/config:mongo_toolchain_{}".format(version)
for target in toolchain_targets:
selects[target][option_name] = "@{}//:{}".format(toolchain_name, target)
for target, local_alias in toolchain_targets.items():
native.alias(
name = local_alias,
actual = select(selects[target]),
)

View File

@ -1,42 +0,0 @@
ARCH_NORMALIZE_MAP = {
"amd64": "x86_64",
"x86_64": "x86_64",
"arm64": "aarch64",
"aarch64": "aarch64",
"ppc64le": "ppc64le",
"s390x": "s390x",
}
COMMON_LINK_FLAGS = [
"external/mongo_toolchain/stow/gcc-v4/lib/gcc/{arch}-mongodb-linux/11.3.0",
"external/mongo_toolchain/v4/lib",
"external/mongo_toolchain/v4/lib64",
]
COMMON_BUILTIN_INCLUDE_DIRECTORIES = [
"/usr/include/openssl",
"/usr/include/{arch}-linux-gnu",
"/usr/include",
]
COMMON_INCLUDE_DIRECTORIES = [
"external/mongo_toolchain/stow/gcc-v4/include/c++/11.3.0",
"external/mongo_toolchain/stow/gcc-v4/include/c++/11.3.0/{arch}-mongodb-linux",
]
COMMON_BINDIRS = [
"external/mongo_toolchain/v4/bin",
"external/mongo_toolchain/stow/gcc-v4/libexec/gcc/{arch}-mongodb-linux/11.3.0",
"external/mongo_toolchain/stow/gcc-v4/lib/gcc/{arch}-mongodb-linux/11.3.0",
"external/mongo_toolchain/stow/llvm-v4/bin",
]
GCC_INCLUDE_DIRS = [
"external/mongo_toolchain/stow/gcc-v4/lib/gcc/{arch}-mongodb-linux/11.3.0/include",
"external/mongo_toolchain/stow/gcc-v4/lib/gcc/{arch}-mongodb-linux/11.3.0/include-fixed",
]
CLANG_INCLUDE_DIRS = [
"external/mongo_toolchain/stow/gcc-v4/include/c++/11.3.0/backward",
"external/mongo_toolchain/stow/llvm-v4/lib/clang/12.0.1/include",
]

View File

@ -0,0 +1,33 @@
COMMON_LINK_FLAGS = [
"external/mongo_toolchain_v4/stow/gcc-v4/lib/gcc/{arch}-mongodb-linux/11.3.0",
"external/mongo_toolchain_v4/v4/lib",
"external/mongo_toolchain_v4/v4/lib64",
]
COMMON_BUILTIN_INCLUDE_DIRECTORIES = [
"/usr/include/openssl",
"/usr/include/{arch}-mongodb-linux",
"/usr/include",
]
COMMON_INCLUDE_DIRECTORIES = [
"external/mongo_toolchain_v4/stow/gcc-v4/include/c++/11.3.0",
"external/mongo_toolchain_v4/stow/gcc-v4/include/c++/11.3.0/{arch}-mongodb-linux",
]
COMMON_BINDIRS = [
"external/mongo_toolchain_v4/v4/bin",
"external/mongo_toolchain_v4/stow/gcc-v4/libexec/gcc/{arch}-mongodb-linux/11.3.0",
"external/mongo_toolchain_v4/stow/gcc-v4/lib/gcc/{arch}-mongodb-linux/11.3.0",
"external/mongo_toolchain_v4/stow/llvm-v4/bin",
]
GCC_INCLUDE_DIRS = [
"external/mongo_toolchain_v4/stow/gcc-v4/lib/gcc/{arch}-mongodb-linux/11.3.0/include",
"external/mongo_toolchain_v4/stow/gcc-v4/lib/gcc/{arch}-mongodb-linux/11.3.0/include-fixed",
]
CLANG_INCLUDE_DIRS = [
"external/mongo_toolchain_v4/stow/gcc-v4/include/c++/11.3.0/backward",
"external/mongo_toolchain_v4/stow/llvm-v4/lib/clang/12.0.1/include",
]

View File

@ -0,0 +1,33 @@
COMMON_LINK_FLAGS = [
"external/mongo_toolchain_v5/stow/gcc-v5/lib/gcc/{arch}-mongodb-linux/14.2.0",
"external/mongo_toolchain_v5/v5/lib",
"external/mongo_toolchain_v5/v5/lib64",
]
COMMON_BUILTIN_INCLUDE_DIRECTORIES = [
"/usr/include/openssl",
"/usr/include/{arch}-mongodb-linux",
"/usr/include",
]
COMMON_INCLUDE_DIRECTORIES = [
"external/mongo_toolchain_v5/stow/gcc-v5/include/c++/14.2.0",
"external/mongo_toolchain_v5/stow/gcc-v5/include/c++/14.2.0/{arch}-mongodb-linux",
]
COMMON_BINDIRS = [
"external/mongo_toolchain_v5/v5/bin",
"external/mongo_toolchain_v5/stow/gcc-v5/libexec/gcc/{arch}-mongodb-linux/14.2.0",
"external/mongo_toolchain_v5/stow/gcc-v5/lib/gcc/{arch}-mongodb-linux/14.2.0",
"external/mongo_toolchain_v5/stow/llvm-v5/bin",
]
GCC_INCLUDE_DIRS = [
"external/mongo_toolchain_v5/stow/gcc-v5/lib/gcc/{arch}-mongodb-linux/14.2.0/include",
"external/mongo_toolchain_v5/stow/gcc-v5/lib/gcc/{arch}-mongodb-linux/14.2.0/include-fixed",
]
CLANG_INCLUDE_DIRS = [
"external/mongo_toolchain_v5/stow/gcc-v5/include/c++/14.2.0/backward",
"external/mongo_toolchain_v5/stow/llvm-v5/lib/clang/19/include",
]

View File

@ -1,107 +1,7 @@
# Use mongo/bazel/toolchains/toolchain_generator.py to generate this mapping for a given patch build
load("//bazel/toolchains:mongo_toolchain_version_v4.bzl", "TOOLCHAIN_MAP_V4")
load("//bazel/toolchains:mongo_toolchain_version_v5.bzl", "TOOLCHAIN_MAP_V5")
TOOLCHAIN_URL_FORMAT = "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_{underscore_platform_name}_{patch_build_id}_{patch_build_date}.tar.gz"
TOOLCHAIN_PATCH_BUILD_ID = "acdc1709a01126c67dbd4f0f37491e171f64ec29"
TOOLCHAIN_PATCH_BUILD_DATE = "24_10_11_23_01_02"
TOOLCHAIN_MAP = {
"amazon_linux_2023_aarch64": {
"platform_name": "amazon2023-arm64",
"sha": "405b63f369fdcc9767314a9ae9d488a4f8ad1eaecd181f5f95fc090d6b218614",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_amazon2023_arm64_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"amazon_linux_2023_x86_64": {
"platform_name": "amazon2023",
"sha": "48f35037f7e9f49c3c9885ea57d9cc59f27550a6e0dfb226e8f2396373b1657b",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_amazon2023_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"amazon_linux_2_aarch64": {
"platform_name": "amazon2-arm64",
"sha": "1db4c8ef6b30b3a72f2c929247dcffed3a99356099b84c16b8b20efdf99e00d6",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_amazon2_arm64_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"amazon_linux_2_x86_64": {
"platform_name": "amazon2",
"sha": "e2bf59dacb789bd3ed708bafb7bf4e432f611f19d6b888340e3b73eee6949b31",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_amazon2_11bae3c145a48dd7be9ee8aa44e5591783f787aa_24_01_09_16_10_07.tar.gz",
},
"debian10_x86_64": {
"platform_name": "debian10",
"sha": "9fd2e74e160699de706aac08bd94aefa7539e835693773c56ff6019847df7cd7",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_debian10_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"debian12_x86_64": {
"platform_name": "debian12",
"sha": "d34bba732f9a4846d6eb27bb1c2f00586fb341a249a12fbb0216268b3b2e69ab",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_debian12_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"rhel8_aarch64": {
"platform_name": "rhel82-arm64",
"sha": "5b56277cc3a9820fe09774d6a2a6c861b306d7cd8a7bca55848193e249909033",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_rhel82_arm64_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"rhel8_ppc64le": {
"platform_name": "rhel81-ppc64le",
"sha": "b62574a447e0e5120475c7ef0ec0e821548a32a103999ed350b05adcc9073b55",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_rhel81_ppc64le_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"rhel8_s390x": {
"platform_name": "rhel80-zseries",
"sha": "5d4f93968672f324e532b62eb9345351b407a866650d824eee79d295d6613606",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_rhel80_zseries_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"rhel8_x86_64": {
"platform_name": "rhel80",
"sha": "4b3406838c9adbb47d308ba4028ca88948f9bab336eef591f7b8395781ab5cd5",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_rhel80_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"rhel9_aarch64": {
"platform_name": "rhel90-arm64",
"sha": "7c6ce149660197f4b63c50404e0c8604285299f6fcf67c1f9bae1de0bad606e1",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_rhel90_arm64_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"rhel9_x86_64": {
"platform_name": "rhel90",
"sha": "ba2cf2efd68805eec11580e0276f2f4bde6a94735b0375cae901bcb7099daebe",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_rhel90_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"suse15_x86_64": {
"platform_name": "suse15",
"sha": "f7ac487d2ace8d4b8793de712f9e7d7cf3bec35bd82da39b30f42db76f59b919",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_suse15_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"ubuntu18_x86_64": {
"platform_name": "ubuntu1804",
"sha": "526b64a04731275ae52b9d8b062efa20c3db183091cdbffd023d86e27c93b490",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_ubuntu1804_11bae3c145a48dd7be9ee8aa44e5591783f787aa_24_01_09_16_10_07.tar.gz",
},
"ubuntu20_aarch64": {
"platform_name": "ubuntu2004-arm64",
"sha": "1f0bee3bde3611d1f2a5f10ea521f333f508d0f3fbd3f4675c77bf0aed1037ec",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_ubuntu2004_arm64_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"ubuntu20_x86_64": {
"platform_name": "ubuntu2004",
"sha": "1dc69e016569ddefa925ee09961e0e466ed80985b767e0f634c0c80286573952",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_ubuntu2004_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"ubuntu22_aarch64": {
"platform_name": "ubuntu2204-arm64",
"sha": "536829b77db6b40fc4b29f848e0b31715e61fe7bfeca0a58575e52bdf4ec0b2b",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_ubuntu2204_arm64_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"ubuntu22_x86_64": {
"platform_name": "ubuntu2204",
"sha": "e7b305c973b69268983431e1b11ddf1f2fbf38715ede2c415b0cf9a4fcdc0615",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_ubuntu2204_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"ubuntu24_aarch64": {
"platform_name": "ubuntu2404-arm64",
"sha": "72e8188295d3296e0361534762e1f4226242b1c65001628cff1f9aac60d94a94",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_ubuntu2404_arm64_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"ubuntu24_x86_64": {
"platform_name": "ubuntu2404",
"sha": "d08520df222f81253eb9b9802fd8c7acd02dd0d60f08776b45ea47401754f947",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_ubuntu2404_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"v4": TOOLCHAIN_MAP_V4,
"v5": TOOLCHAIN_MAP_V5,
}

View File

@ -5,7 +5,58 @@ import hashlib
import os
import pathlib
import tempfile
import urllib.request
import requests
from requests.adapters import HTTPAdapter, Retry
TOOLCHAIN_URL_FORMAT = (
"https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/"
"bazel_{version}_toolchain_builder_"
"{underscore_platform_name}_{patch_build_id}_{patch_build_date}"
".tar.gz"
)
PLATFORM_NAME_MAP = {
"amazon_linux_2023_aarch64": "amazon2023-arm64",
"amazon_linux_2023_x86_64": "amazon2023",
"amazon_linux_2_aarch64": "amazon2-arm64",
"amazon_linux_2_x86_64": "amazon2",
"debian10_x86_64": "debian10",
"debian12_x86_64": "debian12",
"rhel8_aarch64": "rhel82-arm64",
"rhel8_ppc64le": "rhel81-ppc64le",
"rhel8_s390x": "rhel80-zseries",
"rhel8_x86_64": "rhel80",
"rhel9_aarch64": "rhel90-arm64",
"rhel9_x86_64": "rhel90",
"suse15_x86_64": "suse15",
"ubuntu18_x86_64": "ubuntu1804",
"ubuntu20_aarch64": "ubuntu2004-arm64",
"ubuntu20_x86_64": "ubuntu2004",
"ubuntu22_aarch64": "ubuntu2204-arm64",
"ubuntu22_x86_64": "ubuntu2204",
"ubuntu24_aarch64": "ubuntu2404-arm64",
"ubuntu24_x86_64": "ubuntu2404",
}
REQUESTS_SESSION = requests.Session()
REQUESTS_SESSION.mount(
"https://",
HTTPAdapter(max_retries=Retry(total=5, backoff_factor=1, status_forcelist=[502, 503, 504])),
)
def download_toolchain(toolchain_url: str, local_path: str) -> bool:
print(f"Downloading {toolchain_url}...")
response = REQUESTS_SESSION.get(toolchain_url)
if response.status_code != requests.codes.ok:
print(f"WARNING: HTTP {response.status_code} status downloading {toolchain_url}")
return False
with open(local_path, "wb") as f:
f.write(response.content)
return True
def sha256_file(filename: str) -> str:
@ -23,22 +74,22 @@ def main():
"patch_build_date_string",
help="Patch build date string from toolchain-builder project, get this at the task URL, ex the date is 24_01_09_16_10_07 for https://spruce.mongodb.com/task/toolchain_builder_amazon2023_compile_11bae3c145a48dd7be9ee8aa44e5591783f787aa_24_01_09_16_10_07/",
)
parser.add_argument("toolchain_version", help="Toolchain version e.g., v4")
args = parser.parse_args()
version_str = args.toolchain_version
mongo_toolchain_version = {}
version_file_path = os.path.join(
pathlib.Path(__file__).parent.resolve(), "mongo_toolchain_version.bzl"
pathlib.Path(__file__).parent.resolve(), f"mongo_toolchain_version_{version_str}.bzl"
)
with open(version_file_path, "r") as f:
code = compile(f.read(), version_file_path, "exec")
exec(code, {}, mongo_toolchain_version)
for toolchain_name, toolchain in mongo_toolchain_version["TOOLCHAIN_MAP"].items():
underscore_platform_name = toolchain["platform_name"].replace("-", "_")
for toolchain_name, platform_name in PLATFORM_NAME_MAP.items():
underscore_platform_name = platform_name.replace("-", "_")
toolchain_url = mongo_toolchain_version["TOOLCHAIN_URL_FORMAT"].format(
platform_name=toolchain["platform_name"],
toolchain_url = TOOLCHAIN_URL_FORMAT.format(
version=version_str,
platform_name=platform_name,
underscore_platform_name=underscore_platform_name,
patch_build_id=args.patch_build_id,
patch_build_date=args.patch_build_date_string,
@ -47,33 +98,31 @@ def main():
temp_dir = tempfile.gettempdir()
local_tarball_path = os.path.join(
temp_dir,
f"bazel_v4_toolchain_builder_{underscore_platform_name}_{args.patch_build_id}.tar.gz",
f"bazel_{version_str}_toolchain_builder_{underscore_platform_name}_{args.patch_build_id}.tar.gz",
)
print(f"Downloading {toolchain_url}...")
urllib.request.urlretrieve(toolchain_url, local_tarball_path)
if not download_toolchain(toolchain_url, local_tarball_path):
print(f"Toolchain {toolchain_name} for {platform_name} not available, skipping")
continue
sha = sha256_file(local_tarball_path)
os.remove(local_tarball_path)
mongo_toolchain_version["TOOLCHAIN_MAP"][toolchain_name]["sha"] = sha
mongo_toolchain_version["TOOLCHAIN_MAP"][toolchain_name]["url"] = toolchain_url
mongo_toolchain_version[toolchain_name] = {
"platform_name": platform_name,
"sha": sha,
"url": toolchain_url,
}
with open(version_file_path, "w") as f:
print(f"Writing toolchain map to {version_file_path}...")
print(
"# Use mongo/bazel/toolchains/toolchain_generator.py to generate this mapping for a given patch build.\n",
"# Use mongo/bazel/toolchains/mongo_toolchain_version_generator.py to generate this mapping for a given patch build.\n",
file=f,
)
print(
f"TOOLCHAIN_URL_FORMAT = \"{mongo_toolchain_version['TOOLCHAIN_URL_FORMAT']}\"", file=f
)
print(f'TOOLCHAIN_PATCH_BUILD_ID = "{args.patch_build_id}"', file=f)
print(f'TOOLCHAIN_PATCH_BUILD_DATE = "{args.patch_build_date_string}"', file=f)
print("TOOLCHAIN_MAP = {", file=f)
for key, value in sorted(
mongo_toolchain_version["TOOLCHAIN_MAP"].items(), key=lambda x: x[0]
):
print(f"TOOLCHAIN_MAP_{version_str.upper()} = {{", file=f)
for key, value in sorted(mongo_toolchain_version.items(), key=lambda x: x[0]):
print(f' "{key}": {{', file=f)
for subkey, subvalue in sorted(value.items(), key=lambda x: x[0]):
print(f' "{subkey}": "{subvalue}",', file=f)

View File

@ -0,0 +1,106 @@
# Use mongo/bazel/toolchains/mongo_toolchain_version_generator.py to generate this mapping for a given patch build.
TOOLCHAIN_PATCH_BUILD_ID = "acdc1709a01126c67dbd4f0f37491e171f64ec29"
TOOLCHAIN_PATCH_BUILD_DATE = "24_10_11_23_01_02"
TOOLCHAIN_MAP_V4 = {
"amazon_linux_2023_aarch64": {
"platform_name": "amazon2023-arm64",
"sha": "405b63f369fdcc9767314a9ae9d488a4f8ad1eaecd181f5f95fc090d6b218614",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_amazon2023_arm64_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"amazon_linux_2023_x86_64": {
"platform_name": "amazon2023",
"sha": "48f35037f7e9f49c3c9885ea57d9cc59f27550a6e0dfb226e8f2396373b1657b",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_amazon2023_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"amazon_linux_2_aarch64": {
"platform_name": "amazon2-arm64",
"sha": "1db4c8ef6b30b3a72f2c929247dcffed3a99356099b84c16b8b20efdf99e00d6",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_amazon2_arm64_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"amazon_linux_2_x86_64": {
"platform_name": "amazon2",
"sha": "e2bf59dacb789bd3ed708bafb7bf4e432f611f19d6b888340e3b73eee6949b31",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_amazon2_11bae3c145a48dd7be9ee8aa44e5591783f787aa_24_01_09_16_10_07.tar.gz",
},
"debian10_x86_64": {
"platform_name": "debian10",
"sha": "9fd2e74e160699de706aac08bd94aefa7539e835693773c56ff6019847df7cd7",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_debian10_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"debian12_x86_64": {
"platform_name": "debian12",
"sha": "d34bba732f9a4846d6eb27bb1c2f00586fb341a249a12fbb0216268b3b2e69ab",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_debian12_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"rhel8_aarch64": {
"platform_name": "rhel82-arm64",
"sha": "5b56277cc3a9820fe09774d6a2a6c861b306d7cd8a7bca55848193e249909033",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_rhel82_arm64_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"rhel8_ppc64le": {
"platform_name": "rhel81-ppc64le",
"sha": "b62574a447e0e5120475c7ef0ec0e821548a32a103999ed350b05adcc9073b55",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_rhel81_ppc64le_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"rhel8_s390x": {
"platform_name": "rhel80-zseries",
"sha": "5d4f93968672f324e532b62eb9345351b407a866650d824eee79d295d6613606",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_rhel80_zseries_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"rhel8_x86_64": {
"platform_name": "rhel80",
"sha": "4b3406838c9adbb47d308ba4028ca88948f9bab336eef591f7b8395781ab5cd5",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_rhel80_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"rhel9_aarch64": {
"platform_name": "rhel90-arm64",
"sha": "7c6ce149660197f4b63c50404e0c8604285299f6fcf67c1f9bae1de0bad606e1",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_rhel90_arm64_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"rhel9_x86_64": {
"platform_name": "rhel90",
"sha": "ba2cf2efd68805eec11580e0276f2f4bde6a94735b0375cae901bcb7099daebe",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_rhel90_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"suse15_x86_64": {
"platform_name": "suse15",
"sha": "f7ac487d2ace8d4b8793de712f9e7d7cf3bec35bd82da39b30f42db76f59b919",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_suse15_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"ubuntu18_x86_64": {
"platform_name": "ubuntu1804",
"sha": "526b64a04731275ae52b9d8b062efa20c3db183091cdbffd023d86e27c93b490",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_ubuntu1804_11bae3c145a48dd7be9ee8aa44e5591783f787aa_24_01_09_16_10_07.tar.gz",
},
"ubuntu20_aarch64": {
"platform_name": "ubuntu2004-arm64",
"sha": "1f0bee3bde3611d1f2a5f10ea521f333f508d0f3fbd3f4675c77bf0aed1037ec",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_ubuntu2004_arm64_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"ubuntu20_x86_64": {
"platform_name": "ubuntu2004",
"sha": "1dc69e016569ddefa925ee09961e0e466ed80985b767e0f634c0c80286573952",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_ubuntu2004_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"ubuntu22_aarch64": {
"platform_name": "ubuntu2204-arm64",
"sha": "536829b77db6b40fc4b29f848e0b31715e61fe7bfeca0a58575e52bdf4ec0b2b",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_ubuntu2204_arm64_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"ubuntu22_x86_64": {
"platform_name": "ubuntu2204",
"sha": "e7b305c973b69268983431e1b11ddf1f2fbf38715ede2c415b0cf9a4fcdc0615",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_ubuntu2204_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"ubuntu24_aarch64": {
"platform_name": "ubuntu2404-arm64",
"sha": "72e8188295d3296e0361534762e1f4226242b1c65001628cff1f9aac60d94a94",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_ubuntu2404_arm64_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
"ubuntu24_x86_64": {
"platform_name": "ubuntu2404",
"sha": "d08520df222f81253eb9b9802fd8c7acd02dd0d60f08776b45ea47401754f947",
"url": "https://mdb-build-public.s3.us-east-1.amazonaws.com/toolchains/bazel_v4_toolchain_builder_ubuntu2404_acdc1709a01126c67dbd4f0f37491e171f64ec29_24_10_11_23_01_02.tar.gz",
},
}

View File

@ -0,0 +1,6 @@
# Use mongo/bazel/toolchains/mongo_toolchain_version_generator.py to generate this mapping for a given patch build.
TOOLCHAIN_PATCH_BUILD_ID = "N/A"
TOOLCHAIN_PATCH_BUILD_DATE = "N/A"
TOOLCHAIN_MAP_V5 = {
}

View File

@ -1,20 +1,7 @@
"""Repository rules for rules_py_simple"""
load("//bazel:utils.bzl", "retry_download_and_extract")
_OS_MAP = {
"macos": "@platforms//os:osx",
"linux": "@platforms//os:linux",
"windows": "@platforms//os:windows",
}
_ARCH_MAP = {
"amd64": "@platforms//cpu:x86_64",
"aarch64": "@platforms//cpu:arm64",
"x86_64": "@platforms//cpu:x86_64",
"ppc64le": "@platforms//cpu:ppc",
"s390x": "@platforms//cpu:s390x",
}
load("//bazel/platforms:normalize.bzl", "ARCH_TO_PLATFORM_MAP", "OS_TO_PLATFORM_MAP")
URLS_MAP = {
"linux_aarch64": {
@ -144,8 +131,8 @@ sys.dont_write_bytecode = True
)
ctx.report_progress("generating build file")
os_constraint = _OS_MAP[os]
arch_constraint = _ARCH_MAP[arch]
os_constraint = OS_TO_PLATFORM_MAP[os]
arch_constraint = ARCH_TO_PLATFORM_MAP[arch]
constraints = [os_constraint, arch_constraint]

View File

@ -8,9 +8,9 @@ from SCons.Script import ARGUMENTS
if not ARGUMENTS.get('CC') and not ARGUMENTS.get("CXX") and platform.machine() != "s390x":
toolchain_exec_root = SCons.Script.Main.GetOption('toolchain-root')
toolchain_root = toolchain_exec_root + "/external/mongo_toolchain/v4"
toolchain_root = toolchain_exec_root + "/external/mongo_toolchain_v4/v4"
local_toolchain_root = '/opt/mongodbtoolchain/v4'
if not toolchain_root:
toolchain_root = local_toolchain_root
@ -20,9 +20,10 @@ if not ARGUMENTS.get('CC') and not ARGUMENTS.get("CXX") and platform.machine() !
# Get the default SCons path as a list
default_path = SCons.Defaults.DefaultEnvironment()['ENV']['PATH'].split(os.pathsep)
exec(open('bazel/toolchains/mongo_toolchain_flags.bzl', "rb").read())
exec(open('bazel/toolchains/mongo_toolchain_flags_v4.bzl', "rb").read())
exec(open('bazel/platforms/normalize.bzl', "rb").read())
arch = ARCH_NORMALIZE_MAP[platform.machine()]
# Put the toolchain path first so we prefer all tools from there in subprocs
ENV = {
'PATH' : os.pathsep.join([toolchain_bindir, local_toolchain_bindir] + default_path)
@ -36,7 +37,7 @@ if not ARGUMENTS.get('CC') and not ARGUMENTS.get("CXX") and platform.machine() !
TOOLCHAIN_CCFLAGS.append("-isystem"+flag.format(arch=arch))
else:
TOOLCHAIN_CCFLAGS.append("-isystem"+toolchain_exec_root+"/"+flag.format(arch=arch))
# TODO BUILD-16594
# This is temporary workaround so that gcc can find the LLVM lld from the toolchain
# until we can build this into the toolchain's default search paths
@ -51,34 +52,14 @@ if not ARGUMENTS.get('CC') and not ARGUMENTS.get("CXX") and platform.machine() !
# getting the right toolchain in build log output when the path is
# printed for each compiler invocation.
MONGO_TOOLCHAIN_VERSION = "v4"
CC = os.path.join(toolchain_bindir, 'clang')
CXX = os.path.join(toolchain_bindir, 'clang++')
DWP = os.path.join(local_toolchain_bindir, 'dwp')
READELF = os.path.join(local_toolchain_bindir, 'readelf')
GDB = os.path.join(local_toolchain_bindir, 'gdb')
bazel_toolchain_bin = SCons.Script.Main.GetOption('bazel-toolchain-clang')
if bazel_toolchain_bin:
cxx_realpath = os.path.join(bazel_toolchain_bin, "clang++")
else:
cxx_realpath = CXX
bazel_toolchain_bin = SCons.Script.Main.GetOption('bazel-toolchain-gcc')
if bazel_toolchain_bin:
gcc_realpath = os.path.join(bazel_toolchain_bin, "g++")
else:
gcc_realpath = CXX
try:
AR = subprocess.check_output([gcc_realpath, '-print-prog-name=ar']).decode('utf-8').strip()
AS = subprocess.check_output([gcc_realpath, '-print-prog-name=as']).decode('utf-8').strip()
OBJCOPY = subprocess.check_output([cxx_realpath, '-print-prog-name=llvm-objcopy']).decode('utf-8').strip()
LLVM_SYMBOLIZER = subprocess.check_output([cxx_realpath, '-print-prog-name=llvm-symbolizer']).decode('utf-8').strip()
except subprocess.CalledProcessError as e:
print("Failed while invoking toolchain binary " + cxx_realpath + ": " + str(e.output))
SCons.Script.Exit(-1)
except OSError as e:
print("Failed to invoke toolchain binary " + cxx_realpath + ": " + str(e))
SCons.Script.Exit(-1)
AR = os.path.join(toolchain_bindir, 'ar')
AS = os.path.join(toolchain_bindir, 'as')
OBJCOPY = os.path.join(toolchain_bindir, 'llvm-objcopy')
LLVM_SYMBOLIZER = os.path.join(toolchain_bindir, 'llvm-symbolizer')
DWARF_VERSION=4

View File

@ -9,7 +9,7 @@ from SCons.Script import ARGUMENTS
if not ARGUMENTS.get('CC') and not ARGUMENTS.get("CXX"):
toolchain_exec_root = SCons.Script.Main.GetOption('toolchain-root')
toolchain_root = toolchain_exec_root + "/external/mongo_toolchain/v4"
toolchain_root = toolchain_exec_root + "/external/mongo_toolchain_v4/v4"
local_toolchain_root = '/opt/mongodbtoolchain/v4'
if not toolchain_root:
toolchain_root = local_toolchain_root
@ -19,9 +19,10 @@ if not ARGUMENTS.get('CC') and not ARGUMENTS.get("CXX"):
# Get the default SCons path as a list
default_path = SCons.Defaults.DefaultEnvironment()['ENV']['PATH'].split(os.pathsep)
exec(open('bazel/toolchains/mongo_toolchain_flags.bzl', "rb").read())
exec(open('bazel/toolchains/mongo_toolchain_flags_v4.bzl', "rb").read())
exec(open('bazel/platforms/normalize.bzl', "rb").read())
arch = ARCH_NORMALIZE_MAP[platform.machine()]
# Put the toolchain path first so we prefer all tools from there in subprocs
ENV = {
'PATH' : os.pathsep.join([toolchain_bindir, local_toolchain_bindir] + default_path)
@ -35,7 +36,7 @@ if not ARGUMENTS.get('CC') and not ARGUMENTS.get("CXX"):
TOOLCHAIN_CCFLAGS.append("-isystem"+flag.format(arch=arch))
else:
TOOLCHAIN_CCFLAGS.append("-isystem"+toolchain_exec_root+"/"+flag.format(arch=arch))
# TODO BUILD-16594
# This is temporary workaround so that gcc can find the LLVM lld from the toolchain
# until we can build this into the toolchain's default search paths
@ -50,32 +51,13 @@ if not ARGUMENTS.get('CC') and not ARGUMENTS.get("CXX"):
# getting the right toolchain in build log output when the path is
# printed for each compiler invocation.
MONGO_TOOLCHAIN_VERSION = "v4"
CC = os.path.join(toolchain_bindir, 'gcc')
CXX = os.path.join(toolchain_bindir, 'g++')
AR = os.path.join(toolchain_bindir, 'ar')
AS = os.path.join(toolchain_bindir, 'as')
OBJCOPY = os.path.join(toolchain_bindir, 'objcopy')
DWP = os.path.join(local_toolchain_bindir, 'dwp')
READELF = os.path.join(local_toolchain_bindir, 'readelf')
GDB = os.path.join(local_toolchain_bindir, 'gdb')
bazel_toolchain_bin = SCons.Script.Main.GetOption('bazel-toolchain-gcc')
if bazel_toolchain_bin:
cxx_realpath = os.path.join(bazel_toolchain_bin, "g++")
else:
cxx_realpath = CXX
try:
AR = subprocess.check_output([cxx_realpath, '-print-prog-name=ar']).decode('utf-8').strip()
AS = subprocess.check_output([cxx_realpath, '-print-prog-name=as']).decode('utf-8').strip()
bazel_toolchain_bin = SCons.Script.Main.GetOption('bazel-toolchain-clang')
if bazel_toolchain_bin:
OBJCOPY = os.path.join(bazel_toolchain_bin, "llvm-objcopy")
else:
OBJCOPY = subprocess.check_output([clang_realpath, '-print-prog-name=llvm-objcopy']).decode('utf-8').strip()
except subprocess.CalledProcessError as e:
print('Failed while invoking toolchain binary ' + cxx_realpath + ': ' + str(e.output))
SCons.Script.Exit(-1)
except OSError as e:
print('Failed to invoke toolchain binary ' + cxx_realpath + ': ' + str(e))
SCons.Script.Exit(-1)
DWARF_VERSION=5

View File

@ -0,0 +1,65 @@
# Configures the build to use the clang toolchain in /opt/mongodbtoolchain/v5
import os
import subprocess
import platform
import SCons.Defaults
from SCons.Script import ARGUMENTS
if not ARGUMENTS.get('CC') and not ARGUMENTS.get("CXX") and platform.machine() != "s390x":
toolchain_exec_root = SCons.Script.Main.GetOption('toolchain-root')
toolchain_root = toolchain_exec_root + "/external/mongo_toolchain_v5/v5"
local_toolchain_root = '/opt/mongodbtoolchain/v5'
if not toolchain_root:
toolchain_root = local_toolchain_root
toolchain_bindir = os.path.join(toolchain_root, 'bin')
local_toolchain_bindir = os.path.join(local_toolchain_root, 'bin')
# Get the default SCons path as a list
default_path = SCons.Defaults.DefaultEnvironment()['ENV']['PATH'].split(os.pathsep)
exec(open('bazel/toolchains/mongo_toolchain_flags_v5.bzl', "rb").read())
exec(open('bazel/platforms/normalize.bzl', "rb").read())
arch = ARCH_NORMALIZE_MAP[platform.machine()]
# Put the toolchain path first so we prefer all tools from there in subprocs
ENV = {
'PATH' : os.pathsep.join([toolchain_bindir, local_toolchain_bindir] + default_path)
}
TOOLCHAIN_LINKFLAGS=[]
for flag in COMMON_LINK_FLAGS:
TOOLCHAIN_LINKFLAGS.append("-L"+toolchain_exec_root+"/"+flag.format(arch=arch))
TOOLCHAIN_CCFLAGS = ["-nostdinc++"]
for flag in CLANG_INCLUDE_DIRS+COMMON_INCLUDE_DIRECTORIES+COMMON_BUILTIN_INCLUDE_DIRECTORIES:
if flag.startswith("/"):
TOOLCHAIN_CCFLAGS.append("-isystem"+flag.format(arch=arch))
else:
TOOLCHAIN_CCFLAGS.append("-isystem"+toolchain_exec_root+"/"+flag.format(arch=arch))
# TODO BUILD-16594
# This is temporary workaround so that gcc can find the LLVM lld from the toolchain
# until we can build this into the toolchain's default search paths
LINKFLAGS_COMPILER_EXEC_PREFIX = [f'{toolchain_bindir}']
for flag in COMMON_BINDIRS:
LINKFLAGS_COMPILER_EXEC_PREFIX.append(toolchain_exec_root+"/"+flag.format(arch=arch))
# Set any Variables for Tools from the toolchain here. Technically, we
# shouldn't need the full paths since SCons will find the toolchain
# ones first, but we don't want to accidentally get the system version
# if, say, the toolchain is missing. Also, it is clearer that we are
# getting the right toolchain in build log output when the path is
# printed for each compiler invocation.
MONGO_TOOLCHAIN_VERSION = "v5"
CC = os.path.join(toolchain_bindir, 'clang')
CXX = os.path.join(toolchain_bindir, 'clang++')
DWP = os.path.join(local_toolchain_bindir, 'dwp')
READELF = os.path.join(local_toolchain_bindir, 'readelf')
GDB = os.path.join(local_toolchain_bindir, 'gdb')
GDB = os.path.join(local_toolchain_bindir, 'gdb')
AR = os.path.join(toolchain_bindir, 'ar')
AS = os.path.join(toolchain_bindir, 'as')
OBJCOPY = os.path.join(toolchain_bindir, 'llvm-objcopy')
LLVM_SYMBOLIZER = os.path.join(toolchain_bindir, 'llvm-symbolizer')
DWARF_VERSION=4

View File

@ -0,0 +1,63 @@
# Configures the build to use the GCC toolchain in /opt/mongodbtoolchain/v5
import os
import subprocess
import platform
import SCons.Defaults
from SCons.Script import ARGUMENTS
if not ARGUMENTS.get('CC') and not ARGUMENTS.get("CXX"):
toolchain_exec_root = SCons.Script.Main.GetOption('toolchain-root')
toolchain_root = toolchain_exec_root + "/external/mongo_toolchain_v5/v5"
local_toolchain_root = '/opt/mongodbtoolchain/v5'
if not toolchain_root:
toolchain_root = local_toolchain_root
toolchain_bindir = os.path.join(toolchain_root, 'bin')
local_toolchain_bindir = os.path.join(local_toolchain_root, 'bin')
# Get the default SCons path as a list
default_path = SCons.Defaults.DefaultEnvironment()['ENV']['PATH'].split(os.pathsep)
exec(open('bazel/toolchains/mongo_toolchain_flags_v5.bzl', "rb").read())
exec(open('bazel/platforms/normalize.bzl', "rb").read())
arch = ARCH_NORMALIZE_MAP[platform.machine()]
# Put the toolchain path first so we prefer all tools from there in subprocs
ENV = {
'PATH' : os.pathsep.join([toolchain_bindir, local_toolchain_bindir] + default_path)
}
TOOLCHAIN_LINKFLAGS=[]
for flag in COMMON_LINK_FLAGS:
TOOLCHAIN_LINKFLAGS.append("-L"+toolchain_exec_root+"/"+flag.format(arch=arch))
TOOLCHAIN_CCFLAGS = ["-nostdinc++"]
for flag in GCC_INCLUDE_DIRS+COMMON_INCLUDE_DIRECTORIES+COMMON_BUILTIN_INCLUDE_DIRECTORIES:
if flag.startswith("/"):
TOOLCHAIN_CCFLAGS.append("-isystem"+flag.format(arch=arch))
else:
TOOLCHAIN_CCFLAGS.append("-isystem"+toolchain_exec_root+"/"+flag.format(arch=arch))
# TODO BUILD-16594
# This is temporary workaround so that gcc can find the LLVM lld from the toolchain
# until we can build this into the toolchain's default search paths
LINKFLAGS_COMPILER_EXEC_PREFIX = [f'{toolchain_bindir}']
for flag in COMMON_BINDIRS:
LINKFLAGS_COMPILER_EXEC_PREFIX.append(toolchain_exec_root+"/"+flag.format(arch=arch))
# Set any Variables for Tools from the toolchain here. Technically, we
# shouldn't need the full paths since SCons will find the toolchain
# ones first, but we don't want to accidentally get the system version
# if, say, the toolchain is missing. Also, it is clearer that we are
# getting the right toolchain in build log output when the path is
# printed for each compiler invocation.
MONGO_TOOLCHAIN_VERSION = "v5"
CC = os.path.join(toolchain_bindir, 'gcc')
CXX = os.path.join(toolchain_bindir, 'g++')
AR = os.path.join(toolchain_bindir, 'ar')
AS = os.path.join(toolchain_bindir, 'as')
OBJCOPY = os.path.join(toolchain_bindir, 'objcopy')
DWP = os.path.join(local_toolchain_bindir, 'dwp')
READELF = os.path.join(local_toolchain_bindir, 'readelf')
GDB = os.path.join(local_toolchain_bindir, 'gdb')
DWARF_VERSION=5

View File

@ -1089,7 +1089,11 @@ def add_libdeps_time(env, delate_time):
count_of_libdeps_links += 1
def prefetch_toolchain(env):
def bazel_execroot(env):
return f'bazel-{os.path.basename(env.Dir("#").abspath)}'
def prefetch_toolchain(env, version):
setup_bazel_env_vars()
setup_max_retry_attempts()
bazel_bin_dir = (
@ -1101,13 +1105,21 @@ def prefetch_toolchain(env):
os.makedirs(bazel_bin_dir)
Globals.bazel_executable = install_bazel(bazel_bin_dir)
if platform.system() == "Linux" and not ARGUMENTS.get("CC") and not ARGUMENTS.get("CXX"):
exec_root = f'bazel-{os.path.basename(env.Dir("#").abspath)}'
if exec_root and not os.path.exists(f"{exec_root}/external/mongo_toolchain"):
exec_root = bazel_execroot(env)
if exec_root and not os.path.exists(f"{exec_root}/external/mongo_toolchain_{version}"):
print("Prefetch the mongo toolchain...")
try:
retry_call(
subprocess.run,
[[Globals.bazel_executable, "build", "@mongo_toolchain", "--config=local"]],
[
[
Globals.bazel_executable,
"build",
"mongo_toolchain",
"--config=local",
f"--//bazel/config:mongo_toolchain_version={version}",
]
],
fkwargs={
"env": {**os.environ.copy(), **Globals.bazel_env_variables},
"check": True,
@ -1116,9 +1128,12 @@ def prefetch_toolchain(env):
exceptions=(subprocess.CalledProcessError,),
)
except subprocess.CalledProcessError as ex:
print("ERROR: Bazel fetch failed!")
print(f"ERROR: Bazel fetch of {version} toolchain failed!")
print(ex)
print("Please ask about this in #ask-devprod-build slack channel.")
if version == "v4":
print("Please ask about this in #ask-devprod-build slack channel.")
else:
print(f"The {version} toolchain may not be supported on this platform.")
sys.exit(1)
return exec_root
@ -1130,6 +1145,7 @@ def exists(env: SCons.Environment.Environment) -> bool:
write_workstation_bazelrc()
env.AddMethod(prefetch_toolchain, "PrefetchToolchain")
env.AddMethod(bazel_execroot, "BazelExecroot")
env.AddMethod(load_bazel_builders, "LoadBazelBuilders")
return True
@ -1362,6 +1378,9 @@ def generate(env: SCons.Environment.Environment) -> None:
f"--host_platform=//bazel/platforms:{distro_or_os}_{normalized_arch}",
]
if tc := env.get("MONGO_TOOLCHAIN_VERSION"):
bazel_internal_flags += [f"--//bazel/config:mongo_toolchain_version={tc}"]
if "MONGO_ENTERPRISE_VERSION" in env:
enterprise_features = env.GetOption("enterprise_features")
if enterprise_features == "*":

View File

@ -61,7 +61,6 @@ cc_library(
],
copts = [
"-Isrc/mongo/tools/mongo_tidy_checks/", # Ensures that `#include "Mongo..."` calls continue to work in Bazel AND in SCons
"-Iexternal/mongo_toolchain/stow/llvm-v4/include", # Ensures that `#include "clang-tidy/*` directives work.
"-DNDEBUG",
"-Wall",
"-fdiagnostics-color",
@ -92,6 +91,7 @@ cc_library(
"-Woverloaded-virtual",
"-Wwrite-strings",
"-Wsuggest-override",
"-Iexternal/mongo_toolchain_v4/stow/llvm-v4/include/",
],
local_defines = [
"GTEST_HAS_RTTI=0",
@ -107,7 +107,10 @@ cc_library(
"@platforms//os:windows": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
deps = [],
deps = select({
"@//bazel/platforms:use_mongo_toolchain": ["@mongo_toolchain_v4//:llvm_headers"],
"//conditions:default": [],
}),
)
cc_shared_library(
@ -147,7 +150,6 @@ cc_shared_library(
"-Wsuggest-override",
"-Wno-comment",
"-Wl,-z,nodelete",
"-Wl,-rpath-link,external/mongo_toolchain/stow/llvm-v4/lib",
"-Wl,-O3",
"-Wl,--gc-sections",
"-Wl,-rpath,\\$ORIGIN/../lib", # Ensure that the shared library can find its dependencies.