Skip to content

Commit c2e70f0

Browse files
authored
Unrolled build for #143785
Rollup merge of #143785 - bjorn3:faster_ra_build_script_build, r=Kobzol Add --compile-time-deps argument for x check Together with skipping building C++ code in rustc_llvm for check, this reduces the amount of time it takes to do the x check for rust-analyzer analysis from 12m16s to 3m06s when the bootstrap compiler is already downloaded.
2 parents 7e310f4 + 10bec8f commit c2e70f0

File tree

25 files changed

+249
-51
lines changed

25 files changed

+249
-51
lines changed

compiler/rustc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ features = ['unprefixed_malloc_on_supported_platforms']
2727

2828
[features]
2929
# tidy-alphabetical-start
30+
check_only = ['rustc_driver_impl/check_only']
3031
jemalloc = ['dep:tikv-jemalloc-sys']
3132
llvm = ['rustc_driver_impl/llvm']
3233
max_level_info = ['rustc_driver_impl/max_level_info']

compiler/rustc_codegen_llvm/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ serde_json = "1"
4343
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
4444
tracing = "0.1"
4545
# tidy-alphabetical-end
46+
47+
[features]
48+
check_only = ["rustc_llvm/check_only"]

compiler/rustc_driver_impl/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ ctrlc = "3.4.4"
7272

