Skip to content

Commit dc7dab3

Browse files
committed
Add --compile-time-deps argument for x check
This reduces the amount of time it takes to do the x check for rust-analyzer analysis from 12m16s to 3m34s when the bootstrap compiler is already downloaded.
1 parent 2a023bf commit dc7dab3

File tree

8 files changed

+36
-3
lines changed

8 files changed

+36
-3
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ impl Step for Std {
4747
}
4848

4949
fn make_run(run: RunConfig<'_>) {
50+
if run.builder.config.compile_time_deps {
51+
// libstd doesn't have any important build scripts and can't have any proc macros
52+
return;
53+
}
54+
5055
let crates = std_crates_for_run_make(&run);
5156
run.builder.ensure(Std {
5257
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/compile.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2542,6 +2542,11 @@ pub fn stream_cargo(
25422542
}
25432543
cmd.arg("--message-format").arg(message_format);
25442544

2545+
if builder.config.compile_time_deps {
2546+
cmd.arg("-Zunstable-options");
2547+
cmd.arg("--compile-time-deps");
2548+
}
2549+
25452550
for arg in tail_args {
25462551
cmd.arg(arg);
25472552
}

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 {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ pub struct Flags {
132132
#[arg(global = true, long)]
133133
/// use message-format=json
134134
pub json_output: bool,
135+
#[arg(global = true, long)]
136+
/// use --compile-time-deps
137+
pub compile_time_deps: bool,
135138

136139
#[arg(global = true, long, value_name = "STYLE")]
137140
#[arg(value_enum, default_value_t = Color::Auto)]

src/etc/rust_analyzer_eglot.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
:overrideCommand ["python3"
2424
"x.py"
2525
"check"
26-
"--json-output"])
26+
"--json-output"
27+
"--compile-time-deps"])]
2728
:sysrootSrc "./library"
2829
:extraEnv (:RUSTC_BOOTSTRAP "1"))
2930
:rustc ( :source "./Cargo.toml" )))))))

src/etc/rust_analyzer_helix.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,5 @@ overrideCommand = [
5959
"--json-output",
6060
"--build-dir",
6161
"build/rust-analyzer",
62+
"--compile-time-deps"
6263
]

src/etc/rust_analyzer_settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"python3",
2828
"x.py",
2929
"check",
30-
"--json-output"
30+
"--json-output",
31+
"--compile-time-deps"
3132
],
3233
"rust-analyzer.cargo.sysrootSrc": "./library",
3334
"rust-analyzer.rustc.source": "./Cargo.toml",

src/etc/rust_analyzer_zed.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"enable": true,
88
"invocationLocation": "root",
99
"invocationStrategy": "once",
10-
"overrideCommand": ["python3", "x.py", "check", "--json-output"]
10+
"overrideCommand": ["python3", "x.py", "check", "--json-output", "--compile-time-deps"]
1111
},
1212
"extraEnv": {
1313
"RUSTC_BOOTSTRAP": "1"

0 commit comments

Comments
 (0)