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.override-allocator=jemalloc \
--set build.allocator=jemalloc \
--set rust.bootstrap-override-lld=true \
--set rust.lto=thin \
--set rust.codegen-units=1
Expand Down
24 changes: 12 additions & 12 deletions bootstrap.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,12 @@
# For example, exclude = ["tests/ui", "src/tools/tidy"].
#build.exclude = []

# 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: "system" (default), "jemalloc"
#build.allocator = "jemalloc"

# =============================================================================
# General install configuration options
# =============================================================================
Expand Down Expand Up @@ -859,15 +865,9 @@
# Useful for reproducible builds. Generally only set for releases
#rust.remap-debuginfo = false

# 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.
# Deprecated alias for `build.allocator`. Setting this to `true` is
# equivalent to `build.allocator = "jemalloc"`. Both cannot be set in the same section
# (`rust` or `target.[target]`)
#rust.jemalloc = false

# Run tests in various test suites with the "nll compare mode" in addition to
Expand Down Expand Up @@ -1177,10 +1177,10 @@
#optimized-compiler-builtins = build.optimized-compiler-builtins (bool or path)

# 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)
# This overrides the global `build.allocator` option. See that option for more info.
#allocator = build.allocator (string)

# Deprecated alias for `override-allocator`. See `rust.jemalloc` for more info.
# Deprecated alias for `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
2 changes: 1 addition & 1 deletion src/bootstrap/download-ci-llvm-stamp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Change this file to make users of the `download-ci-llvm` configuration download
a new version of LLVM from CI, even if the LLVM submodule hasn’t changed.

