Skip to content

Commit 56de211

Browse files
authored
Merge pull request #20047 from ShoyuVanilla/comp-time-deps
internal: Utilize `cargo check --compile-time-deps`
2 parents 19c23ea + 98c92fa commit 56de211

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

crates/project-model/src/build_dependencies.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ use toolchain::Tool;
2020

2121
use crate::{
2222
CargoConfig, CargoFeatures, CargoWorkspace, InvocationStrategy, ManifestPath, Package, Sysroot,
23-
TargetKind, utf8_stdout,
23+
TargetKind,
24+
toolchain_info::{QueryConfig, version},
25+
utf8_stdout,
2426
};
2527

2628
/// Output of the build script and proc-macro building steps for a workspace.
@@ -446,10 +448,30 @@ impl WorkspaceBuildScripts {
446448
}
447449
};
448450

449-
if config.wrap_rustc_in_build_scripts {
451+
// If [`--compile-time-deps` flag](https://github.com/rust-lang/cargo/issues/14434) is
452+
// available in current toolchain's cargo, use it to build compile time deps only.
453+
const COMP_TIME_DEPS_MIN_TOOLCHAIN_VERSION: semver::Version = semver::Version {
454+
major: 1,
455+
minor: 90,
456+
patch: 0,
457+
pre: semver::Prerelease::EMPTY,
458+
build: semver::BuildMetadata::EMPTY,
459+
};
460+
461+
let query_config = QueryConfig::Cargo(sysroot, manifest_path);
462+
let toolchain = version::get(query_config, &config.extra_env).ok().flatten();
463+
let cargo_comp_time_deps_available =
464+
toolchain.is_some_and(|v| v >= COMP_TIME_DEPS_MIN_TOOLCHAIN_VERSION);
465+
466+
if cargo_comp_time_deps_available {
467+
cmd.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly");
468+
cmd.arg("-Zunstable-options");
469+
cmd.arg("--compile-time-deps");
470+
} else if config.wrap_rustc_in_build_scripts {
450471
// Setup RUSTC_WRAPPER to point to `rust-analyzer` binary itself. We use
451472
// that to compile only proc macros and build scripts during the initial
452473
// `cargo check`.
474+
// We don't need this if we are using `--compile-time-deps` flag.
453475
let myself = std::env::current_exe()?;
454476
cmd.env("RUSTC_WRAPPER", myself);
455477
cmd.env("RA_RUSTC_WRAPPER", "1");

0 commit comments

Comments
 (0)