From 52fcf33ed7de89647329f354cbd0045180a9d367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Thu, 8 May 2025 10:17:21 +0200 Subject: [PATCH 1/4] Remove unused dependency from opt-dist --- src/tools/opt-dist/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tools/opt-dist/Cargo.toml b/src/tools/opt-dist/Cargo.toml index b0db8346f7ed7..279b19d505774 100644 --- a/src/tools/opt-dist/Cargo.toml +++ b/src/tools/opt-dist/Cargo.toml @@ -15,7 +15,6 @@ fs_extra = "1" camino = "1" tar = "0.4" xz = { version = "0.1", package = "xz2" } -serde = { version = "1", features = ["derive"] } serde_json = "1" glob = "0.3" tempfile = "3.5" From 34495f5895e187fe858e5f33c0bb5fe0a4d50efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Thu, 8 May 2025 10:18:17 +0200 Subject: [PATCH 2/4] Migrate `opt-dist` to edition 2024 --- Cargo.lock | 1 - src/tools/opt-dist/Cargo.toml | 2 +- src/tools/opt-dist/src/main.rs | 5 ++++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 83d7a6a9ab134..fa0fa33ea75ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2567,7 +2567,6 @@ dependencies = [ "humansize", "humantime", "log", - "serde", "serde_json", "sysinfo", "tabled", diff --git a/src/tools/opt-dist/Cargo.toml b/src/tools/opt-dist/Cargo.toml index 279b19d505774..dfa884bc3f771 100644 --- a/src/tools/opt-dist/Cargo.toml +++ b/src/tools/opt-dist/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "opt-dist" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] build_helper = { path = "../../build_helper" } diff --git a/src/tools/opt-dist/src/main.rs b/src/tools/opt-dist/src/main.rs index d5e6640fb430a..1bb72431fe6cc 100644 --- a/src/tools/opt-dist/src/main.rs +++ b/src/tools/opt-dist/src/main.rs @@ -361,7 +361,10 @@ fn execute_pipeline( fn main() -> anyhow::Result<()> { // Make sure that we get backtraces for easier debugging in CI - std::env::set_var("RUST_BACKTRACE", "1"); + unsafe { + // SAFETY: we are the only thread running at this point + std::env::set_var("RUST_BACKTRACE", "1"); + } env_logger::builder() .filter_level(LevelFilter::Info) From 082777e088a02c81f8e50853ec28a8bb53d762ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Thu, 8 May 2025 10:19:30 +0200 Subject: [PATCH 3/4] Do not deny warnings for fast try builds --- src/tools/opt-dist/src/environment.rs | 5 +++++ src/tools/opt-dist/src/exec.rs | 11 +++++++++-- src/tools/opt-dist/src/main.rs | 21 +++++++++++++-------- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/tools/opt-dist/src/environment.rs b/src/tools/opt-dist/src/environment.rs index 9342d164be411..946e926a3c010 100644 --- a/src/tools/opt-dist/src/environment.rs +++ b/src/tools/opt-dist/src/environment.rs @@ -26,6 +26,7 @@ pub struct Environment { use_bolt: bool, shared_llvm: bool, run_tests: bool, + fast_try_build: bool, } impl Environment { @@ -106,6 +107,10 @@ impl Environment { pub fn run_tests(&self) -> bool { self.run_tests } + + pub fn is_fast_try_build(&self) -> bool { + self.fast_try_build + } } /// What is the extension of binary executables on this platform? diff --git a/src/tools/opt-dist/src/exec.rs b/src/tools/opt-dist/src/exec.rs index deff69a7f9c00..64ce5cc377522 100644 --- a/src/tools/opt-dist/src/exec.rs +++ b/src/tools/opt-dist/src/exec.rs @@ -113,13 +113,16 @@ impl Bootstrap { "library/std", ]) .env("RUST_BACKTRACE", "full"); + let cmd = add_shared_x_flags(env, cmd); + Self { cmd, metrics_path } } pub fn dist(env: &Environment, dist_args: &[String]) -> Self { let metrics_path = env.build_root().join("build").join("metrics.json"); - let cmd = cmd(&dist_args.iter().map(|arg| arg.as_str()).collect::>()) - .env("RUST_BACKTRACE", "full"); + let args = dist_args.iter().map(|arg| arg.as_str()).collect::>(); + let cmd = cmd(&args).env("RUST_BACKTRACE", "full"); + let cmd = add_shared_x_flags(env, cmd); Self { cmd, metrics_path } } @@ -184,3 +187,7 @@ impl Bootstrap { Ok(()) } } + +fn add_shared_x_flags(env: &Environment, cmd: CmdBuilder) -> CmdBuilder { + if env.is_fast_try_build() { cmd.arg("--set").arg("rust.deny-warnings=false") } else { cmd } +} diff --git a/src/tools/opt-dist/src/main.rs b/src/tools/opt-dist/src/main.rs index 1bb72431fe6cc..d2827ec01ca7d 100644 --- a/src/tools/opt-dist/src/main.rs +++ b/src/tools/opt-dist/src/main.rs @@ -95,7 +95,7 @@ enum EnvironmentCmd { #[arg(long)] benchmark_cargo_config: Vec, - /// Perform tests after final build if it's not a try build + /// Perform tests after final build if it's not a fast try build #[arg(long)] run_tests: bool, }, @@ -111,11 +111,14 @@ enum EnvironmentCmd { }, } -fn is_try_build() -> bool { +/// For a fast try build, we want to only build the bare minimum of components to get a +/// working toolchain, and not run any tests. +fn is_fast_try_build() -> bool { std::env::var("DIST_TRY_BUILD").unwrap_or_else(|_| "0".to_string()) != "0" } fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec)> { + let is_fast_try_build = is_fast_try_build(); let (env, args) = match args.env { EnvironmentCmd::Local { target_triple, @@ -144,6 +147,7 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec)> .skipped_tests(skipped_tests) .benchmark_cargo_config(benchmark_cargo_config) .run_tests(run_tests) + .fast_try_build(is_fast_try_build) .build()?; (env, shared.build_args) @@ -167,6 +171,7 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec)> .use_bolt(!is_aarch64) .skipped_tests(vec![]) .run_tests(true) + .fast_try_build(is_fast_try_build) .build()?; (env, shared.build_args) @@ -187,6 +192,7 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec)> .use_bolt(false) .skipped_tests(vec![]) .run_tests(true) + .fast_try_build(is_fast_try_build) .build()?; (env, shared.build_args) @@ -350,9 +356,8 @@ fn execute_pipeline( // After dist has finished, run a subset of the test suite on the optimized artifacts to discover // possible regressions. - // The tests are not executed for try builds, which can be in various broken states, so we don't - // want to gatekeep them with tests. - if !is_try_build() && env.run_tests() { + // The tests are not executed for fast try builds, which can be broken and might not pass them. + if !is_fast_try_build() && env.run_tests() { timer.section("Run tests", |_| run_tests(env))?; } @@ -396,9 +401,9 @@ fn main() -> anyhow::Result<()> { let (env, mut build_args) = create_environment(args).context("Cannot create environment")?; - // Skip components that are not needed for try builds to speed them up - if is_try_build() { - log::info!("Skipping building of unimportant components for a try build"); + // Skip components that are not needed for fast try builds to speed them up + if is_fast_try_build() { + log::info!("Skipping building of unimportant components for a fast try build"); for target in [ "rust-docs", "rustc-docs", From 4f9bb8c7353892b057ffbe382d680846ff2c01ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Thu, 8 May 2025 16:00:48 +0200 Subject: [PATCH 4/4] Mention fast try builds in the rustc-dev-guide --- src/doc/rustc-dev-guide/src/tests/ci.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/doc/rustc-dev-guide/src/tests/ci.md b/src/doc/rustc-dev-guide/src/tests/ci.md index c04f296ba0b14..825be11c82a97 100644 --- a/src/doc/rustc-dev-guide/src/tests/ci.md +++ b/src/doc/rustc-dev-guide/src/tests/ci.md @@ -135,12 +135,16 @@ There are several use-cases for try builds: - Run a specific CI job (e.g. Windows tests) on a PR, to quickly test if it passes the test suite executed by that job. -You can select which CI jobs will -be executed in the try build by adding lines containing `try-job: -` to the PR description. All such specified jobs will be executed -in the try build once the `@bors try` command is used on the PR. If no try -jobs are specified in this way, the jobs defined in the `try` section of -[`jobs.yml`] will be executed by default. +By default, if you send a comment with `@bors try`, the jobs defined in the `try` section of +[`jobs.yml`] will be executed. We call this mode a "fast try build". Such a try build +will not execute any tests, and it will allow compilation warnings. It is useful when you want to +get an optimized toolchain as fast as possible, for a crater run or performance benchmarks, +even if it might not be working fully correctly. + +If you want to run a custom CI job in a try build and make sure that it passes all tests and does +not produce any compilation warnings, you can select CI jobs to be executed by adding lines +containing `try-job: ` to the PR description. All such specified jobs will be executed +in the try build once the `@bors try` command is used on the PR. Each pattern can either be an exact name of a job or a glob pattern that matches multiple jobs, for example `*msvc*` or `*-alt`. You can start at most 20 jobs in a single try build. When using