Skip to content

Commit ddd2a54

Browse files
committed
move rust config to parse_inner
1 parent 3248ff1 commit ddd2a54

File tree

2 files changed

+251
-261
lines changed

2 files changed

+251
-261
lines changed

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

Lines changed: 247 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use tracing::{instrument, span};
3232
use crate::core::build_steps::llvm;
3333
use crate::core::build_steps::llvm::LLVM_INVALIDATION_PATHS;
3434
pub use crate::core::config::flags::Subcommand;
35-
use crate::core::config::flags::{Color, Flags};
35+
use crate::core::config::flags::{Color, Flags, Warnings};
3636
use crate::core::config::target_selection::TargetSelectionList;
3737
use crate::core::config::toml::TomlConfig;
3838
use crate::core::config::toml::build::{Build, Tool};
@@ -41,7 +41,8 @@ use crate::core::config::toml::dist::Dist;
4141
use crate::core::config::toml::install::Install;
4242
use crate::core::config::toml::llvm::Llvm;
4343
use crate::core::config::toml::rust::{
44-
LldMode, RustOptimize, check_incompatible_options_for_ci_rustc, validate_codegen_backends,
44+
LldMode, Rust, RustOptimize, check_incompatible_options_for_ci_rustc,
45+
default_lld_opt_in_targets, validate_codegen_backends,
4546
};
4647
use crate::core::config::toml::target::Target;
4748
use crate::core::config::{
@@ -1029,7 +1030,250 @@ impl Config {
10291030
config.target_config.insert(TargetSelection::from_user(&triple), target);
10301031
}
10311032
}
1032-
config.apply_rust_config(toml.rust, flags_warnings);
1033+
let mut debug = None;
1034+
let mut rustc_debug_assertions = None;
1035+
let mut std_debug_assertions = None;
1036+
let mut tools_debug_assertions = None;
1037+
let mut overflow_checks = None;
1038+
let mut overflow_checks_std = None;
1039+
let mut debug_logging = None;
1040+
let mut debuginfo_level = None;
1041+
let mut debuginfo_level_rustc = None;
1042+
let mut debuginfo_level_std = None;
1043+
let mut debuginfo_level_tools = None;
1044+
let mut debuginfo_level_tests = None;
1045+
let mut optimize = None;
1046+
let mut lld_enabled = None;
1047+
let mut std_features = None;
1048+
1049+
if let Some(rust) = toml.rust {
1050+
let Rust {
1051+
optimize: optimize_toml,
1052+
debug: debug_toml,
1053+
codegen_units,
1054+
codegen_units_std,
1055+
rustc_debug_assertions: rustc_debug_assertions_toml,
1056+
std_debug_assertions: std_debug_assertions_toml,
1057+
tools_debug_assertions: tools_debug_assertions_toml,
1058+
overflow_checks: overflow_checks_toml,
1059+
overflow_checks_std: overflow_checks_std_toml,
1060+
debug_logging: debug_logging_toml,
1061+
debuginfo_level: debuginfo_level_toml,
1062+
debuginfo_level_rustc: debuginfo_level_rustc_toml,
1063+
debuginfo_level_std: debuginfo_level_std_toml,
1064+
debuginfo_level_tools: debuginfo_level_tools_toml,
1065+
debuginfo_level_tests: debuginfo_level_tests_toml,
1066+
backtrace,
1067+
incremental,
1068+
randomize_layout,
1069+
default_linker,
1070+
channel: _, // already handled above
1071+
musl_root,
1072+
rpath,
1073+
verbose_tests,
1074+
optimize_tests,
1075+
codegen_tests,
1076+
omit_git_hash: _, // already handled above
1077+
dist_src,
1078+
save_toolstates,
1079+
codegen_backends,
1080+
lld: lld_enabled_toml,
1081+
llvm_tools,
1082+
llvm_bitcode_linker,
1083+
deny_warnings,
1084+
backtrace_on_ice,
1085+
verify_llvm_ir,
1086+
thin_lto_import_instr_limit,
1087+
remap_debuginfo,
1088+
jemalloc,
1089+
test_compare_mode,
1090+
llvm_libunwind,
1091+
control_flow_guard,
1092+
ehcont_guard,
1093+
new_symbol_mangling,
1094+
profile_generate,
1095+
profile_use,
1096+
download_rustc,
1097+
lto,
1098+
validate_mir_opts,
1099+
frame_pointers,
1100+
stack_protector,
1101+
strip,
1102+
lld_mode,
1103+
std_features: std_features_toml,
1104+
} = rust;
1105+
1106+
// FIXME(#133381): alt rustc builds currently do *not* have rustc debug assertions
1107+
// enabled. We should not download a CI alt rustc if we need rustc to have debug
1108+
// assertions (e.g. for crashes test suite). This can be changed once something like
1109+
// [Enable debug assertions on alt
1110+
// builds](https://github.com/rust-lang/rust/pull/131077) lands.
1111+
//
1112+
// Note that `rust.debug = true` currently implies `rust.debug-assertions = true`!
1113+
//
1114+
// This relies also on the fact that the global default for `download-rustc` will be
1115+
// `false` if it's not explicitly set.
1116+
let debug_assertions_requested = matches!(rustc_debug_assertions_toml, Some(true))
1117+
|| (matches!(debug_toml, Some(true))
1118+
&& !matches!(rustc_debug_assertions_toml, Some(false)));
1119+
1120+
if debug_assertions_requested
1121+
&& let Some(ref opt) = download_rustc
1122+
&& opt.is_string_or_true()
1123+
{
1124+
eprintln!(
1125+
"WARN: currently no CI rustc builds have rustc debug assertions \
1126+
enabled. Please either set `rust.debug-assertions` to `false` if you \
1127+
want to use download CI rustc or set `rust.download-rustc` to `false`."
1128+
);
1129+
}
1130+
1131+
config.download_rustc_commit = config.download_ci_rustc_commit(
1132+
download_rustc,
1133+
debug_assertions_requested,
1134+
config.llvm_assertions,
1135+
);
1136+
1137+
debug = debug_toml;
1138+
rustc_debug_assertions = rustc_debug_assertions_toml;
1139+
std_debug_assertions = std_debug_assertions_toml;
1140+
tools_debug_assertions = tools_debug_assertions_toml;
1141+
overflow_checks = overflow_checks_toml;
1142+
overflow_checks_std = overflow_checks_std_toml;
1143+
debug_logging = debug_logging_toml;
1144+
debuginfo_level = debuginfo_level_toml;
1145+
debuginfo_level_rustc = debuginfo_level_rustc_toml;
1146+
debuginfo_level_std = debuginfo_level_std_toml;
1147+
debuginfo_level_tools = debuginfo_level_tools_toml;
1148+
debuginfo_level_tests = debuginfo_level_tests_toml;
1149+
lld_enabled = lld_enabled_toml;
1150+
std_features = std_features_toml;
1151+
1152+
if optimize_toml.as_ref().is_some_and(|v| matches!(v, RustOptimize::Bool(false))) {
1153+
eprintln!(
1154+
"WARNING: setting `optimize` to `false` is known to cause errors and \
1155+
should be considered unsupported. Refer to `bootstrap.example.toml` \
1156+
for more details."
1157+
);
1158+
}
1159+
1160+
optimize = optimize_toml;
1161+
config.rust_new_symbol_mangling = new_symbol_mangling;
1162+
set(&mut config.rust_optimize_tests, optimize_tests);
1163+
set(&mut config.codegen_tests, codegen_tests);
1164+
set(&mut config.rust_rpath, rpath);
1165+
set(&mut config.rust_strip, strip);
1166+
set(&mut config.rust_frame_pointers, frame_pointers);
1167+
config.rust_stack_protector = stack_protector;
1168+
set(&mut config.jemalloc, jemalloc);
1169+
set(&mut config.test_compare_mode, test_compare_mode);
1170+
set(&mut config.backtrace, backtrace);
1171+
set(&mut config.rust_dist_src, dist_src);
1172+
set(&mut config.verbose_tests, verbose_tests);
1173+
// in the case "false" is set explicitly, do not overwrite the command line args
1174+
if let Some(true) = incremental {
1175+
config.incremental = true;
1176+
}
1177+
set(&mut config.lld_mode, lld_mode);
1178+
set(&mut config.llvm_bitcode_linker_enabled, llvm_bitcode_linker);
1179+
1180+
config.rust_randomize_layout = randomize_layout.unwrap_or_default();
1181+
config.llvm_tools_enabled = llvm_tools.unwrap_or(true);
1182+
1183+
config.llvm_enzyme = config.channel == "dev" || config.channel == "nightly";
1184+
config.rustc_default_linker = default_linker;
1185+
config.musl_root = musl_root.map(PathBuf::from);
1186+
config.save_toolstates = save_toolstates.map(PathBuf::from);
1187+
set(
1188+
&mut config.deny_warnings,
1189+
match flags_warnings {
1190+
Warnings::Deny => Some(true),
1191+
Warnings::Warn => Some(false),
1192+
Warnings::Default => deny_warnings,
1193+
},
1194+
);
1195+
set(&mut config.backtrace_on_ice, backtrace_on_ice);
1196+
set(&mut config.rust_verify_llvm_ir, verify_llvm_ir);
1197+
config.rust_thin_lto_import_instr_limit = thin_lto_import_instr_limit;
1198+
set(&mut config.rust_remap_debuginfo, remap_debuginfo);
1199+
set(&mut config.control_flow_guard, control_flow_guard);
1200+
set(&mut config.ehcont_guard, ehcont_guard);
1201+
config.llvm_libunwind_default =
1202+
llvm_libunwind.map(|v| v.parse().expect("failed to parse rust.llvm-libunwind"));
1203+
set(
1204+
&mut config.rust_codegen_backends,
1205+
codegen_backends.map(|backends| validate_codegen_backends(backends, "rust")),
1206+
);
1207+
1208+
config.rust_codegen_units = codegen_units.map(threads_from_config);
1209+
config.rust_codegen_units_std = codegen_units_std.map(threads_from_config);
1210+
1211+
if config.rust_profile_use.is_none() {
1212+
config.rust_profile_use = profile_use;
1213+
}
1214+
1215+
if config.rust_profile_generate.is_none() {
1216+
config.rust_profile_generate = profile_generate;
1217+
}
1218+
1219+
config.rust_lto =
1220+
lto.as_deref().map(|value| RustcLto::from_str(value).unwrap()).unwrap_or_default();
1221+
config.rust_validate_mir_opts = validate_mir_opts;
1222+
}
1223+
1224+
config.rust_optimize = optimize.unwrap_or(RustOptimize::Bool(true));
1225+
1226+
// We make `x86_64-unknown-linux-gnu` use the self-contained linker by default, so we will
1227+
// build our internal lld and use it as the default linker, by setting the `rust.lld` config
1228+
// to true by default:
1229+
// - on the `x86_64-unknown-linux-gnu` target
1230+
// - when building our in-tree llvm (i.e. the target has not set an `llvm-config`), so that
1231+
// we're also able to build the corresponding lld
1232+
// - or when using an external llvm that's downloaded from CI, which also contains our prebuilt
1233+
// lld
1234+
// - otherwise, we'd be using an external llvm, and lld would not necessarily available and
1235+
// thus, disabled
1236+
// - similarly, lld will not be built nor used by default when explicitly asked not to, e.g.
1237+
// when the config sets `rust.lld = false`
1238+
if default_lld_opt_in_targets().contains(&config.host_target.triple.to_string())
1239+
&& config.hosts == [config.host_target]
1240+
{
1241+
let no_llvm_config = config
1242+
.target_config
1243+
.get(&config.host_target)
1244+
.is_none_or(|target_config| target_config.llvm_config.is_none());
1245+
let enable_lld = config.llvm_from_ci || no_llvm_config;
1246+
// Prefer the config setting in case an explicit opt-out is needed.
1247+
config.lld_enabled = lld_enabled.unwrap_or(enable_lld);
1248+
} else {
1249+
set(&mut config.lld_enabled, lld_enabled);
1250+
}
1251+
1252+
let default_std_features = BTreeSet::from([String::from("panic-unwind")]);
1253+
config.rust_std_features = std_features.unwrap_or(default_std_features);
1254+
1255+
let default = debug == Some(true);
1256+
config.rustc_debug_assertions = rustc_debug_assertions.unwrap_or(default);
1257+
config.std_debug_assertions = std_debug_assertions.unwrap_or(config.rustc_debug_assertions);
1258+
config.tools_debug_assertions =
1259+
tools_debug_assertions.unwrap_or(config.rustc_debug_assertions);
1260+
config.rust_overflow_checks = overflow_checks.unwrap_or(default);
1261+
config.rust_overflow_checks_std =
1262+
overflow_checks_std.unwrap_or(config.rust_overflow_checks);
1263+
1264+
config.rust_debug_logging = debug_logging.unwrap_or(config.rustc_debug_assertions);
1265+
1266+
let with_defaults = |debuginfo_level_specific: Option<_>| {
1267+
debuginfo_level_specific.or(debuginfo_level).unwrap_or(if debug == Some(true) {
1268+
DebuginfoLevel::Limited
1269+
} else {
1270+
DebuginfoLevel::None
1271+
})
1272+
};
1273+
config.rust_debuginfo_level_rustc = with_defaults(debuginfo_level_rustc);
1274+
config.rust_debuginfo_level_std = with_defaults(debuginfo_level_std);
1275+
config.rust_debuginfo_level_tools = with_defaults(debuginfo_level_tools);
1276+
config.rust_debuginfo_level_tests = debuginfo_level_tests.unwrap_or(DebuginfoLevel::None);
10331277

10341278
config.reproducible_artifacts = flags_reproducible_artifact;
10351279
config.description = description;

0 commit comments

Comments
 (0)