Skip to content

Commit e1f04c0

Browse files
Disable ThinLTO for dist builds.
Dist builds should always be as fast as we can make them, and since those run on CI we don't care quite as much for the build being somewhat slower. As such, we don't automatically enable ThinLTO on builds for the dist builders.
1 parent 616b66d commit e1f04c0

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

config.toml.example

+5
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@
235235
# compiler.
236236
#codegen-units = 1
237237

238+
# Whether to enable ThinLTO (and increase the codegen units to either a default
239+
# or the configured value). On by default. If we want the fastest possible
240+
# compiler, we should disable this.
241+
#thinlto = true
242+
238243
# Whether or not debug assertions are enabled for the compiler and standard
239244
# library. Also enables compilation of debug! and trace! logging macros.
240245
#debug-assertions = false

src/bootstrap/builder.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -509,10 +509,6 @@ impl<'a> Builder<'a> {
509509
})
510510
.env("TEST_MIRI", self.config.test_miri.to_string())
511511
.env("RUSTC_ERROR_METADATA_DST", self.extended_error_dir());
512-
if let Some(n) = self.config.rust_codegen_units {
513-
cargo.env("RUSTC_CODEGEN_UNITS", n.to_string());
514-
}
515-
516512

517513
if let Some(host_linker) = self.build.linker(compiler.host) {
518514
cargo.env("RUSTC_HOST_LINKER", host_linker);
@@ -679,18 +675,31 @@ impl<'a> Builder<'a> {
679675
if self.is_very_verbose() {
680676
cargo.arg("-v");
681677
}
678+
679+
// This must be kept before the thinlto check, as we set codegen units
680+
// to 1 forcibly there.
681+
if let Some(n) = self.config.rust_codegen_units {
682+
cargo.env("RUSTC_CODEGEN_UNITS", n.to_string());
683+
}
684+
682685
if self.config.rust_optimize {
683686
// FIXME: cargo bench does not accept `--release`
684687
if cmd != "bench" {
685688
cargo.arg("--release");
686689
}
687690

688691
if self.config.rust_codegen_units.is_none() &&
689-
self.build.is_rust_llvm(compiler.host)
690-
{
692+
self.build.is_rust_llvm(compiler.host) &&
693+
self.config.rust_thinlto {
691694
cargo.env("RUSTC_THINLTO", "1");
695+
} else if self.config.rust_codegen_units.is_none() {
696+
// Generally, if ThinLTO has been disabled for some reason, we
697+
// want to set the codegen units to 1. However, we shouldn't do
698+
// this if the option was specifically set by the user.
699+
cargo.env("RUSTC_CODEGEN_UNITS", "1");
692700
}
693701
}
702+
694703
if self.config.locked_deps {
695704
cargo.arg("--locked");
696705
}

src/bootstrap/config.rs

+5
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ pub struct Config {
8181
// rust codegen options
8282
pub rust_optimize: bool,
8383
pub rust_codegen_units: Option<u32>,
84+
pub rust_thinlto: bool,
8485
pub rust_debug_assertions: bool,
8586
pub rust_debuginfo: bool,
8687
pub rust_debuginfo_lines: bool,
@@ -261,6 +262,7 @@ impl Default for StringOrBool {
261262
struct Rust {
262263
optimize: Option<bool>,
263264
codegen_units: Option<u32>,
265+
thinlto: Option<bool>,
264266
debug_assertions: Option<bool>,
265267
debuginfo: Option<bool>,
266268
debuginfo_lines: Option<bool>,
@@ -412,6 +414,7 @@ impl Config {
412414

413415
// Store off these values as options because if they're not provided
414416
// we'll infer default values for them later
417+
let mut thinlto = None;
415418
let mut llvm_assertions = None;
416419
let mut debuginfo_lines = None;
417420
let mut debuginfo_only_std = None;
@@ -455,6 +458,7 @@ impl Config {
455458
optimize = rust.optimize;
456459
ignore_git = rust.ignore_git;
457460
debug_jemalloc = rust.debug_jemalloc;
461+
thinlto = rust.thinlto;
458462
set(&mut config.rust_optimize_tests, rust.optimize_tests);
459463
set(&mut config.rust_debuginfo_tests, rust.debuginfo_tests);
460464
set(&mut config.codegen_tests, rust.codegen_tests);
@@ -539,6 +543,7 @@ impl Config {
539543
"stable" | "beta" | "nightly" => true,
540544
_ => false,
541545
};
546+
config.rust_thinlto = thinlto.unwrap_or(true);
542547
config.rust_debuginfo_lines = debuginfo_lines.unwrap_or(default);
543548
config.rust_debuginfo_only_std = debuginfo_only_std.unwrap_or(default);
544549

src/bootstrap/configure.py

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def v(*args):
7070
# Optimization and debugging options. These may be overridden by the release
7171
# channel, etc.
7272
o("optimize", "rust.optimize", "build optimized rust code")
73+
o("thinlto", "rust.thinlto", "build Rust with ThinLTO enabled")
7374
o("optimize-llvm", "llvm.optimize", "build optimized LLVM")
7475
o("llvm-assertions", "llvm.assertions", "build LLVM with assertions")
7576
o("debug-assertions", "rust.debug-assertions", "build with debugging assertions")

src/ci/run.sh

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export RUST_RELEASE_CHANNEL=nightly
4646
if [ "$DEPLOY$DEPLOY_ALT" != "" ]; then
4747
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=$RUST_RELEASE_CHANNEL"
4848
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-static-stdcpp"
49+
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-thinlto"
4950

5051
if [ "$NO_LLVM_ASSERTIONS" = "1" ]; then
5152
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-llvm-assertions"

0 commit comments

Comments
 (0)