@@ -20,9 +20,7 @@ use toolchain::Tool;
2020
2121use crate :: {
2222 CargoConfig , CargoFeatures , CargoWorkspace , InvocationStrategy , ManifestPath , Package , Sysroot ,
23- TargetKind ,
24- toolchain_info:: { QueryConfig , version} ,
25- utf8_stdout,
23+ TargetKind , utf8_stdout,
2624} ;
2725
2826/// Output of the build script and proc-macro building steps for a workspace.
@@ -64,6 +62,7 @@ impl WorkspaceBuildScripts {
6462 workspace : & CargoWorkspace ,
6563 progress : & dyn Fn ( String ) ,
6664 sysroot : & Sysroot ,
65+ toolchain : Option < & semver:: Version > ,
6766 ) -> io:: Result < WorkspaceBuildScripts > {
6867 let current_dir = workspace. workspace_root ( ) ;
6968
@@ -74,6 +73,7 @@ impl WorkspaceBuildScripts {
7473 workspace. manifest_path ( ) ,
7574 current_dir,
7675 sysroot,
76+ toolchain,
7777 ) ?;
7878 Self :: run_per_ws ( cmd, workspace, progress)
7979 }
@@ -95,6 +95,7 @@ impl WorkspaceBuildScripts {
9595 & ManifestPath :: try_from ( working_directory. clone ( ) ) . unwrap ( ) ,
9696 working_directory,
9797 & Sysroot :: empty ( ) ,
98+ None ,
9899 ) ?;
99100 // NB: Cargo.toml could have been modified between `cargo metadata` and
100101 // `cargo check`. We shouldn't assume that package ids we see here are
@@ -387,12 +388,13 @@ impl WorkspaceBuildScripts {
387388 manifest_path : & ManifestPath ,
388389 current_dir : & AbsPath ,
389390 sysroot : & Sysroot ,
391+ toolchain : Option < & semver:: Version > ,
390392 ) -> io:: Result < Command > {
391- let mut cmd = match config. run_build_script_command . as_deref ( ) {
393+ match config. run_build_script_command . as_deref ( ) {
392394 Some ( [ program, args @ ..] ) => {
393395 let mut cmd = toolchain:: command ( program, current_dir, & config. extra_env ) ;
394396 cmd. args ( args) ;
395- cmd
397+ Ok ( cmd)
396398 }
397399 _ => {
398400 let mut cmd = sysroot. tool ( Tool :: Cargo , current_dir, & config. extra_env ) ;
@@ -444,40 +446,35 @@ impl WorkspaceBuildScripts {
444446
445447 cmd. arg ( "--keep-going" ) ;
446448
447- cmd
449+ // If [`--compile-time-deps` flag](https://github.com/rust-lang/cargo/issues/14434) is
450+ // available in current toolchain's cargo, use it to build compile time deps only.
451+ const COMP_TIME_DEPS_MIN_TOOLCHAIN_VERSION : semver:: Version = semver:: Version {
452+ major : 1 ,
453+ minor : 89 ,
454+ patch : 0 ,
455+ pre : semver:: Prerelease :: EMPTY ,
456+ build : semver:: BuildMetadata :: EMPTY ,
457+ } ;
458+
459+ let cargo_comp_time_deps_available =
460+ toolchain. is_some_and ( |v| * v >= COMP_TIME_DEPS_MIN_TOOLCHAIN_VERSION ) ;
461+
462+ if cargo_comp_time_deps_available {
463+ cmd. env ( "__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS" , "nightly" ) ;
464+ cmd. arg ( "-Zunstable-options" ) ;
465+ cmd. arg ( "--compile-time-deps" ) ;
466+ } else if config. wrap_rustc_in_build_scripts {
467+ // Setup RUSTC_WRAPPER to point to `rust-analyzer` binary itself. We use
468+ // that to compile only proc macros and build scripts during the initial
469+ // `cargo check`.
470+ // We don't need this if we are using `--compile-time-deps` flag.
471+ let myself = std:: env:: current_exe ( ) ?;
472+ cmd. env ( "RUSTC_WRAPPER" , myself) ;
473+ cmd. env ( "RA_RUSTC_WRAPPER" , "1" ) ;
474+ }
475+ Ok ( cmd)
448476 }
449- } ;
450-
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 : 89 ,
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 {
471- // Setup RUSTC_WRAPPER to point to `rust-analyzer` binary itself. We use
472- // that to compile only proc macros and build scripts during the initial
473- // `cargo check`.
474- // We don't need this if we are using `--compile-time-deps` flag.
475- let myself = std:: env:: current_exe ( ) ?;
476- cmd. env ( "RUSTC_WRAPPER" , myself) ;
477- cmd. env ( "RA_RUSTC_WRAPPER" , "1" ) ;
478477 }
479-
480- Ok ( cmd)
481478 }
482479}
483480
0 commit comments