Skip to content

Allow configuring jemalloc per target #137170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
#
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
10 changes: 10 additions & 0 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
}
}

Expand Down Expand Up @@ -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"];
Expand Down Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/src/utils/change_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
];
Loading