Skip to content

Commit

Permalink
Skip downloading CI rustc if rust.debug-assertions = true
Browse files Browse the repository at this point in the history
Warn if `download-rustc` used with `rust.debug-assertions` as alt rustc
builds currently do not have rustc debug assertions enabled.
  • Loading branch information
jieyouxu committed Nov 21, 2024
1 parent da09d24 commit 794aaa4
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 5 deletions.
45 changes: 41 additions & 4 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2778,6 +2806,7 @@ impl Config {
fn download_ci_rustc_commit(
&self,
download_rustc: Option<StringOrBool>,
debug_assertions_requested: bool,
llvm_assertions: bool,
) -> Option<String> {
if !is_download_ci_available(&self.build.triple, llvm_assertions) {
Expand All @@ -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,
Expand Down Expand Up @@ -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)
}

Expand Down
80 changes: 80 additions & 0 deletions src/bootstrap/src/core/config/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
"#,
);
}
2 changes: 1 addition & 1 deletion src/bootstrap/src/utils/change_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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'`",
},
];

0 comments on commit 794aaa4

Please sign in to comment.