mirror of
https://github.com/rust-lang/rust.git
synced 2025-12-30 01:04:35 +00:00
Rollup merge of #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`````
This commit is contained in:
commit
af33da37f6
File diff suppressed because it is too large
Load Diff
@ -7,11 +7,12 @@
|
||||
|
||||
use serde::{Deserialize, Deserializer};
|
||||
|
||||
use crate::core::config::Merge;
|
||||
use crate::core::config::toml::ReplaceOpt;
|
||||
use crate::core::config::{Merge, set};
|
||||
use crate::{Config, HashSet, PathBuf, define_config, exit};
|
||||
use crate::{HashSet, PathBuf, define_config, exit};
|
||||
|
||||
define_config! {
|
||||
#[derive(Default)]
|
||||
struct Dist {
|
||||
sign_folder: Option<String> = "sign-folder",
|
||||
upload_addr: Option<String> = "upload-addr",
|
||||
@ -22,31 +23,3 @@ define_config! {
|
||||
vendor: Option<bool> = "vendor",
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
/// Applies distribution-related configuration from the `Dist` struct
|
||||
/// to the global `Config` structure.
|
||||
pub fn apply_dist_config(&mut self, toml_dist: Option<Dist>) {
|
||||
if let Some(dist) = toml_dist {
|
||||
let Dist {
|
||||
sign_folder,
|
||||
upload_addr,
|
||||
src_tarball,
|
||||
compression_formats,
|
||||
compression_profile,
|
||||
include_mingw_linker,
|
||||
vendor,
|
||||
} = dist;
|
||||
self.dist_sign_folder = sign_folder.map(PathBuf::from);
|
||||
self.dist_upload_addr = upload_addr;
|
||||
self.dist_compression_formats = compression_formats;
|
||||
set(&mut self.dist_compression_profile, compression_profile);
|
||||
set(&mut self.rust_dist_src, src_tarball);
|
||||
set(&mut self.dist_include_mingw_linker, include_mingw_linker);
|
||||
self.dist_vendor = vendor.unwrap_or_else(|| {
|
||||
// If we're building from git or tarball sources, enable it by default.
|
||||
self.rust_info.is_managed_git_subrepository() || self.rust_info.is_from_tarball()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,29 +6,14 @@
|
||||
|
||||
use serde::{Deserialize, Deserializer};
|
||||
|
||||
use crate::core::config::Merge;
|
||||
use crate::core::config::toml::ReplaceOpt;
|
||||
use crate::core::config::{GccCiMode, Merge};
|
||||
use crate::{Config, HashSet, PathBuf, define_config, exit};
|
||||
use crate::{HashSet, PathBuf, define_config, exit};
|
||||
|
||||
define_config! {
|
||||
/// TOML representation of how the GCC build is configured.
|
||||
#[derive(Default)]
|
||||
struct Gcc {
|
||||
download_ci_gcc: Option<bool> = "download-ci-gcc",
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
/// Applies GCC-related configuration from the `TomlGcc` struct to the
|
||||
/// global `Config` structure.
|
||||
pub fn apply_gcc_config(&mut self, toml_gcc: Option<Gcc>) {
|
||||
if let Some(gcc) = toml_gcc {
|
||||
self.gcc_ci_mode = match gcc.download_ci_gcc {
|
||||
Some(value) => match value {
|
||||
true => GccCiMode::DownloadFromCi,
|
||||
false => GccCiMode::BuildLocally,
|
||||
},
|
||||
None => GccCiMode::default(),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,12 +8,13 @@
|
||||
|
||||
use serde::{Deserialize, Deserializer};
|
||||
|
||||
use crate::core::config::Merge;
|
||||
use crate::core::config::toml::ReplaceOpt;
|
||||
use crate::core::config::{Merge, set};
|
||||
use crate::{Config, HashSet, PathBuf, define_config, exit};
|
||||
use crate::{HashSet, PathBuf, define_config, exit};
|
||||
|
||||
define_config! {
|
||||
/// TOML representation of various global install decisions.
|
||||
#[derive(Default)]
|
||||
struct Install {
|
||||
prefix: Option<String> = "prefix",
|
||||
sysconfdir: Option<String> = "sysconfdir",
|
||||
@ -24,20 +25,3 @@ define_config! {
|
||||
datadir: Option<String> = "datadir",
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
/// Applies installation-related configuration from the `Install` struct
|
||||
/// to the global `Config` structure.
|
||||
pub fn apply_install_config(&mut self, toml_install: Option<Install>) {
|
||||
if let Some(install) = toml_install {
|
||||
let Install { prefix, sysconfdir, docdir, bindir, libdir, mandir, datadir } = install;
|
||||
self.prefix = prefix.map(PathBuf::from);
|
||||
self.sysconfdir = sysconfdir.map(PathBuf::from);
|
||||
self.datadir = datadir.map(PathBuf::from);
|
||||
self.docdir = docdir.map(PathBuf::from);
|
||||
set(&mut self.bindir, bindir.map(PathBuf::from));
|
||||
self.libdir = libdir.map(PathBuf::from);
|
||||
self.mandir = mandir.map(PathBuf::from);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,12 +3,13 @@
|
||||
|
||||
use serde::{Deserialize, Deserializer};
|
||||
|
||||
use crate::core::config::StringOrBool;
|
||||
use crate::core::config::toml::{Merge, ReplaceOpt, TomlConfig};
|
||||
use crate::core::config::{StringOrBool, set};
|
||||
use crate::{Config, HashMap, HashSet, PathBuf, define_config, exit};
|
||||
use crate::{HashMap, HashSet, PathBuf, define_config, exit};
|
||||
|
||||
define_config! {
|
||||
/// TOML representation of how the LLVM build is configured.
|
||||
#[derive(Default)]
|
||||
struct Llvm {
|
||||
optimize: Option<bool> = "optimize",
|
||||
thin_lto: Option<bool> = "thin-lto",
|
||||
@ -144,127 +145,3 @@ pub fn check_incompatible_options_for_ci_llvm(
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn apply_llvm_config(&mut self, toml_llvm: Option<Llvm>) {
|
||||
let mut llvm_tests = None;
|
||||
let mut llvm_enzyme = None;
|
||||
let mut llvm_offload = None;
|
||||
let mut llvm_plugins = None;
|
||||
|
||||
if let Some(llvm) = toml_llvm {
|
||||
let Llvm {
|
||||
optimize: optimize_toml,
|
||||
thin_lto,
|
||||
release_debuginfo,
|
||||
assertions: _,
|
||||
tests,
|
||||
enzyme,
|
||||
plugins,
|
||||
static_libstdcpp,
|
||||
libzstd,
|
||||
ninja,
|
||||
targets,
|
||||
experimental_targets,
|
||||
link_jobs,
|
||||
link_shared,
|
||||
version_suffix,
|
||||
clang_cl,
|
||||
cflags,
|
||||
cxxflags,
|
||||
ldflags,
|
||||
use_libcxx,
|
||||
use_linker,
|
||||
allow_old_toolchain,
|
||||
offload,
|
||||
polly,
|
||||
clang,
|
||||
enable_warnings,
|
||||
download_ci_llvm,
|
||||
build_config,
|
||||
} = llvm;
|
||||
|
||||
set(&mut self.ninja_in_file, ninja);
|
||||
llvm_tests = tests;
|
||||
llvm_enzyme = enzyme;
|
||||
llvm_offload = offload;
|
||||
llvm_plugins = plugins;
|
||||
set(&mut self.llvm_optimize, optimize_toml);
|
||||
set(&mut self.llvm_thin_lto, thin_lto);
|
||||
set(&mut self.llvm_release_debuginfo, release_debuginfo);
|
||||
set(&mut self.llvm_static_stdcpp, static_libstdcpp);
|
||||
set(&mut self.llvm_libzstd, libzstd);
|
||||
if let Some(v) = link_shared {
|
||||
self.llvm_link_shared.set(Some(v));
|
||||
}
|
||||
self.llvm_targets.clone_from(&targets);
|
||||
self.llvm_experimental_targets.clone_from(&experimental_targets);
|
||||
self.llvm_link_jobs = link_jobs;
|
||||
self.llvm_version_suffix.clone_from(&version_suffix);
|
||||
self.llvm_clang_cl.clone_from(&clang_cl);
|
||||
|
||||
self.llvm_cflags.clone_from(&cflags);
|
||||
self.llvm_cxxflags.clone_from(&cxxflags);
|
||||
self.llvm_ldflags.clone_from(&ldflags);
|
||||
set(&mut self.llvm_use_libcxx, use_libcxx);
|
||||
self.llvm_use_linker.clone_from(&use_linker);
|
||||
self.llvm_allow_old_toolchain = allow_old_toolchain.unwrap_or(false);
|
||||
self.llvm_offload = offload.unwrap_or(false);
|
||||
self.llvm_polly = polly.unwrap_or(false);
|
||||
self.llvm_clang = clang.unwrap_or(false);
|
||||
self.llvm_enable_warnings = enable_warnings.unwrap_or(false);
|
||||
self.llvm_build_config = build_config.clone().unwrap_or(Default::default());
|
||||
|
||||
self.llvm_from_ci = self.parse_download_ci_llvm(download_ci_llvm, self.llvm_assertions);
|
||||
|
||||
if self.llvm_from_ci {
|
||||
let warn = |option: &str| {
|
||||
println!(
|
||||
"WARNING: `{option}` will only be used on `compiler/rustc_llvm` build, not for the LLVM build."
|
||||
);
|
||||
println!(
|
||||
"HELP: To use `{option}` for LLVM builds, set `download-ci-llvm` option to false."
|
||||
);
|
||||
};
|
||||
|
||||
if static_libstdcpp.is_some() {
|
||||
warn("static-libstdcpp");
|
||||
}
|
||||
|
||||
if link_shared.is_some() {
|
||||
warn("link-shared");
|
||||
}
|
||||
|
||||
// FIXME(#129153): instead of all the ad-hoc `download-ci-llvm` checks that follow,
|
||||
// use the `builder-config` present in tarballs since #128822 to compare the local
|
||||
// config to the ones used to build the LLVM artifacts on CI, and only notify users
|
||||
// if they've chosen a different value.
|
||||
|
||||
if libzstd.is_some() {
|
||||
println!(
|
||||
"WARNING: when using `download-ci-llvm`, the local `llvm.libzstd` option, \
|
||||
like almost all `llvm.*` options, will be ignored and set by the LLVM CI \
|
||||
artifacts builder config."
|
||||
);
|
||||
println!(
|
||||
"HELP: To use `llvm.libzstd` for LLVM/LLD builds, set `download-ci-llvm` option to false."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if !self.llvm_from_ci && self.llvm_thin_lto && link_shared.is_none() {
|
||||
// If we're building with ThinLTO on, by default we want to link
|
||||
// to LLVM shared, to avoid re-doing ThinLTO (which happens in
|
||||
// the link step) with each stage.
|
||||
self.llvm_link_shared.set(Some(true));
|
||||
}
|
||||
} else {
|
||||
self.llvm_from_ci = self.parse_download_ci_llvm(None, false);
|
||||
}
|
||||
|
||||
self.llvm_tests = llvm_tests.unwrap_or(false);
|
||||
self.llvm_enzyme = llvm_enzyme.unwrap_or(false);
|
||||
self.llvm_offload = llvm_offload.unwrap_or(false);
|
||||
self.llvm_plugins = llvm_plugins.unwrap_or(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
//! these raw TOML configurations from various sources (the main `bootstrap.toml`,
|
||||
//! included files, profile defaults, and command-line overrides). This processed
|
||||
//! TOML data then serves as an intermediate representation, which is further
|
||||
//! transformed and applied to the final [`Config`] struct.
|
||||
//! transformed and applied to the final `Config` struct.
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde_derive::Deserialize;
|
||||
|
||||
@ -1,22 +1,16 @@
|
||||
//! This module defines the `Rust` struct, which represents the `[rust]` table
|
||||
//! in the `bootstrap.toml` configuration file.
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
use serde::{Deserialize, Deserializer};
|
||||
|
||||
use crate::core::build_steps::compile::CODEGEN_BACKEND_PREFIX;
|
||||
use crate::core::config::toml::TomlConfig;
|
||||
use crate::core::config::{
|
||||
DebuginfoLevel, Merge, ReplaceOpt, RustcLto, StringOrBool, set, threads_from_config,
|
||||
};
|
||||
use crate::flags::Warnings;
|
||||
use crate::{
|
||||
BTreeSet, CodegenBackendKind, Config, HashSet, PathBuf, TargetSelection, define_config, exit,
|
||||
};
|
||||
use crate::core::config::{DebuginfoLevel, Merge, ReplaceOpt, StringOrBool};
|
||||
use crate::{BTreeSet, CodegenBackendKind, HashSet, PathBuf, TargetSelection, define_config, exit};
|
||||
|
||||
define_config! {
|
||||
/// TOML representation of how the Rust build is configured.
|
||||
#[derive(Default)]
|
||||
struct Rust {
|
||||
optimize: Option<RustOptimize> = "optimize",
|
||||
debug: Option<bool> = "debug",
|
||||
@ -424,7 +418,7 @@ pub(crate) fn parse_codegen_backends(
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
fn default_lld_opt_in_targets() -> Vec<String> {
|
||||
pub fn default_lld_opt_in_targets() -> Vec<String> {
|
||||
vec!["x86_64-unknown-linux-gnu".to_string()]
|
||||
}
|
||||
|
||||
@ -434,7 +428,7 @@ thread_local! {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn default_lld_opt_in_targets() -> Vec<String> {
|
||||
pub fn default_lld_opt_in_targets() -> Vec<String> {
|
||||
TEST_LLD_OPT_IN_TARGETS.with(|cell| cell.borrow().clone()).unwrap_or_default()
|
||||
}
|
||||
|
||||
@ -447,250 +441,3 @@ pub fn with_lld_opt_in_targets<R>(targets: Vec<String>, f: impl FnOnce() -> R) -
|
||||
result
|
||||
})
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn apply_rust_config(&mut self, toml_rust: Option<Rust>, warnings: Warnings) {
|
||||
let mut debug = None;
|
||||
let mut rustc_debug_assertions = None;
|
||||
let mut std_debug_assertions = None;
|
||||
let mut tools_debug_assertions = None;
|
||||
let mut overflow_checks = None;
|
||||
let mut overflow_checks_std = None;
|
||||
let mut debug_logging = None;
|
||||
let mut debuginfo_level = None;
|
||||
let mut debuginfo_level_rustc = None;
|
||||
let mut debuginfo_level_std = None;
|
||||
let mut debuginfo_level_tools = None;
|
||||
let mut debuginfo_level_tests = None;
|
||||
let mut optimize = None;
|
||||
let mut lld_enabled = None;
|
||||
let mut std_features = None;
|
||||
|
||||
if let Some(rust) = toml_rust {
|
||||
let Rust {
|
||||
optimize: optimize_toml,
|
||||
debug: debug_toml,
|
||||
codegen_units,
|
||||
codegen_units_std,
|
||||
rustc_debug_assertions: rustc_debug_assertions_toml,
|
||||
std_debug_assertions: std_debug_assertions_toml,
|
||||
tools_debug_assertions: tools_debug_assertions_toml,
|
||||
overflow_checks: overflow_checks_toml,
|
||||
overflow_checks_std: overflow_checks_std_toml,
|
||||
debug_logging: debug_logging_toml,
|
||||
debuginfo_level: debuginfo_level_toml,
|
||||
debuginfo_level_rustc: debuginfo_level_rustc_toml,
|
||||
debuginfo_level_std: debuginfo_level_std_toml,
|
||||
debuginfo_level_tools: debuginfo_level_tools_toml,
|
||||
debuginfo_level_tests: debuginfo_level_tests_toml,
|
||||
backtrace,
|
||||
incremental,
|
||||
randomize_layout,
|
||||
default_linker,
|
||||
channel: _, // already handled above
|
||||
musl_root,
|
||||
rpath,
|
||||
verbose_tests,
|
||||
optimize_tests,
|
||||
codegen_tests,
|
||||
omit_git_hash: _, // already handled above
|
||||
dist_src,
|
||||
save_toolstates,
|
||||
codegen_backends,
|
||||
lld: lld_enabled_toml,
|
||||
llvm_tools,
|
||||
llvm_bitcode_linker,
|
||||
deny_warnings,
|
||||
backtrace_on_ice,
|
||||
verify_llvm_ir,
|
||||
thin_lto_import_instr_limit,
|
||||
remap_debuginfo,
|
||||
jemalloc,
|
||||
test_compare_mode,
|
||||
llvm_libunwind,
|
||||
control_flow_guard,
|
||||
ehcont_guard,
|
||||
new_symbol_mangling,
|
||||
profile_generate,
|
||||
profile_use,
|
||||
download_rustc,
|
||||
lto,
|
||||
validate_mir_opts,
|
||||
frame_pointers,
|
||||
stack_protector,
|
||||
strip,
|
||||
lld_mode,
|
||||
std_features: std_features_toml,
|
||||
} = rust;
|
||||
|
||||
// FIXME(#133381): alt rustc builds currently do *not* have rustc debug assertions
|
||||
// enabled. We should not download a CI alt rustc if we need rustc to have debug
|
||||
// assertions (e.g. for crashes test suite). This can be changed once something like
|
||||
// [Enable debug assertions on alt
|
||||
// builds](https://github.com/rust-lang/rust/pull/131077) lands.
|
||||
//
|
||||
// Note that `rust.debug = true` currently implies `rust.debug-assertions = true`!
|
||||
//
|
||||
// This relies also on the fact that the global default for `download-rustc` will be
|
||||
// `false` if it's not explicitly set.
|
||||
let debug_assertions_requested = matches!(rustc_debug_assertions_toml, Some(true))
|
||||
|| (matches!(debug_toml, Some(true))
|
||||
&& !matches!(rustc_debug_assertions_toml, Some(false)));
|
||||
|
||||
if debug_assertions_requested
|
||||
&& let Some(ref opt) = download_rustc
|
||||
&& opt.is_string_or_true()
|
||||
{
|
||||
eprintln!(
|
||||
"WARN: currently no CI rustc builds have rustc debug assertions \
|
||||
enabled. Please either set `rust.debug-assertions` to `false` if you \
|
||||
want to use download CI rustc or set `rust.download-rustc` to `false`."
|
||||
);
|
||||
}
|
||||
|
||||
self.download_rustc_commit = self.download_ci_rustc_commit(
|
||||
download_rustc,
|
||||
debug_assertions_requested,
|
||||
self.llvm_assertions,
|
||||
);
|
||||
|
||||
debug = debug_toml;
|
||||
rustc_debug_assertions = rustc_debug_assertions_toml;
|
||||
std_debug_assertions = std_debug_assertions_toml;
|
||||
tools_debug_assertions = tools_debug_assertions_toml;
|
||||
overflow_checks = overflow_checks_toml;
|
||||
overflow_checks_std = overflow_checks_std_toml;
|
||||
debug_logging = debug_logging_toml;
|
||||
debuginfo_level = debuginfo_level_toml;
|
||||
debuginfo_level_rustc = debuginfo_level_rustc_toml;
|
||||
debuginfo_level_std = debuginfo_level_std_toml;
|
||||
debuginfo_level_tools = debuginfo_level_tools_toml;
|
||||
debuginfo_level_tests = debuginfo_level_tests_toml;
|
||||
lld_enabled = lld_enabled_toml;
|
||||
std_features = std_features_toml;
|
||||
|
||||
if optimize_toml.as_ref().is_some_and(|v| matches!(v, RustOptimize::Bool(false))) {
|
||||
eprintln!(
|
||||
"WARNING: setting `optimize` to `false` is known to cause errors and \
|
||||
should be considered unsupported. Refer to `bootstrap.example.toml` \
|
||||
for more details."
|
||||
);
|
||||
}
|
||||
|
||||
optimize = optimize_toml;
|
||||
self.rust_new_symbol_mangling = new_symbol_mangling;
|
||||
set(&mut self.rust_optimize_tests, optimize_tests);
|
||||
set(&mut self.codegen_tests, codegen_tests);
|
||||
set(&mut self.rust_rpath, rpath);
|
||||
set(&mut self.rust_strip, strip);
|
||||
set(&mut self.rust_frame_pointers, frame_pointers);
|
||||
self.rust_stack_protector = stack_protector;
|
||||
set(&mut self.jemalloc, jemalloc);
|
||||
set(&mut self.test_compare_mode, test_compare_mode);
|
||||
set(&mut self.backtrace, backtrace);
|
||||
set(&mut self.rust_dist_src, dist_src);
|
||||
set(&mut self.verbose_tests, verbose_tests);
|
||||
// in the case "false" is set explicitly, do not overwrite the command line args
|
||||
if let Some(true) = incremental {
|
||||
self.incremental = true;
|
||||
}
|
||||
set(&mut self.lld_mode, lld_mode);
|
||||
set(&mut self.llvm_bitcode_linker_enabled, llvm_bitcode_linker);
|
||||
|
||||
self.rust_randomize_layout = randomize_layout.unwrap_or_default();
|
||||
self.llvm_tools_enabled = llvm_tools.unwrap_or(true);
|
||||
|
||||
self.llvm_enzyme = self.channel == "dev" || self.channel == "nightly";
|
||||
self.rustc_default_linker = default_linker;
|
||||
self.musl_root = musl_root.map(PathBuf::from);
|
||||
self.save_toolstates = save_toolstates.map(PathBuf::from);
|
||||
set(
|
||||
&mut self.deny_warnings,
|
||||
match warnings {
|
||||
Warnings::Deny => Some(true),
|
||||
Warnings::Warn => Some(false),
|
||||
Warnings::Default => deny_warnings,
|
||||
},
|
||||
);
|
||||
set(&mut self.backtrace_on_ice, backtrace_on_ice);
|
||||
set(&mut self.rust_verify_llvm_ir, verify_llvm_ir);
|
||||
self.rust_thin_lto_import_instr_limit = thin_lto_import_instr_limit;
|
||||
set(&mut self.rust_remap_debuginfo, remap_debuginfo);
|
||||
set(&mut self.control_flow_guard, control_flow_guard);
|
||||
set(&mut self.ehcont_guard, ehcont_guard);
|
||||
self.llvm_libunwind_default =
|
||||
llvm_libunwind.map(|v| v.parse().expect("failed to parse rust.llvm-libunwind"));
|
||||
set(
|
||||
&mut self.rust_codegen_backends,
|
||||
codegen_backends.map(|backends| parse_codegen_backends(backends, "rust")),
|
||||
);
|
||||
|
||||
self.rust_codegen_units = codegen_units.map(threads_from_config);
|
||||
self.rust_codegen_units_std = codegen_units_std.map(threads_from_config);
|
||||
|
||||
if self.rust_profile_use.is_none() {
|
||||
self.rust_profile_use = profile_use;
|
||||
}
|
||||
|
||||
if self.rust_profile_generate.is_none() {
|
||||
self.rust_profile_generate = profile_generate;
|
||||
}
|
||||
|
||||
self.rust_lto =
|
||||
lto.as_deref().map(|value| RustcLto::from_str(value).unwrap()).unwrap_or_default();
|
||||
self.rust_validate_mir_opts = validate_mir_opts;
|
||||
}
|
||||
|
||||
self.rust_optimize = optimize.unwrap_or(RustOptimize::Bool(true));
|
||||
|
||||
// We make `x86_64-unknown-linux-gnu` use the self-contained linker by default, so we will
|
||||
// build our internal lld and use it as the default linker, by setting the `rust.lld` config
|
||||
// to true by default:
|
||||
// - on the `x86_64-unknown-linux-gnu` target
|
||||
// - when building our in-tree llvm (i.e. the target has not set an `llvm-config`), so that
|
||||
// we're also able to build the corresponding lld
|
||||
// - or when using an external llvm that's downloaded from CI, which also contains our prebuilt
|
||||
// lld
|
||||
// - otherwise, we'd be using an external llvm, and lld would not necessarily available and
|
||||
// thus, disabled
|
||||
// - similarly, lld will not be built nor used by default when explicitly asked not to, e.g.
|
||||
// when the config sets `rust.lld = false`
|
||||
if default_lld_opt_in_targets().contains(&self.host_target.triple.to_string())
|
||||
&& self.hosts == [self.host_target]
|
||||
{
|
||||
let no_llvm_config = self
|
||||
.target_config
|
||||
.get(&self.host_target)
|
||||
.is_none_or(|target_config| target_config.llvm_config.is_none());
|
||||
let enable_lld = self.llvm_from_ci || no_llvm_config;
|
||||
// Prefer the config setting in case an explicit opt-out is needed.
|
||||
self.lld_enabled = lld_enabled.unwrap_or(enable_lld);
|
||||
} else {
|
||||
set(&mut self.lld_enabled, lld_enabled);
|
||||
}
|
||||
|
||||
let default_std_features = BTreeSet::from([String::from("panic-unwind")]);
|
||||
self.rust_std_features = std_features.unwrap_or(default_std_features);
|
||||
|
||||
let default = debug == Some(true);
|
||||
self.rustc_debug_assertions = rustc_debug_assertions.unwrap_or(default);
|
||||
self.std_debug_assertions = std_debug_assertions.unwrap_or(self.rustc_debug_assertions);
|
||||
self.tools_debug_assertions = tools_debug_assertions.unwrap_or(self.rustc_debug_assertions);
|
||||
self.rust_overflow_checks = overflow_checks.unwrap_or(default);
|
||||
self.rust_overflow_checks_std = overflow_checks_std.unwrap_or(self.rust_overflow_checks);
|
||||
|
||||
self.rust_debug_logging = debug_logging.unwrap_or(self.rustc_debug_assertions);
|
||||
|
||||
let with_defaults = |debuginfo_level_specific: Option<_>| {
|
||||
debuginfo_level_specific.or(debuginfo_level).unwrap_or(if debug == Some(true) {
|
||||
DebuginfoLevel::Limited
|
||||
} else {
|
||||
DebuginfoLevel::None
|
||||
})
|
||||
};
|
||||
self.rust_debuginfo_level_rustc = with_defaults(debuginfo_level_rustc);
|
||||
self.rust_debuginfo_level_std = with_defaults(debuginfo_level_std);
|
||||
self.rust_debuginfo_level_tools = with_defaults(debuginfo_level_tools);
|
||||
self.rust_debuginfo_level_tests = debuginfo_level_tests.unwrap_or(DebuginfoLevel::None);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,18 +7,12 @@
|
||||
//! * [`TomlTarget`]: This struct directly mirrors the `[target.<triple>]` sections in your
|
||||
//! `bootstrap.toml`. It's used for deserializing raw TOML data for a specific target.
|
||||
//! * [`Target`]: This struct represents the processed and validated configuration for a
|
||||
//! build target, which is is stored in the main [`Config`] structure.
|
||||
//! * [`Config::apply_target_config`]: This method processes the `TomlTarget` data and
|
||||
//! applies it to the global [`Config`], ensuring proper path resolution, validation,
|
||||
//! and integration with other build settings.
|
||||
|
||||
use std::collections::HashMap;
|
||||
//! build target, which is is stored in the main `Config` structure.
|
||||
|
||||
use serde::{Deserialize, Deserializer};
|
||||
|
||||
use crate::core::config::toml::rust::parse_codegen_backends;
|
||||
use crate::core::config::{LlvmLibunwind, Merge, ReplaceOpt, SplitDebuginfo, StringOrBool};
|
||||
use crate::{CodegenBackendKind, Config, HashSet, PathBuf, TargetSelection, define_config, exit};
|
||||
use crate::{CodegenBackendKind, HashSet, PathBuf, define_config, exit};
|
||||
|
||||
define_config! {
|
||||
/// TOML representation of how each build target is configured.
|
||||
@ -93,68 +87,3 @@ impl Target {
|
||||
target
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn apply_target_config(&mut self, toml_target: Option<HashMap<String, TomlTarget>>) {
|
||||
if let Some(t) = toml_target {
|
||||
for (triple, cfg) in t {
|
||||
let mut target = Target::from_triple(&triple);
|
||||
|
||||
if let Some(ref s) = cfg.llvm_config {
|
||||
if self.download_rustc_commit.is_some() && triple == *self.host_target.triple {
|
||||
panic!(
|
||||
"setting llvm_config for the host is incompatible with download-rustc"
|
||||
);
|
||||
}
|
||||
target.llvm_config = Some(self.src.join(s));
|
||||
}
|
||||
if let Some(patches) = cfg.llvm_has_rust_patches {
|
||||
assert!(
|
||||
self.submodules == Some(false) || cfg.llvm_config.is_some(),
|
||||
"use of `llvm-has-rust-patches` is restricted to cases where either submodules are disabled or llvm-config been provided"
|
||||
);
|
||||
target.llvm_has_rust_patches = Some(patches);
|
||||
}
|
||||
if let Some(ref s) = cfg.llvm_filecheck {
|
||||
target.llvm_filecheck = Some(self.src.join(s));
|
||||
}
|
||||
target.llvm_libunwind = cfg.llvm_libunwind.as_ref().map(|v| {
|
||||
v.parse().unwrap_or_else(|_| {
|
||||
panic!("failed to parse target.{triple}.llvm-libunwind")
|
||||
})
|
||||
});
|
||||
if let Some(s) = cfg.no_std {
|
||||
target.no_std = s;
|
||||
}
|
||||
target.cc = cfg.cc.map(PathBuf::from);
|
||||
target.cxx = cfg.cxx.map(PathBuf::from);
|
||||
target.ar = cfg.ar.map(PathBuf::from);
|
||||
target.ranlib = cfg.ranlib.map(PathBuf::from);
|
||||
target.linker = cfg.linker.map(PathBuf::from);
|
||||
target.crt_static = cfg.crt_static;
|
||||
target.musl_root = cfg.musl_root.map(PathBuf::from);
|
||||
target.musl_libdir = cfg.musl_libdir.map(PathBuf::from);
|
||||
target.wasi_root = cfg.wasi_root.map(PathBuf::from);
|
||||
target.qemu_rootfs = cfg.qemu_rootfs.map(PathBuf::from);
|
||||
target.runner = cfg.runner;
|
||||
target.sanitizers = cfg.sanitizers;
|
||||
target.profiler = cfg.profiler;
|
||||
target.rpath = cfg.rpath;
|
||||
target.optimized_compiler_builtins = cfg.optimized_compiler_builtins;
|
||||
target.jemalloc = cfg.jemalloc;
|
||||
if let Some(backends) = cfg.codegen_backends {
|
||||
target.codegen_backends =
|
||||
Some(parse_codegen_backends(backends, &format!("target.{triple}")))
|
||||
}
|
||||
|
||||
target.split_debuginfo = cfg.split_debuginfo.as_ref().map(|v| {
|
||||
v.parse().unwrap_or_else(|_| {
|
||||
panic!("invalid value for target.{triple}.split-debuginfo")
|
||||
})
|
||||
});
|
||||
|
||||
self.target_config.insert(TargetSelection::from_user(&triple), target);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -517,7 +517,7 @@ impl Build {
|
||||
local_rebuild: config.local_rebuild,
|
||||
fail_fast: config.cmd.fail_fast(),
|
||||
doc_tests: config.cmd.doc_tests(),
|
||||
verbosity: config.verbose,
|
||||
verbosity: config.exec_ctx.verbosity as usize,
|
||||
|
||||
host_target: config.host_target,
|
||||
hosts: config.hosts.clone(),
|
||||
|
||||
@ -550,7 +550,7 @@ impl Default for CommandOutput {
|
||||
#[derive(Clone, Default)]
|
||||
pub struct ExecutionContext {
|
||||
dry_run: DryRun,
|
||||
verbose: u8,
|
||||
pub verbosity: u8,
|
||||
pub fail_fast: bool,
|
||||
delayed_failures: Arc<Mutex<Vec<String>>>,
|
||||
command_cache: Arc<CommandCache>,
|
||||
@ -603,8 +603,8 @@ impl CommandCache {
|
||||
}
|
||||
|
||||
impl ExecutionContext {
|
||||
pub fn new() -> Self {
|
||||
ExecutionContext::default()
|
||||
pub fn new(verbosity: u8, fail_fast: bool) -> Self {
|
||||
Self { verbosity, fail_fast, ..Default::default() }
|
||||
}
|
||||
|
||||
pub fn dry_run(&self) -> bool {
|
||||
@ -629,7 +629,7 @@ impl ExecutionContext {
|
||||
}
|
||||
|
||||
pub fn is_verbose(&self) -> bool {
|
||||
self.verbose > 0
|
||||
self.verbosity > 0
|
||||
}
|
||||
|
||||
pub fn fail_fast(&self) -> bool {
|
||||
@ -640,8 +640,8 @@ impl ExecutionContext {
|
||||
self.dry_run = value;
|
||||
}
|
||||
|
||||
pub fn set_verbose(&mut self, value: u8) {
|
||||
self.verbose = value;
|
||||
pub fn set_verbosity(&mut self, value: u8) {
|
||||
self.verbosity = value;
|
||||
}
|
||||
|
||||
pub fn set_fail_fast(&mut self, value: bool) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user