about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJakub Beránek <berykubik@gmail.com>2022-09-29 16:28:57 +0200
committerJakub Beránek <berykubik@gmail.com>2022-10-23 13:43:08 +0200
commitcba16819a1aa2f99c861eba907847db39fea06c5 (patch)
tree4bae651d8f19f353a2099950729cf35c504a3acc
parent32238ce1e2219bfec46bc660091b2dcac0168148 (diff)
downloadrust-cba16819a1aa2f99c861eba907847db39fea06c5.tar.gz
rust-cba16819a1aa2f99c861eba907847db39fea06c5.zip
Add `rust.lto` config option
-rw-r--r--config.toml.example5
-rw-r--r--src/bootstrap/compile.rs2
-rw-r--r--src/bootstrap/config.rs31
-rw-r--r--src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile3
4 files changed, 39 insertions, 2 deletions
diff --git a/config.toml.example b/config.toml.example
index 1f5747456e9..35b07924b8e 100644
--- a/config.toml.example
+++ b/config.toml.example
@@ -638,6 +638,11 @@ changelog-seen = 2
 # If an explicit setting is given, it will be used for all parts of the codebase.
 #new-symbol-mangling = true|false (see comment)
 
+# Select LTO mode that will be used for compiling rustc. By default, thin local LTO (LTO within a
+# single crate) is used. You can also select "thin" or "fat" to apply Thin/Fat LTO on the
+# `rustc_driver` dylib.
+#lto = thin-local
+
 # =============================================================================
 # Options for specific targets
 #
diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs
index 4ccdabe4bb6..f59f2021484 100644
--- a/src/bootstrap/compile.rs
+++ b/src/bootstrap/compile.rs
@@ -21,7 +21,7 @@ use serde::Deserialize;
 use crate::builder::Cargo;
 use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
 use crate::cache::{Interned, INTERNER};
-use crate::config::{LlvmLibunwind, TargetSelection};
+use crate::config::{LlvmLibunwind, RustcLto, TargetSelection};
 use crate::dist;
 use crate::native;
 use crate::tool::SourceType;
diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs
index 635823b958b..4025697dabe 100644
--- a/src/bootstrap/config.rs
+++ b/src/bootstrap/config.rs
@@ -158,6 +158,7 @@ pub struct Config {
     pub rust_new_symbol_mangling: Option<bool>,
     pub rust_profile_use: Option<String>,
     pub rust_profile_generate: Option<String>,
+    pub rust_lto: RustcLto,
     pub llvm_profile_use: Option<String>,
     pub llvm_profile_generate: bool,
     pub llvm_libunwind_default: Option<LlvmLibunwind>,
@@ -319,6 +320,28 @@ impl SplitDebuginfo {
     }
 }
 
+/// LTO mode used for compiling rustc itself.
+#[derive(Default)]
+pub enum RustcLto {
+    #[default]
+    ThinLocal,
+    Thin,
+    Fat
+}
+
+impl std::str::FromStr for RustcLto {
+    type Err = String;
+
+    fn from_str(s: &str) -> Result<Self, Self::Err> {
+        match s {
+            "thin-local" => Ok(RustcLto::ThinLocal),
+            "thin" => Ok(RustcLto::Thin),
+            "fat" => Ok(RustcLto::Fat),
+            _ => Err(format!("Invalid value for rustc LTO: {}", s)),
+        }
+    }
+}
+
 #[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
 pub struct TargetSelection {
     pub triple: Interned<String>,
@@ -726,6 +749,7 @@ define_config! {
         profile_use: Option<String> = "profile-use",
         // ignored; this is set from an env var set by bootstrap.py
         download_rustc: Option<StringOrBool> = "download-rustc",
+        lto: Option<String> = "lto",
     }
 }
 
@@ -1173,6 +1197,13 @@ impl Config {
             config.rust_profile_use = flags.rust_profile_use.or(rust.profile_use);
             config.rust_profile_generate = flags.rust_profile_generate.or(rust.profile_generate);
             config.download_rustc_commit = download_ci_rustc_commit(&config, rust.download_rustc);
+
+            config.rust_lto = rust
+                .lto
+                .as_deref()
+                .map(RustcLto::from_str)
+                .map(|v| v.expect("invalid value for rust.lto"))
+                .unwrap_or_default();
         } else {
             config.rust_profile_use = flags.rust_profile_use;
             config.rust_profile_generate = flags.rust_profile_generate;
diff --git a/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile b/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile
index b960239807a..423aba06cca 100644
--- a/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile
+++ b/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile
@@ -78,7 +78,8 @@ ENV RUST_CONFIGURE_ARGS \
       --set llvm.thin-lto=true \
       --set llvm.ninja=false \
       --set rust.jemalloc \
-      --set rust.use-lld=true
+      --set rust.use-lld=true \
+      --set rust.lto=thin
 ENV SCRIPT ../src/ci/pgo.sh python3 ../x.py dist \
     --host $HOSTS --target $HOSTS \
     --include-default-paths \