Skip to content
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
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ See [the rustc-dev-guide for more info][sysllvm].
--set llvm.libzstd=true \
--set llvm.ninja=false \
--set rust.debug-assertions=false \
--set rust.jemalloc \
--set rust.override-allocator=jemalloc \
--set rust.bootstrap-override-lld=true \
--set rust.lto=thin \
--set rust.codegen-units=1
Expand Down
15 changes: 12 additions & 3 deletions bootstrap.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -853,9 +853,15 @@
# Useful for reproducible builds. Generally only set for releases
#rust.remap-debuginfo = false

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

# Deprecated alias for `rust.override-allocator`. Setting this to `true` is
# equivalent to `rust.override-allocator = "jemalloc"`. If both are set, they
# must agree.
#rust.jemalloc = false

# Run tests in various test suites with the "nll compare mode" in addition to
Expand Down Expand Up @@ -1159,8 +1165,11 @@
# order to run `x check`.
#optimized-compiler-builtins = build.optimized-compiler-builtins (bool or path)

# 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.
# Link the compiler and LLVM against the specified allocator instead of the default libc allocator.
# This overrides the global `rust.override-allocator` option. See that option for more info.
#override-allocator = rust.override-allocator (string)

# Deprecated alias for `override-allocator`. See `rust.jemalloc` for more info.
#jemalloc = rust.jemalloc (bool)

# The linker configuration that will *override* the default linker used for Linux
Expand Down
6 changes: 4 additions & 2 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::core::builder::{
};
use crate::core::config::toml::target::DefaultLinuxLinkerOverride;
use crate::core::config::{
CompilerBuiltins, DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection,
CompilerBuiltins, DebuginfoLevel, LlvmLibunwind, OverrideAllocator, RustcLto, TargetSelection,
};
use crate::utils::build_stamp;
use crate::utils::build_stamp::BuildStamp;
Expand Down Expand Up @@ -1388,7 +1388,9 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS
}

