allow configuring jemalloc per target

This commit is contained in:
Pietro Albini 2025-02-17 11:29:40 +01:00
parent 905b1bf1cc
commit a71de77ae9
No known key found for this signature in database
GPG Key ID: CD76B35F7734769E
6 changed files with 24 additions and 4 deletions

View File

@ -729,7 +729,8 @@
#remap-debuginfo = false
# Link the compiler and LLVM against `jemalloc` instead of the default libc allocator.
# This option is only tested on Linux and OSX.
# This option is only tested on Linux and OSX. It can also be configured per-target in the
# [target.<tuple>] section.
#jemalloc = false
# Run tests in various test suites with the "nll compare mode" in addition to
@ -927,6 +928,10 @@
# order to run `x check`.
#optimized-compiler-builtins = build.optimized-compiler-builtins (bool)
# Link the compiler and LLVM against `jemalloc` instead of the default libc allocator.
# This overrides the global `rust.jemalloc` option. See that option for more info.
#jemalloc = rust.jemalloc (bool)
# =============================================================================
# Distribution options
#

View File

@ -1260,7 +1260,7 @@ pub fn rustc_cargo_env(
// Build jemalloc on AArch64 with support for page sizes up to 64K
// See: https://github.com/rust-lang/rust/pull/135081
if builder.config.jemalloc
if builder.config.jemalloc(target)
&& target.starts_with("aarch64")
&& env::var_os("JEMALLOC_SYS_WITH_LG_PAGE").is_none()
{

View File

@ -643,7 +643,7 @@ impl Step for Rustdoc {
// to build rustdoc.
//
let mut features = Vec::new();
if builder.config.jemalloc {
if builder.config.jemalloc(target) {
features.push("jemalloc".to_string());
}

View File

@ -325,6 +325,9 @@ pub struct Config {
pub hosts: Vec<TargetSelection>,
pub targets: Vec<TargetSelection>,
pub local_rebuild: bool,
#[cfg(not(test))]
jemalloc: bool,
#[cfg(test)]
pub jemalloc: bool,
pub control_flow_guard: bool,
pub ehcont_guard: bool,
@ -643,6 +646,7 @@ pub struct Target {
pub no_std: bool,
pub codegen_backends: Option<Vec<String>>,
pub optimized_compiler_builtins: Option<bool>,
pub jemalloc: Option<bool>,
}
impl Target {
@ -1234,6 +1238,7 @@ define_config! {
codegen_backends: Option<Vec<String>> = "codegen-backends",
runner: Option<String> = "runner",
optimized_compiler_builtins: Option<bool> = "optimized-compiler-builtins",
jemalloc: Option<bool> = "jemalloc",
}
}
@ -2161,6 +2166,7 @@ impl Config {
target.profiler = cfg.profiler;
target.rpath = cfg.rpath;
target.optimized_compiler_builtins = cfg.optimized_compiler_builtins;
target.jemalloc = cfg.jemalloc;
if let Some(ref backends) = cfg.codegen_backends {
let available_backends = ["llvm", "cranelift", "gcc"];
@ -2726,6 +2732,10 @@ impl Config {
.unwrap_or(&self.rust_codegen_backends)
}
pub fn jemalloc(&self, target: TargetSelection) -> bool {
self.target_config.get(&target).and_then(|cfg| cfg.jemalloc).unwrap_or(self.jemalloc)
}
pub fn default_codegen_backend(&self, target: TargetSelection) -> Option<String> {
self.codegen_backends(target).first().cloned()
}

View File

@ -677,7 +677,7 @@ impl Build {
crates.is_empty() || possible_features_by_crates.contains(feature)
};
let mut features = vec![];
if self.config.jemalloc && check("jemalloc") {
if self.config.jemalloc(target) && check("jemalloc") {
features.push("jemalloc");
}
if (self.config.llvm_enabled(target) || kind == Kind::Check) && check("llvm") {

View File

@ -350,4 +350,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
severity: ChangeSeverity::Info,
summary: "The llvm.ccache option has moved to build.ccache. llvm.ccache is now deprecated.",
},
ChangeInfo {
change_id: 137170,
severity: ChangeSeverity::Info,
summary: "It is now possible to configure `jemalloc` for each target",
},
];