Last change is for: https://github.com/rust-lang/rust/pull/158766
Last change is for: https://github.com/rust-lang/rust/pull/160100
4 changes: 2 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, OverrideAllocator, RustcLto, TargetSelection,
Allocator, CompilerBuiltins, DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection,
};
use crate::utils::build_stamp;
use crate::utils::build_stamp::BuildStamp;
Expand Down Expand Up @@ -1392,7 +1392,7 @@ 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 let Some(OverrideAllocator::Jemalloc) = builder.config.override_allocator(target)
if builder.config.allocator(target) == Allocator::Jemalloc
&& env::var_os("JEMALLOC_SYS_WITH_LG_PAGE").is_none()
{
// Build jemalloc on AArch64 with support for page sizes up to 64K
Expand Down
16 changes: 8 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, CommandLineStep, RunConfig, ShouldRun, Step, StepMetadata,
apply_pgo, cargo_profile_var,
};
use crate::core::config::{DebuginfoLevel, OverrideAllocator, RustcLto, TargetSelection};
use crate::core::config::{Allocator, DebuginfoLevel, 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 @@ -241,7 +241,7 @@ 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 let Some(OverrideAllocator::Jemalloc) = builder.config.override_allocator(target)
if builder.config.allocator(target) == Allocator::Jemalloc
&& env::var_os("JEMALLOC_SYS_WITH_LG_PAGE").is_none()
{
// Build jemalloc on AArch64 with support for page sizes up to 64K
Expand Down Expand Up @@ -767,8 +767,8 @@ impl CommandLineStep for Rustdoc {
// to build rustdoc.
//
let mut extra_features = Vec::new();
if let Some(allocator) = builder.config.override_allocator(target) {
extra_features.push(allocator.feature_name().to_string());
if let Some(allocator_feature_name) = builder.config.allocator(target).feature_name() {
extra_features.push(allocator_feature_name.to_string());
}
if !builder.config.rust_debug_logging {
extra_features.push("max_level_info".to_string())
Expand Down Expand Up @@ -1585,8 +1585,8 @@ tool_rustc_extended!(Clippy {
stable: true,
add_bins_to_sysroot: ["clippy-driver"],
add_features: |builder, target, features| {
if let Some(allocator) = builder.config.override_allocator(target) {
features.push(allocator.feature_name().to_string());
if let Some(allocator_feature_name) = builder.config.allocator(target).feature_name() {
features.push(allocator_feature_name.to_string());
}
}
});
Expand All @@ -1596,8 +1596,8 @@ tool_rustc_extended!(Miri {
stable: false,
add_bins_to_sysroot: ["miri"],
add_features: |builder, target, features| {
if let Some(allocator) = builder.config.override_allocator(target) {
features.push(allocator.feature_name().to_string());
if let Some(allocator_feature_name) = builder.config.allocator(target).feature_name() {
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
74 changes: 40 additions & 34 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ use crate::core::config::toml::target::{
DefaultLinuxLinkerOverride, Target, TomlTarget, default_linux_linker_overrides,
};
use crate::core::config::{
CompilerBuiltins, CompressDebuginfo, DebuggerPath, DebuginfoLevel, DryRun, GccCiMode,
LlvmLibunwind, Merge, OverrideAllocator, ReplaceOpt, RustcLto, SplitDebuginfo, StringOrBool,
Allocator, CompilerBuiltins, CompressDebuginfo, DebuggerPath, DebuginfoLevel, DryRun,
GccCiMode, LlvmLibunwind, Merge, ReplaceOpt, RustcLto, SplitDebuginfo, StringOrBool,
threads_from_config,
};
use crate::core::download::{
Expand Down Expand Up @@ -249,7 +249,7 @@ pub struct Config {
pub hosts: Vec<TargetSelection>,
pub targets: Vec<TargetSelection>,
pub local_rebuild: bool,
pub override_allocator: Option<OverrideAllocator>,
pub allocator: Option<Allocator>,
pub control_flow_guard: bool,
pub ehcont_guard: bool,

Expand Down Expand Up @@ -538,6 +538,7 @@ impl Config {
exclude: build_exclude,
compiletest_allow_stage0: build_compiletest_allow_stage0,
sde: build_sde,
allocator: build_allocator,
} = toml_build.unwrap_or_default();

let Install {
Expand Down Expand Up @@ -590,7 +591,6 @@ 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 @@ -970,7 +970,7 @@ impl Config {
codegen_backends: target_codegen_backends,
runner: target_runner,
optimized_compiler_builtins: target_optimized_compiler_builtins,
override_allocator: target_override_allocator,
allocator: target_allocator,
jemalloc: target_jemalloc,
} = cfg;

Expand Down Expand Up @@ -1047,9 +1047,10 @@ impl Config {
target.rpath = target_rpath;
target.rustflags = target_rustflags.unwrap_or_default();
target.optimized_compiler_builtins = target_optimized_compiler_builtins;
target.override_allocator = reconcile_jemalloc(
target.allocator = reconcile_jemalloc(
target_jemalloc,
target_override_allocator,
target_allocator,
&format!("target.{triple}"),
&format!("target.{triple}"),
);
if let Some(backends) = target_codegen_backends {
Expand Down Expand Up @@ -1396,6 +1397,7 @@ NOTE: Please add `--stage 2` to your command line, or if you're sure you want to

Config {
// tidy-alphabetical-start
allocator: reconcile_jemalloc(rust_jemalloc, build_allocator, "rust", "build"),
android_ndk: build_android_ndk,
backtrace: rust_backtrace.unwrap_or(true),
backtrace_on_ice: rust_backtrace_on_ice.unwrap_or(false),
Expand Down Expand Up @@ -1521,7 +1523,6 @@ 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 @@ -1956,11 +1957,12 @@ 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 override_allocator(&self, target: TargetSelection) -> Option<OverrideAllocator> {
pub fn allocator(&self, target: TargetSelection) -> Allocator {
self.target_config
.get(&target)
.and_then(|cfg| cfg.override_allocator)
.or(self.override_allocator)
.and_then(|cfg| cfg.allocator)
.or(self.allocator)
.unwrap_or(Allocator::System)
}

pub fn rpath_enabled(&self, target: TargetSelection) -> bool {
Expand Down Expand Up @@ -2054,35 +2056,39 @@ impl AsRef<ExecutionContext> for Config {
}

/// Reconciles the deprecated `jemalloc` boolean option with the new
/// `override-allocator` option.
/// `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.
/// Emits a warning if `jemalloc` is set, and an error if *both* `jemalloc` and `allocator` are 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,
allocator: Option<Allocator>,
jemalloc_section: &str,
allocator_section: &str,
) -> Option<Allocator> {
match (jemalloc, allocator) {
(None, None) => None,
(None, Some(allocator)) => Some(allocator),
(Some(true), None) => {
println!(
"WARNING: The `jemalloc` option is deprecated. \
Please use `{allocator_section}.allocator = \"jemalloc\"` instead of `{jemalloc_section}.jemalloc = true`",
);
Some(Allocator::Jemalloc)
}
(Some(false), None) => {
println!(
"WARNING: The `jemalloc` option is deprecated. \
Please use `{allocator_section}.allocator = \"system\"` instead of `{jemalloc_section}.jemalloc = false`",
);
Some(Allocator::System)
}
_ => {
panic!(
"ERROR: `{jemalloc_section}.jemalloc` and `{allocator_section}.allocator` are both set. \
Please remove the outdated `{jemalloc_section}.jemalloc` directive."
)
}
}
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> {
Expand Down
15 changes: 9 additions & 6 deletions src/bootstrap/src/core/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,27 +252,30 @@ impl<'de> Deserialize<'de> for CompilerBuiltins {
}

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

impl OverrideAllocator {
pub fn feature_name(self) -> &'static str {
impl Allocator {
pub fn feature_name(self) -> Option<&'static str> {
match self {
OverrideAllocator::Jemalloc => "jemalloc",
Allocator::System => None,
Allocator::Jemalloc => Some("jemalloc"),
}
}
}

impl<'de> Deserialize<'de> for OverrideAllocator {
impl<'de> Deserialize<'de> for Allocator {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let name = String::deserialize(deserializer)?;
match name.as_str() {
"system" => Ok(Self::System),
"jemalloc" => Ok(Self::Jemalloc),
other => Err(serde::de::Error::unknown_variant(other, &["jemalloc"])),
other => Err(serde::de::Error::unknown_variant(other, &["system", "jemalloc"])),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/bootstrap/src/core/config/toml/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::collections::HashMap;
use serde::{Deserialize, Deserializer};

use crate::core::config::toml::ReplaceOpt;
use crate::core::config::{CompilerBuiltins, DebuggerPath, Merge, StringOrBool};
use crate::core::config::{Allocator, CompilerBuiltins, DebuggerPath, Merge, StringOrBool};
use crate::{HashSet, PathBuf, define_config, exit};

define_config! {
Expand Down Expand Up @@ -77,6 +77,7 @@ define_config! {
exclude: Option<Vec<PathBuf>> = "exclude",
record_failed_tests_path: Option<String> = "record_failed_tests_path",
sde: Option<String> = "sde",
allocator: Option<Allocator> = "allocator",
}
}

Expand Down
Loading
Loading