From 87958ad68314daa784e93db4462afc0c079bd3a8 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 11 Jul 2025 13:32:03 +0000 Subject: [PATCH] Avoid building C++ for rustc_llvm with --compile-time-deps This saves about 30s. --- compiler/rustc/Cargo.toml | 1 + compiler/rustc_codegen_llvm/Cargo.toml | 3 +++ compiler/rustc_driver_impl/Cargo.toml | 1 + compiler/rustc_interface/Cargo.toml | 1 + compiler/rustc_llvm/Cargo.toml | 4 ++++ compiler/rustc_llvm/build.rs | 4 ++++ src/bootstrap/src/lib.rs | 3 +++ 7 files changed, 17 insertions(+) diff --git a/compiler/rustc/Cargo.toml b/compiler/rustc/Cargo.toml index f4caa3ef769d..99414d6264e9 100644 --- a/compiler/rustc/Cargo.toml +++ b/compiler/rustc/Cargo.toml @@ -27,6 +27,7 @@ features = ['unprefixed_malloc_on_supported_platforms'] [features] # tidy-alphabetical-start +check_only = ['rustc_driver_impl/check_only'] jemalloc = ['dep:tikv-jemalloc-sys'] llvm = ['rustc_driver_impl/llvm'] max_level_info = ['rustc_driver_impl/max_level_info'] diff --git a/compiler/rustc_codegen_llvm/Cargo.toml b/compiler/rustc_codegen_llvm/Cargo.toml index 88efc8ac96b5..5ab22f8fc4d9 100644 --- a/compiler/rustc_codegen_llvm/Cargo.toml +++ b/compiler/rustc_codegen_llvm/Cargo.toml @@ -43,3 +43,6 @@ serde_json = "1" smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } tracing = "0.1" # tidy-alphabetical-end + +[features] +check_only = ["rustc_llvm/check_only"] diff --git a/compiler/rustc_driver_impl/Cargo.toml b/compiler/rustc_driver_impl/Cargo.toml index 1971d06aad64..ce26aa449d9a 100644 --- a/compiler/rustc_driver_impl/Cargo.toml +++ b/compiler/rustc_driver_impl/Cargo.toml @@ -72,6 +72,7 @@ ctrlc = "3.4.4" [features] # tidy-alphabetical-start +check_only = ['rustc_interface/check_only'] llvm = ['rustc_interface/llvm'] max_level_info = ['rustc_log/max_level_info'] rustc_randomized_layouts = [ diff --git a/compiler/rustc_interface/Cargo.toml b/compiler/rustc_interface/Cargo.toml index a72a79587878..473ac5e0cea4 100644 --- a/compiler/rustc_interface/Cargo.toml +++ b/compiler/rustc_interface/Cargo.toml @@ -56,5 +56,6 @@ rustc_abi = { path = "../rustc_abi" } [features] # tidy-alphabetical-start +check_only = ['rustc_codegen_llvm?/check_only'] llvm = ['dep:rustc_codegen_llvm'] # tidy-alphabetical-end diff --git a/compiler/rustc_llvm/Cargo.toml b/compiler/rustc_llvm/Cargo.toml index 061562b2ec5e..39de4783238b 100644 --- a/compiler/rustc_llvm/Cargo.toml +++ b/compiler/rustc_llvm/Cargo.toml @@ -14,3 +14,7 @@ libc = "0.2.73" # pinned `cc` in `rustc_codegen_ssa` if you update `cc` here. cc = "=1.2.16" # tidy-alphabetical-end + +[features] +# Used by ./x.py check --compile-time-deps to skip building C++ code +check_only = [] diff --git a/compiler/rustc_llvm/build.rs b/compiler/rustc_llvm/build.rs index 9a6549379d39..069b684ad09b 100644 --- a/compiler/rustc_llvm/build.rs +++ b/compiler/rustc_llvm/build.rs @@ -106,6 +106,10 @@ fn output(cmd: &mut Command) -> String { } fn main() { + if cfg!(feature = "check_only") { + return; + } + for component in REQUIRED_COMPONENTS.iter().chain(OPTIONAL_COMPONENTS.iter()) { println!("cargo:rustc-check-cfg=cfg(llvm_component,values(\"{component}\"))"); } diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index d9a4da8f3cc0..bf7369525a45 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -775,6 +775,9 @@ fn rustc_features(&self, kind: Kind, target: TargetSelection, crates: &[String]) if self.config.rust_randomize_layout && check("rustc_randomized_layouts") { features.push("rustc_randomized_layouts"); } + if self.config.compile_time_deps && kind == Kind::Check { + features.push("check_only"); + } // If debug logging is on, then we want the default for tracing: // https://github.com/tokio-rs/tracing/blob/3dd5c03d907afdf2c39444a29931833335171554/tracing/src/level_filters.rs#L26