Skip to content

Commit 10cc816

Browse files
authored
Rollup merge of #137170 - ferrocene:pa-target-jemalloc, r=Kobzol
Allow configuring jemalloc per target In Ferrocene we're trying to switch from `./configure` to a predefined `config.toml` file. One of the limitations of doing that is the `rust.jemalloc` configuration option, which we need to conditionally disable based on the target. This PR adds a `target.$tuple.jemalloc` option to override `rust.jemalloc` to make that possible.
2 parents 8d72b7c + a71de77 commit 10cc816

File tree

6 files changed

+24
-4
lines changed

6 files changed

+24
-4
lines changed

config.example.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,8 @@
729729
#remap-debuginfo = false
730730

731731
# Link the compiler and LLVM against `jemalloc` instead of the default libc allocator.
732-
# This option is only tested on Linux and OSX.
732+
# This option is only tested on Linux and OSX. It can also be configured per-target in the
733+
# [target.<tuple>] section.
733734
#jemalloc = false
734735

735736
# Run tests in various test suites with the "nll compare mode" in addition to
@@ -927,6 +928,10 @@
927928
# order to run `x check`.
928929
#optimized-compiler-builtins = build.optimized-compiler-builtins (bool)
929930

931+
# Link the compiler and LLVM against `jemalloc` instead of the default libc allocator.
932+
# This overrides the global `rust.jemalloc` option. See that option for more info.
933+
#jemalloc = rust.jemalloc (bool)
934+
930935
# =============================================================================
931936
# Distribution options
932937
#

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ pub fn rustc_cargo_env(
13411341

13421342
// Build jemalloc on AArch64 with support for page sizes up to 64K
13431343
// See: https://github.com/rust-lang/rust/pull/135081
1344-
if builder.config.jemalloc
1344+
if builder.config.jemalloc(target)
13451345
&& target.starts_with("aarch64")
13461346
&& env::var_os("JEMALLOC_SYS_WITH_LG_PAGE").is_none()
13471347
{

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ impl Step for Rustdoc {
654654
// to build rustdoc.
655655
//
656656
let mut features = Vec::new();
657-
if builder.config.jemalloc {
657+
if builder.config.jemalloc(target) {
658658
features.push("jemalloc".to_string());
659659
}
660660

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

+10
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ pub struct Config {
325325
pub hosts: Vec<TargetSelection>,
326326
pub targets: Vec<TargetSelection>,
327327
pub local_rebuild: bool,
328+
#[cfg(not(test))]
329+
jemalloc: bool,
330+
#[cfg(test)]
328331
pub jemalloc: bool,
329332
pub control_flow_guard: bool,
330333
pub ehcont_guard: bool,
@@ -643,6 +646,7 @@ pub struct Target {
643646
pub no_std: bool,
644647
pub codegen_backends: Option<Vec<String>>,
645648
pub optimized_compiler_builtins: Option<bool>,
649+
pub jemalloc: Option<bool>,
646650
}
647651

648652
impl Target {
@@ -1234,6 +1238,7 @@ define_config! {
12341238
codegen_backends: Option<Vec<String>> = "codegen-backends",
12351239
runner: Option<String> = "runner",
12361240
optimized_compiler_builtins: Option<bool> = "optimized-compiler-builtins",
1241+
jemalloc: Option<bool> = "jemalloc",
12371242
}
12381243
}
12391244

@@ -2161,6 +2166,7 @@ impl Config {
21612166
target.profiler = cfg.profiler;
21622167
target.rpath = cfg.rpath;
21632168
target.optimized_compiler_builtins = cfg.optimized_compiler_builtins;
2169+
target.jemalloc = cfg.jemalloc;
21642170

21652171
if let Some(ref backends) = cfg.codegen_backends {
21662172
let available_backends = ["llvm", "cranelift", "gcc"];
@@ -2726,6 +2732,10 @@ impl Config {
27262732
.unwrap_or(&self.rust_codegen_backends)
27272733
}
27282734

2735+
pub fn jemalloc(&self, target: TargetSelection) -> bool {
2736+
self.target_config.get(&target).and_then(|cfg| cfg.jemalloc).unwrap_or(self.jemalloc)
2737+
}
2738+
27292739
pub fn default_codegen_backend(&self, target: TargetSelection) -> Option<String> {
27302740
self.codegen_backends(target).first().cloned()
27312741
}

src/bootstrap/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ impl Build {
688688
crates.is_empty() || possible_features_by_crates.contains(feature)
689689
};
690690
let mut features = vec![];
691-
if self.config.jemalloc && check("jemalloc") {
691+
if self.config.jemalloc(target) && check("jemalloc") {
692692
features.push("jemalloc");
693693
}
694694
if (self.config.llvm_enabled(target) || kind == Kind::Check) && check("llvm") {

src/bootstrap/src/utils/change_tracker.rs

+5
Original file line numberDiff line numberDiff line change
@@ -350,4 +350,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
350350
severity: ChangeSeverity::Info,
351351
summary: "The llvm.ccache option has moved to build.ccache. llvm.ccache is now deprecated.",
352352
},
353+
ChangeInfo {
354+
change_id: 137170,
355+
severity: ChangeSeverity::Info,
356+
summary: "It is now possible to configure `jemalloc` for each target",
357+
},
353358
];

0 commit comments

Comments
 (0)