From cba16819a1aa2f99c861eba907847db39fea06c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Thu, 29 Sep 2022 16:28:57 +0200 Subject: [PATCH] Add `rust.lto` config option --- config.toml.example | 5 +++ src/bootstrap/compile.rs | 2 +- src/bootstrap/config.rs | 31 +++++++++++++++++++ .../host-x86_64/dist-x86_64-linux/Dockerfile | 3 +- 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, pub rust_profile_use: Option, pub rust_profile_generate: Option, + pub rust_lto: RustcLto, pub llvm_profile_use: Option, pub llvm_profile_generate: bool, pub llvm_libunwind_default: Option, @@ -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 { + 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, @@ -726,6 +749,7 @@ define_config! { profile_use: Option = "profile-use", // ignored; this is set from an env var set by bootstrap.py download_rustc: Option = "download-rustc", + lto: Option = "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 \