SERVER-101393 set max link threading for LTO configs (#32818)
GitOrigin-RevId: f7fa80d7df350eb9cd73297b08058b28b5da93b0
This commit is contained in:
parent
c834d83af7
commit
6fada461c3
2
.bazelrc
2
.bazelrc
@ -96,7 +96,7 @@ common --flag_alias=compress_debug_compile=//bazel/config:compress_debug_compile
|
||||
common --flag_alias=include_mongot=//bazel/config:include_mongot
|
||||
# This flag will only work if you pass it on the command line as it is parsed by bazelisk pre-bazel script
|
||||
common --flag_alias=include_autogenerated_targets=//bazel/config:include_autogenerated_targets
|
||||
|
||||
common --flag_alias=bolt=//bazel/config:bolt
|
||||
common --flag_alias=dwarf_version=//bazel/config:dwarf_version
|
||||
common --flag_alias=http_client=//bazel/config:http_client
|
||||
common --flag_alias=developer_dir=//bazel/config:developer_dir
|
||||
|
||||
@ -387,3 +387,7 @@ bazel_skylib_workspace()
|
||||
load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains")
|
||||
|
||||
buildifier_prebuilt_register_toolchains()
|
||||
|
||||
load("//bazel/platforms:local_host_values.bzl", "setup_local_host_values")
|
||||
|
||||
setup_local_host_values(name = "local_host_values")
|
||||
|
||||
@ -2274,6 +2274,18 @@ config_setting(
|
||||
},
|
||||
)
|
||||
|
||||
bool_flag(
|
||||
name = "bolt",
|
||||
build_setting_default = False,
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "bolt_enabled",
|
||||
flag_values = {
|
||||
"//bazel/config:bolt": "True",
|
||||
},
|
||||
)
|
||||
|
||||
bool_flag(
|
||||
name = "scons_query",
|
||||
build_setting_default = False,
|
||||
|
||||
@ -24,6 +24,7 @@ load(
|
||||
"extract_debuginfo_binary",
|
||||
"extract_debuginfo_test",
|
||||
)
|
||||
load("@local_host_values//:local_host_values_set.bzl", "NUM_CPUS")
|
||||
|
||||
# https://learn.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=msvc-170
|
||||
# /MD defines _MT and _DLL and links in MSVCRT.lib into each .obj file
|
||||
@ -2147,7 +2148,11 @@ def _mongo_cc_binary_and_test(
|
||||
"copts": MONGO_GLOBAL_COPTS + package_specific_copts + copts + fincludes_copt,
|
||||
"data": data + SANITIZER_DATA,
|
||||
"tags": tags,
|
||||
"linkopts": MONGO_GLOBAL_LINKFLAGS + package_specific_linkflags + linkopts + rpath_flags,
|
||||
"linkopts": MONGO_GLOBAL_LINKFLAGS + package_specific_linkflags + linkopts + rpath_flags + select({
|
||||
"//bazel/config:thin_lto_enabled": ["-Wl,--threads=" + str(NUM_CPUS)],
|
||||
"//bazel/config:bolt_enabled": ["-Wl,--threads=" + str(NUM_CPUS)],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
"linkstatic": LINKSTATIC_ENABLED,
|
||||
"local_defines": MONGO_GLOBAL_DEFINES + local_defines,
|
||||
"defines": defines,
|
||||
@ -2166,6 +2171,10 @@ def _mongo_cc_binary_and_test(
|
||||
# Debug compression significantly reduces .o, .dwo, and .a sizes
|
||||
"//bazel/config:compress_debug_compile_enabled": {"cpp_link.coefficient": "6.0"},
|
||||
"//conditions:default": {"cpp_link.coefficient": "2.0"},
|
||||
}) | select({
|
||||
"//bazel/config:thin_lto_enabled": {"cpp_link.cpus": str(NUM_CPUS)},
|
||||
"//bazel/config:bolt_enabled": {"cpp_link.cpus": str(NUM_CPUS)},
|
||||
"//conditions:default": {},
|
||||
}),
|
||||
"env": env | SANITIZER_ENV,
|
||||
} | kwargs
|
||||
|
||||
38
bazel/platforms/local_host_values.bzl
Normal file
38
bazel/platforms/local_host_values.bzl
Normal file
@ -0,0 +1,38 @@
|
||||
def _local_host_values(ctx):
|
||||
if "win" in ctx.os.name:
|
||||
result = ctx.execute([
|
||||
ctx.path(ctx.attr.python_interpreter_target_win),
|
||||
"-c",
|
||||
"import os; print(os.cpu_count())",
|
||||
])
|
||||
else:
|
||||
result = ctx.execute([
|
||||
ctx.path(ctx.attr.python_interpreter_target_default),
|
||||
"-c",
|
||||
"import os; print(os.cpu_count())",
|
||||
])
|
||||
|
||||
ctx.file(
|
||||
"BUILD.bazel",
|
||||
"",
|
||||
)
|
||||
ctx.file(
|
||||
"local_host_values_set.bzl",
|
||||
"""
|
||||
NUM_CPUS = %s
|
||||
""" % (result.stdout),
|
||||
)
|
||||
|
||||
setup_local_host_values = repository_rule(
|
||||
implementation = _local_host_values,
|
||||
attrs = {
|
||||
"python_interpreter_target_default": attr.label(
|
||||
default = "@py_host//:dist/bin/python3",
|
||||
doc = "The target of the Python interpreter used during repository setup, if not windows",
|
||||
),
|
||||
"python_interpreter_target_win": attr.label(
|
||||
default = "@py_host//:dist/python.exe",
|
||||
doc = "The target of the Python interpreter used during repository setup for windows platforms",
|
||||
),
|
||||
},
|
||||
)
|
||||
Loading…
Reference in New Issue
Block a user