Skip to content

Commit

Permalink
Rollup merge of rust-lang#132772 - onur-ozkan:download-rustc-default,…
Browse files Browse the repository at this point in the history
… r=jieyouxu

use `download-rustc="if-unchanged"` as a global default

If `download-rustc` isn't explicitly set and the source is Git-managed, it should be totally okay to utilize "if-unchanged" behaviour. The "dist" profile already sets `download-rustc` to `false`, so this shouldn’t impact anything on CI.

This also resolves an unhandled case where `bootstrap` unexpectedly panics if `"if-unchanged"` was used with a non-Git source. Now we exits gracefully with an error message pointing the problem.
  • Loading branch information
matthiaskrgr authored Nov 9, 2024
2 parents 88acd49 + 2a38108 commit c435fa8
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 32 deletions.
1 change: 1 addition & 0 deletions src/bootstrap/defaults/config.dist.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extended = true
# Most users installing from source want to build all parts of the project from source.
[llvm]
download-ci-llvm = false

[rust]
# We have several defaults in bootstrap that depend on whether the channel is `dev` (e.g. `omit-git-hash` and `download-ci-llvm`).
# Make sure they don't get set when installing from source.
Expand Down
3 changes: 0 additions & 3 deletions src/bootstrap/defaults/config.library.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ bench-stage = 0
[rust]
# This greatly increases the speed of rebuilds, especially when there are only minor changes. However, it makes the initial build slightly slower.
incremental = true
# Download rustc from CI instead of building it from source.
# For stage > 1 builds, this cuts compile times significantly when there are no changes on "compiler" tree.
download-rustc = "if-unchanged"
# Make the compiler and standard library faster to build, at the expense of a ~20% runtime slowdown.
lto = "off"

Expand Down
5 changes: 0 additions & 5 deletions src/bootstrap/defaults/config.tools.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
[rust]
# This greatly increases the speed of rebuilds, especially when there are only minor changes. However, it makes the initial build slightly slower.
incremental = true
# Download rustc from CI instead of building it from source.
# For stage > 1 builds, this cuts compile times significantly when there are no changes on "compiler" tree.
# Using these defaults will download the stage2 compiler (see `download-rustc`
# setting) and the stage2 toolchain should therefore be used for these defaults.
download-rustc = "if-unchanged"

[build]
# Document with the in-tree rustdoc by default, since `download-rustc` makes it quick to compile.
Expand Down
55 changes: 31 additions & 24 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1665,10 +1665,26 @@ impl Config {
let mut debuginfo_level_tools = None;
let mut debuginfo_level_tests = None;
let mut optimize = None;
let mut omit_git_hash = None;
let mut lld_enabled = None;
let mut std_features = None;

let default = config.channel == "dev";
config.omit_git_hash = toml.rust.as_ref().and_then(|r| r.omit_git_hash).unwrap_or(default);

config.rust_info = GitInfo::new(config.omit_git_hash, &config.src);
config.cargo_info = GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/cargo"));
config.rust_analyzer_info =
GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/rust-analyzer"));
config.clippy_info =
GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/clippy"));
config.miri_info = GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/miri"));
config.rustfmt_info =
GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/rustfmt"));
config.enzyme_info =
GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/enzyme"));
config.in_tree_llvm_info = GitInfo::new(false, &config.src.join("src/llvm-project"));
config.in_tree_gcc_info = GitInfo::new(false, &config.src.join("src/gcc"));

let mut is_user_configured_rust_channel = false;

if let Some(rust) = toml.rust {
Expand Down Expand Up @@ -1699,7 +1715,7 @@ impl Config {
verbose_tests,
optimize_tests,
codegen_tests,
omit_git_hash: omit_git_hash_toml,
omit_git_hash: _, // already handled above
dist_src,
save_toolstates,
codegen_backends,
Expand Down Expand Up @@ -1750,7 +1766,6 @@ impl Config {
std_features = std_features_toml;

optimize = optimize_toml;
omit_git_hash = omit_git_hash_toml;
config.rust_new_symbol_mangling = new_symbol_mangling;
set(&mut config.rust_optimize_tests, optimize_tests);
set(&mut config.codegen_tests, codegen_tests);
Expand Down Expand Up @@ -1826,24 +1841,6 @@ impl Config {

config.reproducible_artifacts = flags.reproducible_artifact;

// rust_info must be set before is_ci_llvm_available() is called.
let default = config.channel == "dev";
config.omit_git_hash = omit_git_hash.unwrap_or(default);
config.rust_info = GitInfo::new(config.omit_git_hash, &config.src);

config.cargo_info = GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/cargo"));
config.rust_analyzer_info =
GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/rust-analyzer"));
config.clippy_info =
GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/clippy"));
config.miri_info = GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/miri"));
config.rustfmt_info =
GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/rustfmt"));
config.enzyme_info =
GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/enzyme"));
config.in_tree_llvm_info = GitInfo::new(false, &config.src.join("src/llvm-project"));
config.in_tree_gcc_info = GitInfo::new(false, &config.src.join("src/gcc"));

// We need to override `rust.channel` if it's manually specified when using the CI rustc.
// This is because if the compiler uses a different channel than the one specified in config.toml,
// tests may fail due to using a different channel than the one used by the compiler during tests.
Expand Down Expand Up @@ -2760,9 +2757,19 @@ impl Config {

// If `download-rustc` is not set, default to rebuilding.
let if_unchanged = match download_rustc {
None | Some(StringOrBool::Bool(false)) => return None,
None => self.rust_info.is_managed_git_subrepository(),
Some(StringOrBool::Bool(false)) => return None,
Some(StringOrBool::Bool(true)) => false,
Some(StringOrBool::String(s)) if s == "if-unchanged" => true,
Some(StringOrBool::String(s)) if s == "if-unchanged" => {
if !self.rust_info.is_managed_git_subrepository() {
println!(
"ERROR: `download-rustc=if-unchanged` is only compatible with Git managed sources."
);
crate::exit!(1);
}

true
}
Some(StringOrBool::String(other)) => {
panic!("unrecognized option for download-rustc: {other}")
}
Expand All @@ -2789,7 +2796,7 @@ impl Config {
}
println!("ERROR: could not find commit hash for downloading rustc");
println!("HELP: maybe your repository history is too shallow?");
println!("HELP: consider disabling `download-rustc`");
println!("HELP: consider setting `rust.download-rustc=false` in config.toml");
println!("HELP: or fetch enough history to include one upstream commit");
crate::exit!(1);
}
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/src/core/config/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ change-id = 0
[rust]
lto = "off"
deny-warnings = true
download-rustc=false
[build]
gdb = "foo"
Expand Down Expand Up @@ -200,6 +201,8 @@ runner = "x86_64-runner"
.collect(),
"setting dictionary value"
);
assert!(!config.llvm_from_ci);
assert!(!config.download_rustc());
}

#[test]
Expand Down

0 comments on commit c435fa8

Please sign in to comment.