Skip to content

Commit cba1681

Browse files
committed
Add rust.lto config option
1 parent 32238ce commit cba1681

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

Diff for: config.toml.example

+5
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,11 @@ changelog-seen = 2
638638
# If an explicit setting is given, it will be used for all parts of the codebase.
639639
#new-symbol-mangling = true|false (see comment)
640640

641+
# Select LTO mode that will be used for compiling rustc. By default, thin local LTO (LTO within a
642+
# single crate) is used. You can also select "thin" or "fat" to apply Thin/Fat LTO on the
643+
# `rustc_driver` dylib.
644+
#lto = thin-local
645+
641646
# =============================================================================
642647
# Options for specific targets
643648
#

Diff for: src/bootstrap/compile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use serde::Deserialize;
2121
use crate::builder::Cargo;
2222
use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
2323
use crate::cache::{Interned, INTERNER};
24-
use crate::config::{LlvmLibunwind, TargetSelection};
24+
use crate::config::{LlvmLibunwind, RustcLto, TargetSelection};
2525
use crate::dist;
2626
use crate::native;
2727
use crate::tool::SourceType;

Diff for: src/bootstrap/config.rs

+31
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ pub struct Config {
158158
pub rust_new_symbol_mangling: Option<bool>,
159159
pub rust_profile_use: Option<String>,
160160
pub rust_profile_generate: Option<String>,
161+
pub rust_lto: RustcLto,
161162
pub llvm_profile_use: Option<String>,
162163
pub llvm_profile_generate: bool,
163164
pub llvm_libunwind_default: Option<LlvmLibunwind>,
@@ -319,6 +320,28 @@ impl SplitDebuginfo {
319320
}
320321
}
321322

323+
/// LTO mode used for compiling rustc itself.
324+
#[derive(Default)]
325+
pub enum RustcLto {
326+
#[default]
327+
ThinLocal,
328+
Thin,
329+
Fat
330+
}
331+
332+
impl std::str::FromStr for RustcLto {
333+
type Err = String;
334+
335+
fn from_str(s: &str) -> Result<Self, Self::Err> {
336+
match s {
337+
"thin-local" => Ok(RustcLto::ThinLocal),
338+
"thin" => Ok(RustcLto::Thin),
339+
"fat" => Ok(RustcLto::Fat),
340+
_ => Err(format!("Invalid value for rustc LTO: {}", s)),
341+
}
342+
}
343+
}
344+
322345
#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
323346
pub struct TargetSelection {
324347
pub triple: Interned<String>,
@@ -726,6 +749,7 @@ define_config! {
726749
profile_use: Option<String> = "profile-use",
727750
// ignored; this is set from an env var set by bootstrap.py
728751
download_rustc: Option<StringOrBool> = "download-rustc",
752+
lto: Option<String> = "lto",
729753
}
730754
}
731755

@@ -1173,6 +1197,13 @@ impl Config {
11731197
config.rust_profile_use = flags.rust_profile_use.or(rust.profile_use);
11741198
config.rust_profile_generate = flags.rust_profile_generate.or(rust.profile_generate);
11751199
config.download_rustc_commit = download_ci_rustc_commit(&config, rust.download_rustc);
1200+
1201+
config.rust_lto = rust
1202+
.lto
1203+
.as_deref()
1204+
.map(RustcLto::from_str)
1205+
.map(|v| v.expect("invalid value for rust.lto"))
1206+
.unwrap_or_default();
11761207
} else {
11771208
config.rust_profile_use = flags.rust_profile_use;
11781209
config.rust_profile_generate = flags.rust_profile_generate;

Diff for: src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ ENV RUST_CONFIGURE_ARGS \
7878
--set llvm.thin-lto=true \
7979
--set llvm.ninja=false \
8080
--set rust.jemalloc \
81-
--set rust.use-lld=true
81+
--set rust.use-lld=true \
82+
--set rust.lto=thin
8283
ENV SCRIPT ../src/ci/pgo.sh python3 ../x.py dist \
8384
--host $HOSTS --target $HOSTS \
8485
--include-default-paths \

0 commit comments

Comments
 (0)