Skip to content

Commit af33da3

Browse files
authored
Rollup merge of rust-lang#144807 - Shourya742:2025-07-30-streamline-config, r=Kobzol
Streamline config in bootstrap This PR restructures the config module to improve readability and debuggability. It also aims to eliminate as many invariants as possible. Best reviewed commit by commit. r? `````@Kobzol`````
2 parents 44ffe10 + 962836d commit af33da3

File tree

10 files changed

+935
-951
lines changed

10 files changed

+935
-951
lines changed

src/bootstrap/src/core/config/config.rs

Lines changed: 908 additions & 419 deletions
Large diffs are not rendered by default.

src/bootstrap/src/core/config/toml/dist.rs

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
88
use serde::{Deserialize, Deserializer};
99

10+
use crate::core::config::Merge;
1011
use crate::core::config::toml::ReplaceOpt;
11-
use crate::core::config::{Merge, set};
12-
use crate::{Config, HashSet, PathBuf, define_config, exit};
12+
use crate::{HashSet, PathBuf, define_config, exit};
1313

1414
define_config! {
15+
#[derive(Default)]
1516
struct Dist {
1617
sign_folder: Option<String> = "sign-folder",
1718
upload_addr: Option<String> = "upload-addr",
@@ -22,31 +23,3 @@ define_config! {
2223
vendor: Option<bool> = "vendor",
2324
}
2425
}
25-
26-
impl Config {
27-
/// Applies distribution-related configuration from the `Dist` struct
28-
/// to the global `Config` structure.
29-
pub fn apply_dist_config(&mut self, toml_dist: Option<Dist>) {
30-
if let Some(dist) = toml_dist {
31-
let Dist {
32-
sign_folder,
33-
upload_addr,
34-
src_tarball,
35-
compression_formats,
36-
compression_profile,
37-
include_mingw_linker,
38-
vendor,
39-
} = dist;
40-
self.dist_sign_folder = sign_folder.map(PathBuf::from);
41-
self.dist_upload_addr = upload_addr;
42-
self.dist_compression_formats = compression_formats;
43-
set(&mut self.dist_compression_profile, compression_profile);
44-
set(&mut self.rust_dist_src, src_tarball);
45-
set(&mut self.dist_include_mingw_linker, include_mingw_linker);
46-
self.dist_vendor = vendor.unwrap_or_else(|| {
47-
// If we're building from git or tarball sources, enable it by default.
48-
self.rust_info.is_managed_git_subrepository() || self.rust_info.is_from_tarball()
49-
});
50-
}
51-
}
52-
}

src/bootstrap/src/core/config/toml/gcc.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,14 @@
66
77
use serde::{Deserialize, Deserializer};
88

9+
use crate::core::config::Merge;
910
use crate::core::config::toml::ReplaceOpt;
10-
use crate::core::config::{GccCiMode, Merge};
11-
use crate::{Config, HashSet, PathBuf, define_config, exit};
11+
use crate::{HashSet, PathBuf, define_config, exit};
1212

1313
define_config! {
1414
/// TOML representation of how the GCC build is configured.
15+
#[derive(Default)]
1516
struct Gcc {
1617
download_ci_gcc: Option<bool> = "download-ci-gcc",
1718
}
1819
}
19-
20-
impl Config {
21-
/// Applies GCC-related configuration from the `TomlGcc` struct to the
22-
/// global `Config` structure.
23-
pub fn apply_gcc_config(&mut self, toml_gcc: Option<Gcc>) {
24-
if let Some(gcc) = toml_gcc {
25-
self.gcc_ci_mode = match gcc.download_ci_gcc {
26-
Some(value) => match value {
27-
true => GccCiMode::DownloadFromCi,
28-
false => GccCiMode::BuildLocally,
29-
},
30-
None => GccCiMode::default(),
31-
};
32-
}
33-
}
34-
}

src/bootstrap/src/core/config/toml/install.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
99
use serde::{Deserialize, Deserializer};
1010

11+
use crate::core::config::Merge;
1112
use crate::core::config::toml::ReplaceOpt;
12-
use crate::core::config::{Merge, set};
13-
use crate::{Config, HashSet, PathBuf, define_config, exit};
13+
use crate::{HashSet, PathBuf, define_config, exit};
1414

1515
define_config! {
1616
/// TOML representation of various global install decisions.
17+
#[derive(Default)]
1718
struct Install {
1819
prefix: Option<String> = "prefix",
1920
sysconfdir: Option<String> = "sysconfdir",
@@ -24,20 +25,3 @@ define_config! {
2425
datadir: Option<String> = "datadir",
2526
}
2627
}
27-
28-
impl Config {
29-
/// Applies installation-related configuration from the `Install` struct
30-
/// to the global `Config` structure.
31-
pub fn apply_install_config(&mut self, toml_install: Option<Install>) {
32-
if let Some(install) = toml_install {
33-
let Install { prefix, sysconfdir, docdir, bindir, libdir, mandir, datadir } = install;
34-
self.prefix = prefix.map(PathBuf::from);
35-
self.sysconfdir = sysconfdir.map(PathBuf::from);
36-
self.datadir = datadir.map(PathBuf::from);
37-
self.docdir = docdir.map(PathBuf::from);
38-
set(&mut self.bindir, bindir.map(PathBuf::from));
39-
self.libdir = libdir.map(PathBuf::from);
40-
self.mandir = mandir.map(PathBuf::from);
41-
}
42-
}
43-
}

src/bootstrap/src/core/config/toml/llvm.rs

Lines changed: 3 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
44
use serde::{Deserialize, Deserializer};
55

6+
use crate::core::config::StringOrBool;
67
use crate::core::config::toml::{Merge, ReplaceOpt, TomlConfig};
7-
use crate::core::config::{StringOrBool, set};
8-
use crate::{Config, HashMap, HashSet, PathBuf, define_config, exit};
8+
use crate::{HashMap, HashSet, PathBuf, define_config, exit};
99

1010
define_config! {
1111
/// TOML representation of how the LLVM build is configured.
12+
#[derive(Default)]
1213
struct Llvm {
1314
optimize: Option<bool> = "optimize",
1415
thin_lto: Option<bool> = "thin-lto",
@@ -144,127 +145,3 @@ pub fn check_incompatible_options_for_ci_llvm(
144145

145146
Ok(())
146147
}
147-
148-
impl Config {
149-
pub fn apply_llvm_config(&mut self, toml_llvm: Option<Llvm>) {
150-
let mut llvm_tests = None;
151-
let mut llvm_enzyme = None;
152-
let mut llvm_offload = None;
153-
let mut llvm_plugins = None;
154-
155-
if let Some(llvm) = toml_llvm {
156-
let Llvm {
157-
optimize: optimize_toml,
158-
thin_lto,
159-
release_debuginfo,
160-
assertions: _,
161-
tests,
162-
enzyme,
163-
plugins,
164-
static_libstdcpp,
165-
libzstd,
166-
ninja,
167-
targets,
168-
experimental_targets,
169-
link_jobs,
170-
link_shared,
171-
version_suffix,
172-
clang_cl,
173-
cflags,
174-
cxxflags,
175-
ldflags,
176-
use_libcxx,
177-
use_linker,
178-
allow_old_toolchain,
179-
offload,
180-
polly,
181-
clang,
182-
enable_warnings,
183-
download_ci_llvm,
184-
build_config,
185-
} = llvm;
186-
187-
set(&mut self.ninja_in_file, ninja);
188-
llvm_tests = tests;
189-
llvm_enzyme = enzyme;
190-
llvm_offload = offload;
191-
llvm_plugins = plugins;
192-
set(&mut self.llvm_optimize, optimize_toml);
193-
set(&mut self.llvm_thin_lto, thin_lto);
194-
set(&mut self.llvm_release_debuginfo, release_debuginfo);
195-
set(&mut self.llvm_static_stdcpp, static_libstdcpp);
196-
set(&mut self.llvm_libzstd, libzstd);
197-
if let Some(v) = link_shared {
198-
self.llvm_link_shared.set(Some(v));
199-
}
200-
self.llvm_targets.clone_from(&targets);
201-
self.llvm_experimental_targets.clone_from(&experimental_targets);
202-
self.llvm_link_jobs = link_jobs;
203-
self.llvm_version_suffix.clone_from(&version_suffix);
204-
self.llvm_clang_cl.clone_from(&clang_cl);
205-
206-
self.llvm_cflags.clone_from(&cflags);
207-
self.llvm_cxxflags.clone_from(&cxxflags);
208-
self.llvm_ldflags.clone_from(&ldflags);
209-
set(&mut self.llvm_use_libcxx, use_libcxx);
210-
self.llvm_use_linker.clone_from(&use_linker);
211-
self.llvm_allow_old_toolchain = allow_old_toolchain.unwrap_or(false);
212-
self.llvm_offload = offload.unwrap_or(false);
213-
self.llvm_polly = polly.unwrap_or(false);
214-
self.llvm_clang = clang.unwrap_or(false);
215-
self.llvm_enable_warnings = enable_warnings.unwrap_or(false);
216-
self.llvm_build_config = build_config.clone().unwrap_or(Default::default());
217-
218-
self.llvm_from_ci = self.parse_download_ci_llvm(download_ci_llvm, self.llvm_assertions);
219-
220-
if self.llvm_from_ci {
221-
let warn = |option: &str| {
222-
println!(
223-
"WARNING: `{option}` will only be used on `compiler/rustc_llvm` build, not for the LLVM build."
224-
);
225-
println!(
226-
"HELP: To use `{option}` for LLVM builds, set `download-ci-llvm` option to false."
227-
);
228-
};
229-
230-
if static_libstdcpp.is_some() {
231-
warn("static-libstdcpp");
232-
}
233-
234-
if link_shared.is_some() {
235-
warn("link-shared");
236-
}
237-
238-
// FIXME(#129153): instead of all the ad-hoc `download-ci-llvm` checks that follow,
239-
// use the `builder-config` present in tarballs since #128822 to compare the local
240-
// config to the ones used to build the LLVM artifacts on CI, and only notify users
241-
// if they've chosen a different value.
242-
243-
if libzstd.is_some() {
244-
println!(
245-
"WARNING: when using `download-ci-llvm`, the local `llvm.libzstd` option, \
246-
like almost all `llvm.*` options, will be ignored and set by the LLVM CI \
247-
artifacts builder config."
248-
);
249-
println!(
250-
"HELP: To use `llvm.libzstd` for LLVM/LLD builds, set `download-ci-llvm` option to false."
251-
);
252-
}
253-
}
254-
255-
if !self.llvm_from_ci && self.llvm_thin_lto && link_shared.is_none() {
256-
// If we're building with ThinLTO on, by default we want to link
257-
// to LLVM shared, to avoid re-doing ThinLTO (which happens in
258-
// the link step) with each stage.
259-
self.llvm_link_shared.set(Some(true));
260-
}
261-
} else {
262-
self.llvm_from_ci = self.parse_download_ci_llvm(None, false);
263-
}
264-
265-
self.llvm_tests = llvm_tests.unwrap_or(false);
266-
self.llvm_enzyme = llvm_enzyme.unwrap_or(false);
267-
self.llvm_offload = llvm_offload.unwrap_or(false);
268-
self.llvm_plugins = llvm_plugins.unwrap_or(false);
269-
}
270-
}

src/bootstrap/src/core/config/toml/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! these raw TOML configurations from various sources (the main `bootstrap.toml`,
66
//! included files, profile defaults, and command-line overrides). This processed
77
//! TOML data then serves as an intermediate representation, which is further
8-
//! transformed and applied to the final [`Config`] struct.
8+
//! transformed and applied to the final `Config` struct.
99
1010
use serde::Deserialize;
1111
use serde_derive::Deserialize;

0 commit comments

Comments
 (0)