Skip to content

Commit 93e80cc

Browse files
committed
Replace jemalloc bootstrap options with override-allocator
1 parent 57f772f commit 93e80cc

21 files changed

Lines changed: 92 additions & 50 deletions

File tree

INSTALL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ See [the rustc-dev-guide for more info][sysllvm].
9696
--set llvm.libzstd=true \
9797
--set llvm.ninja=false \
9898
--set rust.debug-assertions=false \
99-
--set rust.jemalloc \
99+
--set rust.override-allocator=jemalloc \
100100
--set rust.bootstrap-override-lld=true \
101101
--set rust.lto=thin \
102102
--set rust.codegen-units=1

bootstrap.example.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -845,10 +845,11 @@
845845
# Useful for reproducible builds. Generally only set for releases
846846
#rust.remap-debuginfo = false
847847

848-
# Link the compiler and LLVM against `jemalloc` instead of the default libc allocator.
848+
# Link the compiler and LLVM against the specified allocator instead of the default libc allocator.
849849
# This option is only tested on Linux and OSX. It can also be configured per-target in the
850850
# [target.<tuple>] section.
851-
#rust.jemalloc = false
851+
# Possible options: "jemalloc"
852+
#rust.override-allocator = "jemalloc"
852853

853854
# Run tests in various test suites with the "nll compare mode" in addition to
854855
# running the tests in normal mode. Largely only used on CI and during local
@@ -1120,9 +1121,9 @@
11201121
# order to run `x check`.
11211122
#optimized-compiler-builtins = build.optimized-compiler-builtins (bool or path)
11221123

1123-
# Link the compiler and LLVM against `jemalloc` instead of the default libc allocator.
1124-
# This overrides the global `rust.jemalloc` option. See that option for more info.
1125-
#jemalloc = rust.jemalloc (bool)
1124+
# Link the compiler and LLVM against the specified allocator instead of the default libc allocator.
1125+
# This overrides the global `rust.override-allocator` option. See that option for more info.
1126+
#override-allocator = rust.override-allocator (string)
11261127

11271128
# The linker configuration that will *override* the default linker used for Linux
11281129
# targets in the built compiler.

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::core::builder::{
2828
};
2929
use crate::core::config::toml::target::DefaultLinuxLinkerOverride;
3030
use crate::core::config::{
31-
CompilerBuiltins, DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection,
31+
CompilerBuiltins, DebuginfoLevel, LlvmLibunwind, OverrideAllocator, RustcLto, TargetSelection,
3232
};
3333
use crate::utils::build_stamp;
3434
use crate::utils::build_stamp::BuildStamp;
@@ -1411,7 +1411,9 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS
14111411
}
14121412

