@@ -20,7 +20,9 @@ use toolchain::Tool;
20
20
21
21
use crate :: {
22
22
CargoConfig , CargoFeatures , CargoWorkspace , InvocationStrategy , ManifestPath , Package , Sysroot ,
23
- TargetKind , utf8_stdout,
23
+ TargetKind ,
24
+ toolchain_info:: { QueryConfig , version} ,
25
+ utf8_stdout,
24
26
} ;
25
27
26
28
/// Output of the build script and proc-macro building steps for a workspace.
@@ -446,10 +448,30 @@ impl WorkspaceBuildScripts {
446
448
}
447
449
} ;
448
450
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 {
450
471
// Setup RUSTC_WRAPPER to point to `rust-analyzer` binary itself. We use
451
472
// that to compile only proc macros and build scripts during the initial
452
473
// `cargo check`.
474
+ // We don't need this if we are using `--compile-time-deps` flag.
453
475
let myself = std:: env:: current_exe ( ) ?;
454
476
cmd. env ( "RUSTC_WRAPPER" , myself) ;
455
477
cmd. env ( "RA_RUSTC_WRAPPER" , "1" ) ;
0 commit comments