// See also the "JEMALLOC_SYS_WITH_LG_PAGE" setting in the tool build step.
if builder.config.jemalloc(target) && env::var_os("JEMALLOC_SYS_WITH_LG_PAGE").is_none() {
if let Some(OverrideAllocator::Jemalloc) = builder.config.override_allocator(target)
&& env::var_os("JEMALLOC_SYS_WITH_LG_PAGE").is_none()
{
// Build jemalloc on AArch64 with support for page sizes up to 64K
// See: https://github.com/rust-lang/rust/pull/135081
if target.starts_with("aarch64") {
Expand Down
18 changes: 10 additions & 8 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::core::builder::{
Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step, StepMetadata, apply_pgo,
cargo_profile_var,
};
use crate::core::config::{DebuginfoLevel, RustcLto, TargetSelection};
use crate::core::config::{DebuginfoLevel, OverrideAllocator, RustcLto, TargetSelection};
use crate::utils::exec::{BootstrapCommand, command};
use crate::utils::helpers::{add_dylib_path, exe, t};
use crate::{Compiler, FileType, Kind, Mode};
Expand Down Expand Up @@ -240,7 +240,9 @@ pub fn prepare_tool_cargo(
cargo.env("LZMA_API_STATIC", "1");

// See also the "JEMALLOC_SYS_WITH_LG_PAGE" setting in the compile build step.
if builder.config.jemalloc(target) && env::var_os("JEMALLOC_SYS_WITH_LG_PAGE").is_none() {
if let Some(OverrideAllocator::Jemalloc) = builder.config.override_allocator(target)
&& env::var_os("JEMALLOC_SYS_WITH_LG_PAGE").is_none()
{
// Build jemalloc on AArch64 with support for page sizes up to 64K
// See: https://github.com/rust-lang/rust/pull/135081
if target.starts_with("aarch64") {
Expand Down Expand Up @@ -764,8 +766,8 @@ impl Step for Rustdoc {
// to build rustdoc.
//
let mut extra_features = Vec::new();
if builder.config.jemalloc(target) {
extra_features.push("jemalloc".to_string());
if let Some(allocator) = builder.config.override_allocator(target) {
extra_features.push(allocator.feature_name().to_string());
}

let compilers = RustcPrivateCompilers::from_target_compiler(builder, target_compiler);
Expand Down Expand Up @@ -1588,8 +1590,8 @@ tool_rustc_extended!(Clippy {
stable: true,
add_bins_to_sysroot: ["clippy-driver"],
add_features: |builder, target, features| {
if builder.config.jemalloc(target) {
features.push("jemalloc".to_string());
if let Some(allocator) = builder.config.override_allocator(target) {
features.push(allocator.feature_name().to_string());
}
}
});
Expand All @@ -1599,8 +1601,8 @@ tool_rustc_extended!(Miri {
stable: false,
add_bins_to_sysroot: ["miri"],
add_features: |builder, target, features| {
if builder.config.jemalloc(target) {
features.push("jemalloc".to_string());
if let Some(allocator) = builder.config.override_allocator(target) {
features.push(allocator.feature_name().to_string());
}
},
// Always compile also tests when building miri. Otherwise feature unification can cause rebuilds between building and testing miri.
Expand Down
53 changes: 47 additions & 6 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use crate::core::config::toml::target::{
};
use crate::core::config::{
CompilerBuiltins, CompressDebuginfo, DebuginfoLevel, DryRun, GccCiMode, LlvmLibunwind, Merge,
ReplaceOpt, RustcLto, SplitDebuginfo, StringOrBool, threads_from_config,
OverrideAllocator, ReplaceOpt, RustcLto, SplitDebuginfo, StringOrBool, threads_from_config,
};
use crate::core::download::{
DownloadContext, download_beta_toolchain, is_download_ci_available, maybe_download_rustfmt,
Expand Down Expand Up @@ -246,7 +246,7 @@ pub struct Config {
pub hosts: Vec<TargetSelection>,
pub targets: Vec<TargetSelection>,
pub local_rebuild: bool,
pub jemalloc: bool,
pub override_allocator: Option<OverrideAllocator>,
pub control_flow_guard: bool,
pub ehcont_guard: bool,

Expand Down Expand Up @@ -588,6 +588,7 @@ impl Config {
thin_lto_import_instr_limit: rust_thin_lto_import_instr_limit,
parallel_frontend_threads: rust_parallel_frontend_threads,
remap_debuginfo: rust_remap_debuginfo,
override_allocator: rust_override_allocator,
jemalloc: rust_jemalloc,
test_compare_mode: rust_test_compare_mode,
llvm_libunwind: rust_llvm_libunwind,
Expand Down Expand Up @@ -969,6 +970,7 @@ impl Config {
codegen_backends: target_codegen_backends,
runner: target_runner,
optimized_compiler_builtins: target_optimized_compiler_builtins,
override_allocator: target_override_allocator,
jemalloc: target_jemalloc,
} = cfg;

Expand Down Expand Up @@ -1045,7 +1047,11 @@ impl Config {
target.rpath = target_rpath;
target.rustflags = target_rustflags.unwrap_or_default();
target.optimized_compiler_builtins = target_optimized_compiler_builtins;
target.jemalloc = target_jemalloc;
target.override_allocator = reconcile_jemalloc(
target_jemalloc,
target_override_allocator,
&format!("target.{triple}"),
);
if let Some(backends) = target_codegen_backends {
target.codegen_backends =
Some(parse_codegen_backends(backends, &format!("target.{triple}")))
Expand Down Expand Up @@ -1455,7 +1461,6 @@ NOTE: Please add `--stage 2` to your command line, or if you're sure you want to
initial_rustdoc,
initial_rustfmt,
initial_sysroot,
jemalloc: rust_jemalloc.unwrap_or(false),
jobs: Some(threads_from_config(flags_jobs.or(build_jobs).unwrap_or(0))),
json_output: flags_json_output,
keep_stage: flags_keep_stage,
Expand Down Expand Up @@ -1516,6 +1521,7 @@ NOTE: Please add `--stage 2` to your command line, or if you're sure you want to
on_fail: flags_on_fail,
optimized_compiler_builtins,
out,
override_allocator: reconcile_jemalloc(rust_jemalloc, rust_override_allocator, "rust"),
patch_binaries_for_nix: build_patch_binaries_for_nix,
path_modification_cache,
paths,
Expand Down Expand Up @@ -1949,8 +1955,11 @@ NOTE: Please add `--stage 2` to your command line, or if you're sure you want to
self.enabled_codegen_backends(target).first().unwrap()
}

pub fn jemalloc(&self, target: TargetSelection) -> bool {
self.target_config.get(&target).and_then(|cfg| cfg.jemalloc).unwrap_or(self.jemalloc)
pub fn override_allocator(&self, target: TargetSelection) -> Option<OverrideAllocator> {
self.target_config
.get(&target)
.and_then(|cfg| cfg.override_allocator)
.or(self.override_allocator)
}

pub fn rpath_enabled(&self, target: TargetSelection) -> bool {
Expand Down Expand Up @@ -2043,6 +2052,38 @@ impl AsRef<ExecutionContext> for Config {
}
}

/// Reconciles the deprecated `jemalloc` boolean option with the new
/// `override-allocator` option.
///
/// Emits a warning if `jemalloc` is present and errors out if it is set but
/// `override-allocator` is not `jemalloc`. The allocator is overridden if
/// either option is set.
fn reconcile_jemalloc(
jemalloc: Option<bool>,
override_allocator: Option<OverrideAllocator>,
section: &str,
) -> Option<OverrideAllocator> {
if let Some(jemalloc) = jemalloc {
println!(
"WARNING: The `{section}.jemalloc` option is deprecated. \
Use `{section}.override-allocator` instead.",
);
if jemalloc && override_allocator.is_some_and(|a| a != OverrideAllocator::Jemalloc) {
panic!(
"ERROR: `{section}.jemalloc` is set but `{section}.override-allocator` is \
not `jemalloc` ({:?}). Remove the deprecated `jemalloc` option or set \
`override-allocator = \"jemalloc\"`.",
override_allocator,
);
}
}
override_allocator.or(if jemalloc == Some(true) {
Some(OverrideAllocator::Jemalloc)
} else {
None
})
}

fn compute_src_directory(src_dir: Option<PathBuf>, exec_ctx: &ExecutionContext) -> Option<PathBuf> {
if let Some(src) = src_dir {
return Some(src);
Expand Down
26 changes: 26 additions & 0 deletions src/bootstrap/src/core/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,32 @@ impl<'de> Deserialize<'de> for CompilerBuiltins {
}
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum OverrideAllocator {
Jemalloc,
}

impl OverrideAllocator {
pub fn feature_name(self) -> &'static str {
match self {
OverrideAllocator::Jemalloc => "jemalloc",
}
}
}

impl<'de> Deserialize<'de> for OverrideAllocator {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let name = String::deserialize(deserializer)?;
match name.as_str() {
"jemalloc" => Ok(Self::Jemalloc),
other => Err(serde::de::Error::unknown_variant(other, &["jemalloc"])),
}
}
}

#[derive(Copy, Clone, Default, Debug, Eq, PartialEq)]
pub enum DebuginfoLevel {
#[default]
Expand Down
8 changes: 7 additions & 1 deletion src/bootstrap/src/core/config/toml/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use build_helper::ci::CiEnv;
use serde::{Deserialize, Deserializer};

use crate::core::config::toml::TomlConfig;
use crate::core::config::{CompressDebuginfo, DebuginfoLevel, Merge, ReplaceOpt, StringOrBool};
use crate::core::config::{
CompressDebuginfo, DebuginfoLevel, Merge, OverrideAllocator, ReplaceOpt, StringOrBool,
};
use crate::{BTreeSet, CodegenBackendKind, HashSet, PathBuf, TargetSelection, define_config, exit};

define_config! {
Expand Down Expand Up @@ -57,6 +59,8 @@ define_config! {
verify_llvm_ir: Option<bool> = "verify-llvm-ir",
thin_lto_import_instr_limit: Option<u32> = "thin-lto-import-instr-limit",
remap_debuginfo: Option<bool> = "remap-debuginfo",
override_allocator: Option<OverrideAllocator> = "override-allocator",
// FIXME: Remove this option in Q1 2027
jemalloc: Option<bool> = "jemalloc",
test_compare_mode: Option<bool> = "test-compare-mode",
llvm_libunwind: Option<String> = "llvm-libunwind",
Expand Down Expand Up @@ -331,6 +335,7 @@ pub fn check_incompatible_options_for_ci_rustc(
stack_protector,
strip,
jemalloc,
override_allocator,
rpath,
channel,
default_linker,
Expand Down Expand Up @@ -401,6 +406,7 @@ pub fn check_incompatible_options_for_ci_rustc(
err!(current_rust_config.llvm_tools, llvm_tools, "rust");
err!(current_rust_config.llvm_bitcode_linker, llvm_bitcode_linker, "rust");
err!(current_rust_config.jemalloc, jemalloc, "rust");
err!(current_rust_config.override_allocator, override_allocator, "rust");
err!(current_rust_config.default_linker, default_linker, "rust");
err!(current_rust_config.stack_protector, stack_protector, "rust");
err!(current_rust_config.std_features, std_features, "rust");
Expand Down
7 changes: 4 additions & 3 deletions src/bootstrap/src/core/config/toml/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use serde::de::Error;
use serde::{Deserialize, Deserializer};

use crate::core::config::{
CompilerBuiltins, CompressDebuginfo, LlvmLibunwind, Merge, ReplaceOpt, SplitDebuginfo,
StringOrBool,
CompilerBuiltins, CompressDebuginfo, LlvmLibunwind, Merge, OverrideAllocator, ReplaceOpt,
SplitDebuginfo, StringOrBool,
};
use crate::{CodegenBackendKind, HashSet, PathBuf, define_config, exit};

Expand Down Expand Up @@ -48,6 +48,7 @@ define_config! {
codegen_backends: Option<Vec<String>> = "codegen-backends",
runner: Option<String> = "runner",
optimized_compiler_builtins: Option<CompilerBuiltins> = "optimized-compiler-builtins",
override_allocator: Option<OverrideAllocator> = "override-allocator",
jemalloc: Option<bool> = "jemalloc",
}
}
Expand Down Expand Up @@ -83,7 +84,7 @@ pub struct Target {
pub no_std: bool,
pub codegen_backends: Option<Vec<CodegenBackendKind>>,
pub optimized_compiler_builtins: Option<CompilerBuiltins>,
pub jemalloc: Option<bool>,
pub override_allocator: Option<OverrideAllocator>,
}

impl Target {
Expand Down
6 changes: 4 additions & 2 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,8 +866,10 @@ impl Build {
crates.is_empty() || possible_features_by_crates.contains(feature)
};
let mut features = vec![];
if self.config.jemalloc(target) && check("jemalloc") {
features.push("jemalloc");
if let Some(allocator) = self.config.override_allocator(target)
&& check(allocator.feature_name())
{
features.push(allocator.feature_name());
}
if (self.config.llvm_enabled(target) || kind == Kind::Check) && check("llvm") {
features.push("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 @@ -641,4 +641,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
severity: ChangeSeverity::Info,
summary: "New config section `pgo` was introduced, to configure PGO profiling options. The `--rust-profile-use`/`--rust-profile-generate`/`--llvm-profile-use`/`--llvm-profile-generate` flags and the `rust.profile-use`/`rust.profile-generate` config options have been deprecated.",
},
ChangeInfo {
change_id: 155617,
severity: ChangeSeverity::Warning,
summary: "`jemalloc` options are replaced with `override-allocator` which take allocator names such as `jemalloc`",
},
];
Loading
Loading