14131413
// See also the "JEMALLOC_SYS_WITH_LG_PAGE" setting in the tool build step.
1414-
if builder.config.jemalloc(target) && env::var_os("JEMALLOC_SYS_WITH_LG_PAGE").is_none() {
1414+
if let Some(OverrideAllocator::Jemalloc) = builder.config.override_allocator(target)
1415+
&& env::var_os("JEMALLOC_SYS_WITH_LG_PAGE").is_none()
1416+
{
14151417
// Build jemalloc on AArch64 with support for page sizes up to 64K
14161418
// See: https://github.com/rust-lang/rust/pull/135081
14171419
if target.starts_with("aarch64") {

src/bootstrap/src/core/build_steps/tool.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::core::builder;
2020
use crate::core::builder::{
2121
Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step, StepMetadata, cargo_profile_var,
2222
};
23-
use crate::core::config::{DebuginfoLevel, RustcLto, TargetSelection};
23+
use crate::core::config::{DebuginfoLevel, OverrideAllocator, RustcLto, TargetSelection};
2424
use crate::utils::exec::{BootstrapCommand, command};
2525
use crate::utils::helpers::{add_dylib_path, exe, t};
2626
use crate::{Compiler, FileType, Kind, Mode};
@@ -229,7 +229,9 @@ pub fn prepare_tool_cargo(
229229
cargo.env("LZMA_API_STATIC", "1");
230230

231231
// See also the "JEMALLOC_SYS_WITH_LG_PAGE" setting in the compile build step.
232-
if builder.config.jemalloc(target) && env::var_os("JEMALLOC_SYS_WITH_LG_PAGE").is_none() {
232+
if let Some(OverrideAllocator::Jemalloc) = builder.config.override_allocator(target)
233+
&& env::var_os("JEMALLOC_SYS_WITH_LG_PAGE").is_none()
234+
{
233235
// Build jemalloc on AArch64 with support for page sizes up to 64K
234236
// See: https://github.com/rust-lang/rust/pull/135081
235237
if target.starts_with("aarch64") {
@@ -752,8 +754,8 @@ impl Step for Rustdoc {
752754
// to build rustdoc.
753755
//
754756
let mut extra_features = Vec::new();
755-
if builder.config.jemalloc(target) {
756-
extra_features.push("jemalloc".to_string());
757+
if let Some(allocator) = builder.config.override_allocator(target) {
758+
extra_features.push(allocator.feature_name().to_string());
757759
}
758760

759761
let compilers = RustcPrivateCompilers::from_target_compiler(builder, target_compiler);
@@ -1576,8 +1578,8 @@ tool_rustc_extended!(Clippy {
15761578
stable: true,
15771579
add_bins_to_sysroot: ["clippy-driver"],
15781580
add_features: |builder, target, features| {
1579-
if builder.config.jemalloc(target) {
1580-
features.push("jemalloc".to_string());
1581+
if let Some(allocator) = builder.config.override_allocator(target) {
1582+
features.push(allocator.feature_name().to_string());
15811583
}
15821584
}
15831585
});
@@ -1587,8 +1589,8 @@ tool_rustc_extended!(Miri {
15871589
stable: false,
15881590
add_bins_to_sysroot: ["miri"],
15891591
add_features: |builder, target, features| {
1590-
if builder.config.jemalloc(target) {
1591-
features.push("jemalloc".to_string());
1592+
if let Some(allocator) = builder.config.override_allocator(target) {
1593+
features.push(allocator.feature_name().to_string());
15921594
}
15931595
},
15941596
// Always compile also tests when building miri. Otherwise feature unification can cause rebuilds between building and testing miri.

src/bootstrap/src/core/config/config.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ use crate::core::config::toml::target::{
4848
DefaultLinuxLinkerOverride, Target, TomlTarget, default_linux_linker_overrides,
4949
};
5050
use crate::core::config::{
51-
CompilerBuiltins, DebuginfoLevel, DryRun, GccCiMode, LlvmLibunwind, Merge, ReplaceOpt,
52-
RustcLto, SplitDebuginfo, StringOrBool, threads_from_config,
51+
CompilerBuiltins, DebuginfoLevel, DryRun, GccCiMode, LlvmLibunwind, Merge, OverrideAllocator,
52+
ReplaceOpt, RustcLto, SplitDebuginfo, StringOrBool, threads_from_config,
5353
};
5454
use crate::core::download::{
5555
DownloadContext, download_beta_toolchain, is_download_ci_available, maybe_download_rustfmt,
@@ -242,7 +242,7 @@ pub struct Config {
242242
pub hosts: Vec<TargetSelection>,
243243
pub targets: Vec<TargetSelection>,
244244
pub local_rebuild: bool,
245-
pub jemalloc: bool,
245+
pub override_allocator: Option<OverrideAllocator>,
246246
pub control_flow_guard: bool,
247247
pub ehcont_guard: bool,
248248

@@ -570,7 +570,7 @@ impl Config {
570570
thin_lto_import_instr_limit: rust_thin_lto_import_instr_limit,
571571
parallel_frontend_threads: rust_parallel_frontend_threads,
572572
remap_debuginfo: rust_remap_debuginfo,
573-
jemalloc: rust_jemalloc,
573+
override_allocator: rust_override_allocator,
574574
test_compare_mode: rust_test_compare_mode,
575575
llvm_libunwind: rust_llvm_libunwind,
576576
control_flow_guard: rust_control_flow_guard,
@@ -900,7 +900,7 @@ impl Config {
900900
codegen_backends: target_codegen_backends,
901901
runner: target_runner,
902902
optimized_compiler_builtins: target_optimized_compiler_builtins,
903-
jemalloc: target_jemalloc,
903+
override_allocator: target_override_allocator,
904904
} = cfg;
905905

906906
let mut target = Target::from_triple(&triple);
@@ -976,7 +976,7 @@ impl Config {
976976
target.rpath = target_rpath;
977977
target.rustflags = target_rustflags.unwrap_or_default();
978978
target.optimized_compiler_builtins = target_optimized_compiler_builtins;
979-
target.jemalloc = target_jemalloc;
979+
target.override_allocator = target_override_allocator;
980980
if let Some(backends) = target_codegen_backends {
981981
target.codegen_backends =
982982
Some(parse_codegen_backends(backends, &format!("target.{triple}")))
@@ -1371,7 +1371,6 @@ impl Config {
13711371
initial_rustdoc,
13721372
initial_rustfmt,
13731373
initial_sysroot,
1374-
jemalloc: rust_jemalloc.unwrap_or(false),
13751374
jobs: Some(threads_from_config(flags_jobs.or(build_jobs).unwrap_or(0))),
13761375
json_output: flags_json_output,
13771376
keep_stage: flags_keep_stage,
@@ -1433,6 +1432,7 @@ impl Config {
14331432
on_fail: flags_on_fail,
14341433
optimized_compiler_builtins,
14351434
out,
1435+
override_allocator: rust_override_allocator,
14361436
patch_binaries_for_nix: build_patch_binaries_for_nix,
14371437
path_modification_cache,
14381438
paths: flags_paths,
@@ -1864,8 +1864,11 @@ impl Config {
18641864
self.enabled_codegen_backends(target).first().unwrap()
18651865
}
18661866

1867-
pub fn jemalloc(&self, target: TargetSelection) -> bool {
1868-
self.target_config.get(&target).and_then(|cfg| cfg.jemalloc).unwrap_or(self.jemalloc)
1867+
pub fn override_allocator(&self, target: TargetSelection) -> Option<OverrideAllocator> {
1868+
self.target_config
1869+
.get(&target)
1870+
.and_then(|cfg| cfg.override_allocator)
1871+
.or(self.override_allocator)
18691872
}
18701873

18711874
pub fn rpath_enabled(&self, target: TargetSelection) -> bool {

src/bootstrap/src/core/config/mod.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,32 @@ impl<'de> Deserialize<'de> for CompilerBuiltins {
251251
}
252252
}
253253

254+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
255+
pub enum OverrideAllocator {
256+
Jemalloc,
257+
}
258+
259+
impl OverrideAllocator {
260+
pub fn feature_name(self) -> &'static str {
261+
match self {
262+
OverrideAllocator::Jemalloc => "jemalloc",
263+
}
264+
}
265+
}
266+
267+
impl<'de> Deserialize<'de> for OverrideAllocator {
268+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
269+
where
270+
D: Deserializer<'de>,
271+
{
272+
let name = String::deserialize(deserializer)?;
273+
match name.as_str() {
274+
"jemalloc" => Ok(Self::Jemalloc),
275+
other => Err(serde::de::Error::unknown_variant(other, &["jemalloc"])),
276+
}
277+
}
278+
}
279+
254280
#[derive(Copy, Clone, Default, Debug, Eq, PartialEq)]
255281
pub enum DebuginfoLevel {
256282
#[default]

src/bootstrap/src/core/config/toml/rust.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use serde::{Deserialize, Deserializer};
55

66
use crate::core::config::toml::TomlConfig;
7-
use crate::core::config::{DebuginfoLevel, Merge, ReplaceOpt, StringOrBool};
7+
use crate::core::config::{DebuginfoLevel, Merge, OverrideAllocator, ReplaceOpt, StringOrBool};
88
use crate::{BTreeSet, CodegenBackendKind, HashSet, PathBuf, TargetSelection, define_config, exit};
99

1010
define_config! {
@@ -55,7 +55,7 @@ define_config! {
5555
verify_llvm_ir: Option<bool> = "verify-llvm-ir",
5656
thin_lto_import_instr_limit: Option<u32> = "thin-lto-import-instr-limit",
5757
remap_debuginfo: Option<bool> = "remap-debuginfo",
58-
jemalloc: Option<bool> = "jemalloc",
58+
override_allocator: Option<OverrideAllocator> = "override-allocator",
5959
test_compare_mode: Option<bool> = "test-compare-mode",
6060
llvm_libunwind: Option<String> = "llvm-libunwind",
6161
control_flow_guard: Option<bool> = "control-flow-guard",
@@ -325,7 +325,7 @@ pub fn check_incompatible_options_for_ci_rustc(
325325
llvm_bitcode_linker,
326326
stack_protector,
327327
strip,
328-
jemalloc,
328+
override_allocator,
329329
rpath,
330330
channel,
331331
default_linker,
@@ -394,7 +394,7 @@ pub fn check_incompatible_options_for_ci_rustc(
394394
err!(current_rust_config.strip, strip, "rust");
395395
err!(current_rust_config.llvm_tools, llvm_tools, "rust");
396396
err!(current_rust_config.llvm_bitcode_linker, llvm_bitcode_linker, "rust");
397-
err!(current_rust_config.jemalloc, jemalloc, "rust");
397+
err!(current_rust_config.override_allocator, override_allocator, "rust");
398398
err!(current_rust_config.default_linker, default_linker, "rust");
399399
err!(current_rust_config.stack_protector, stack_protector, "rust");
400400
err!(current_rust_config.std_features, std_features, "rust");

src/bootstrap/src/core/config/toml/target.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ use serde::de::Error;
1515
use serde::{Deserialize, Deserializer};
1616

1717
use crate::core::config::{
18-
CompilerBuiltins, LlvmLibunwind, Merge, ReplaceOpt, SplitDebuginfo, StringOrBool,
18+
CompilerBuiltins, LlvmLibunwind, Merge, OverrideAllocator, ReplaceOpt, SplitDebuginfo,
19+
StringOrBool,
1920
};
2021
use crate::{CodegenBackendKind, HashSet, PathBuf, define_config, exit};
2122

@@ -47,7 +48,7 @@ define_config! {
4748
codegen_backends: Option<Vec<String>> = "codegen-backends",
4849
runner: Option<String> = "runner",
4950
optimized_compiler_builtins: Option<CompilerBuiltins> = "optimized-compiler-builtins",
50-
jemalloc: Option<bool> = "jemalloc",
51+
override_allocator: Option<OverrideAllocator> = "override-allocator",
5152
}
5253
}
5354

@@ -81,7 +82,7 @@ pub struct Target {
8182
pub no_std: bool,
8283
pub codegen_backends: Option<Vec<CodegenBackendKind>>,
8384
pub optimized_compiler_builtins: Option<CompilerBuiltins>,
84-
pub jemalloc: Option<bool>,
85+
pub override_allocator: Option<OverrideAllocator>,
8586
}
8687

8788
impl Target {

src/bootstrap/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,8 +867,10 @@ impl Build {
867867
crates.is_empty() || possible_features_by_crates.contains(feature)
868868
};
869869
let mut features = vec![];
870-
if self.config.jemalloc(target) && check("jemalloc") {
871-
features.push("jemalloc");
870+
if let Some(allocator) = self.config.override_allocator(target)
871+
&& check(allocator.feature_name())
872+
{
873+
features.push(allocator.feature_name());
872874
}
873875
if (self.config.llvm_enabled(target) || kind == Kind::Check) && check("llvm") {
874876
features.push("llvm");

src/bootstrap/src/utils/change_tracker.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,4 +626,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
626626
severity: ChangeSeverity::Info,
627627
summary: "New `--verbose-run-make-subprocess-output` flag for `x.py test` (defaults to true). Set `--verbose-run-make-subprocess-output=false` to suppress verbose subprocess output for passing run-make tests when using `--no-capture`.",
628628
},
629+
ChangeInfo {
630+
change_id: 155617,
631+
severity: ChangeSeverity::Warning,
632+
summary: "`jemalloc` options are replaced with `override-allocator` which take allocator names such as `jemalloc`",
633+
},
629634
];

0 commit comments

Comments
 (0)