@@ -20,7 +20,9 @@ use toolchain::Tool;
2020
2121use 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