diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index f35e8ec948bcd..30c7ba0893bd9 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -1771,8 +1771,36 @@ impl Config { std_features: std_features_toml, } = rust; - config.download_rustc_commit = - config.download_ci_rustc_commit(download_rustc, config.llvm_assertions); + // Before something like [Enable debug assertions on alt + // builds](https://github.com/rust-lang/rust/pull/131077) lands, alt rustc builds do + // *not* have rustc debug assertions enabled. We should not download an CI alt rustc if + // we need rustc to have debug assertions (e.g. for crashes test suite). + // + // Note that `rust.debug = true` (currently) implies `rust.debug-assertions = true`! + // + // This relies also on the fact that 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 { + if let Some(ref opt) = download_rustc { + if opt.is_string_or_true() { + panic!( + "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`." + ); + } + } + } + + config.download_rustc_commit = config.download_ci_rustc_commit( + download_rustc, + debug_assertions_requested, + config.llvm_assertions, + ); debug = debug_toml; rustc_debug_assertions = rustc_debug_assertions_toml; @@ -2778,6 +2806,7 @@ impl Config { fn download_ci_rustc_commit( &self, download_rustc: Option, + debug_assertions_requested: bool, llvm_assertions: bool, ) -> Option { if !is_download_ci_available(&self.build.triple, llvm_assertions) { @@ -2786,9 +2815,9 @@ impl Config { // If `download-rustc` is not set, default to rebuilding. let if_unchanged = match download_rustc { - // Globally default for `download-rustc` to `false`, because some contributors don't use + // Globally default `download-rustc` to `false`, because some contributors don't use // profiles for reasons such as: - // - They need to seemlessly switch between compiler/library work. + // - They need to seamlessly switch between compiler/library work. // - They don't want to use compiler profile because they need to override too many // things and it's easier to not use a profile. None | Some(StringOrBool::Bool(false)) => return None, @@ -2849,6 +2878,14 @@ impl Config { return None; } + if debug_assertions_requested { + println!( + "WARN: `rust.debug-assertions = true` will prevent downloading CI rustc as alt CI \ + rustc is not currently built with debug assertions." + ); + return None; + } + Some(commit) } diff --git a/src/bootstrap/src/core/config/tests.rs b/src/bootstrap/src/core/config/tests.rs index 24f932a172432..0db321c4cbe0f 100644 --- a/src/bootstrap/src/core/config/tests.rs +++ b/src/bootstrap/src/core/config/tests.rs @@ -447,3 +447,83 @@ fn check_rustc_if_unchanged_paths() { assert!(config.src.join(p).exists(), "{p} doesn't exist."); } } + +#[test] +#[should_panic] +fn download_rustc_xor_rustc_debug_assertions_both_true() { + parse( + r#" + [rust] + debug-assertions = true + download-rustc = true + "#, + ); +} + +#[test] +#[should_panic] +fn download_rustc_xor_rustc_debug_assertions_debug_download_unchanged() { + parse( + r#" + [rust] + debug-assertions = true + download-rustc = 'if-unchanged' + "#, + ); +} + +#[test] +#[should_panic] +fn download_rustc_xor_rustc_debug_assertions_debug_true() { + parse( + r#" + [rust] + debug = true + download-rustc = true + "#, + ); +} + +#[test] +fn download_rustc_xor_rustc_debug_assertions_only_download_rustc() { + let _ = parse( + r#" + [rust] + download-rustc = true + "#, + ); + + let _ = parse( + r#" + [rust] + download-rustc = 'if-unchanged' + "#, + ); + + // Relies on global default for `download-rustc` to be `false`. + let _ = parse( + r#" + [rust] + debug = true + "#, + ); + + let _ = parse( + r#" + [rust] + debug-assertions = true + "#, + ); +} + +#[test] +fn download_rustc_xor_rustc_debug_assertions_no_debug_assert_ok() { + let _ = parse( + r#" + [rust] + debug = true + debug-assertions = false + download-rustc = true + "#, + ); +} diff --git a/src/bootstrap/src/utils/change_tracker.rs b/src/bootstrap/src/utils/change_tracker.rs index 0d8d633a1b066..1e6fa9604954a 100644 --- a/src/bootstrap/src/utils/change_tracker.rs +++ b/src/bootstrap/src/utils/change_tracker.rs @@ -308,6 +308,6 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[ ChangeInfo { change_id: 133068, severity: ChangeSeverity::Info, - summary: "Reverted `download-rustc` defaults; global default is now `false`, and only use `'if-unchanged'` default for library and tools profile.", + summary: "Reverted `download-rustc` defaults; global default is now `false`, and only use `'if-unchanged'` default for library and tools profile. Also fixed that `rust.debug-assertions = true` is incompatible with `rust.download-rustc = true | 'if-unchanged'`", }, ];