7373
[features]
7474
# tidy-alphabetical-start
75+
check_only = ['rustc_interface/check_only']
7576
llvm = ['rustc_interface/llvm']
7677
max_level_info = ['rustc_log/max_level_info']
7778
rustc_randomized_layouts = [

compiler/rustc_interface/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@ rustc_abi = { path = "../rustc_abi" }
5656

5757
[features]
5858
# tidy-alphabetical-start
59+
check_only = ['rustc_codegen_llvm?/check_only']
5960
llvm = ['dep:rustc_codegen_llvm']
6061
# tidy-alphabetical-end

compiler/rustc_llvm/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ libc = "0.2.73"
1414
# pinned `cc` in `rustc_codegen_ssa` if you update `cc` here.
1515
cc = "=1.2.16"
1616
# tidy-alphabetical-end
17+
18+
[features]
19+
# Used by ./x.py check --compile-time-deps to skip building C++ code
20+
check_only = []

compiler/rustc_llvm/build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ fn output(cmd: &mut Command) -> String {
106106
}
107107

108108
fn main() {
109+
if cfg!(feature = "check_only") {
110+
return;
111+
}
112+
109113
for component in REQUIRED_COMPONENTS.iter().chain(OPTIONAL_COMPONENTS.iter()) {
110114
println!("cargo:rustc-check-cfg=cfg(llvm_component,values(\"{component}\"))");
111115
}

src/bootstrap/src/core/build_steps/check.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ impl Step for Std {
5454
return;
5555
}
5656

57+
if run.builder.config.compile_time_deps {
58+
// libstd doesn't have any important build scripts and can't have any proc macros
59+
return;
60+
}
61+
5762
let crates = std_crates_for_run_make(&run);
5863
run.builder.ensure(Std {
5964
build_compiler: prepare_compiler_for_check(run.builder, run.target, Mode::Std),
@@ -250,6 +255,13 @@ fn prepare_compiler_for_check(
250255
match mode {
251256
Mode::ToolBootstrap => builder.compiler(0, host),
252257
Mode::ToolStd => {
258+
if builder.config.compile_time_deps {
259+
// When --compile-time-deps is passed, we can't use any rustc
260+
// other than the bootstrap compiler. Luckily build scripts and
261+
// proc macros for tools are unlikely to need nightly.
262+
return builder.compiler(0, host);
263+
}
264+
253265
// These tools require the local standard library to be checked
254266
let build_compiler = builder.compiler(builder.top_stage, host);
255267

src/bootstrap/src/core/build_steps/setup.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,12 +586,14 @@ Select which editor you would like to set up [default: None]: ";
586586
"b5dd299b93dca3ceeb9b335f929293cb3d4bf4977866fbe7ceeac2a8a9f99088",
587587
"631c837b0e98ae35fd48b0e5f743b1ca60adadf2d0a2b23566ba25df372cf1a9",
588588
"080955765db84bb6cbf178879f489c4e2369397626a6ecb3debedb94a9d0b3ce",
589+
"f501475c6654187091c924ae26187fa5791d74d4a8ab3fb61fbbe4c0275aade1",
589590
],
590591
EditorKind::Helix => &[
591592
"2d3069b8cf1b977e5d4023965eb6199597755e6c96c185ed5f2854f98b83d233",
592593
"6736d61409fbebba0933afd2e4c44ff2f97c1cb36cf0299a7f4a7819b8775040",
593594
"f252dcc30ca85a193a699581e5e929d5bd6c19d40d7a7ade5e257a9517a124a5",
594595
"198c195ed0c070d15907b279b8b4ea96198ca71b939f5376454f3d636ab54da5",
596+
"1c43ead340b20792b91d02b08494ee68708e7e09f56b6766629b4b72079208f1",
595597
],
596598
EditorKind::Vim | EditorKind::VsCode => &[
597599
"ea67e259dedf60d4429b6c349a564ffcd1563cf41c920a856d1f5b16b4701ac8",
@@ -607,12 +609,14 @@ Select which editor you would like to set up [default: None]: ";
607609
"e53e9129ca5ee5dcbd6ec8b68c2d87376474eb154992deba3c6d9ab1703e0717",
608610
"f954316090936c7e590c253ca9d524008375882fa13c5b41d7e2547a896ff893",
609611
"701b73751efd7abd6487f2c79348dab698af7ac4427b79fa3d2087c867144b12",
612+
"a61df796c0c007cb6512127330564e49e57d558dec715703916a928b072a1054",
610613
],
611614
EditorKind::Zed => &[
612615
"bbce727c269d1bd0c98afef4d612eb4ce27aea3c3a8968c5f10b31affbc40b6c",
613616
"a5380cf5dd9328731aecc5dfb240d16dac46ed272126b9728006151ef42f5909",
614617
"2e96bf0d443852b12f016c8fc9840ab3d0a2b4fe0b0fb3a157e8d74d5e7e0e26",
615618
"4fadd4c87389a601a27db0d3d74a142fa3a2e656ae78982e934dbe24bee32ad6",
619+
"f0bb3d23ab1a49175ab0ef5c4071af95bb03d01d460776cdb716d91333443382",
616620
],
617621
}
618622
}

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,12 @@ impl Builder<'_> {
747747
// Make cargo emit diagnostics relative to the rustc src dir.
748748
cargo.arg(format!("-Zroot-dir={}", self.src.display()));
749749

750+
if self.config.compile_time_deps {
751+
// Build only build scripts and proc-macros for rust-analyzer when requested.
752+
cargo.arg("-Zunstable-options");
753+
cargo.arg("--compile-time-deps");
754+
}
755+
750756
// FIXME: Temporary fix for https://github.com/rust-lang/cargo/issues/3005
751757
// Force cargo to output binaries with disambiguating hashes in the name
752758
let mut metadata = if compiler.stage == 0 {

src/bootstrap/src/core/config/config.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ pub struct Config {
110110
pub include_default_paths: bool,
111111
pub rustc_error_format: Option<String>,
112112
pub json_output: bool,
113+
pub compile_time_deps: bool,
113114
pub test_compare_mode: bool,
114115
pub color: Color,
115116
pub patch_binaries_for_nix: Option<bool>,
@@ -421,6 +422,7 @@ impl Config {
421422
jobs: flags_jobs,
422423
warnings: flags_warnings,
423424
json_output: flags_json_output,
425+
compile_time_deps: flags_compile_time_deps,
424426
color: flags_color,
425427
bypass_bootstrap_lock: flags_bypass_bootstrap_lock,
426428
rust_profile_generate: flags_rust_profile_generate,
@@ -468,6 +470,7 @@ impl Config {
468470
config.include_default_paths = flags_include_default_paths;
469471
config.rustc_error_format = flags_rustc_error_format;
470472
config.json_output = flags_json_output;
473+
config.compile_time_deps = flags_compile_time_deps;
471474
config.on_fail = flags_on_fail;
472475
config.cmd = flags_cmd;
473476
config.incremental = flags_incremental;
@@ -1064,6 +1067,13 @@ impl Config {
10641067
_ => {}
10651068
}
10661069

1070+
if config.compile_time_deps && !matches!(config.cmd, Subcommand::Check { .. }) {
1071+
eprintln!(
1072+
"WARNING: Can't use --compile-time-deps with any subcommand other than check."
1073+
);
1074+
exit!(1);
1075+
}
1076+
10671077
// CI should always run stage 2 builds, unless it specifically states otherwise
10681078
#[cfg(not(test))]
10691079
if flags_stage.is_none() && config.is_running_on_ci {

0 commit comments

Comments
 (0)