@@ -20,9 +20,7 @@ use toolchain::Tool;
20
20
21
21
use crate :: {
22
22
CargoConfig , CargoFeatures , CargoWorkspace , InvocationStrategy , ManifestPath , Package , Sysroot ,
23
- TargetKind ,
24
- toolchain_info:: { QueryConfig , version} ,
25
- utf8_stdout,
23
+ TargetKind , utf8_stdout,
26
24
} ;
27
25
28
26
/// Output of the build script and proc-macro building steps for a workspace.
@@ -64,6 +62,7 @@ impl WorkspaceBuildScripts {
64
62
workspace : & CargoWorkspace ,
65
63
progress : & dyn Fn ( String ) ,
66
64
sysroot : & Sysroot ,
65
+ toolchain : Option < & semver:: Version > ,
67
66
) -> io:: Result < WorkspaceBuildScripts > {
68
67
let current_dir = workspace. workspace_root ( ) ;
69
68
@@ -74,6 +73,7 @@ impl WorkspaceBuildScripts {
74
73
workspace. manifest_path ( ) ,
75
74
current_dir,
76
75
sysroot,
76
+ toolchain,
77
77
) ?;
78
78
Self :: run_per_ws ( cmd, workspace, progress)
79
79
}
@@ -95,6 +95,7 @@ impl WorkspaceBuildScripts {
95
95
& ManifestPath :: try_from ( working_directory. clone ( ) ) . unwrap ( ) ,
96
96
working_directory,
97
97
& Sysroot :: empty ( ) ,
98
+ None ,
98
99
) ?;
99
100
// NB: Cargo.toml could have been modified between `cargo metadata` and
100
101
// `cargo check`. We shouldn't assume that package ids we see here are
@@ -387,12 +388,13 @@ impl WorkspaceBuildScripts {
387
388
manifest_path : & ManifestPath ,
388
389
current_dir : & AbsPath ,
389
390
sysroot : & Sysroot ,
391
+ toolchain : Option < & semver:: Version > ,
390
392
) -> io:: Result < Command > {
391
- let mut cmd = match config. run_build_script_command . as_deref ( ) {
393
+ match config. run_build_script_command . as_deref ( ) {
392
394
Some ( [ program, args @ ..] ) => {
393
395
let mut cmd = toolchain:: command ( program, current_dir, & config. extra_env ) ;
394
396
cmd. args ( args) ;
395
- cmd
397
+ Ok ( cmd)
396
398
}
397
399
_ => {
398
400
let mut cmd = sysroot. tool ( Tool :: Cargo , current_dir, & config. extra_env ) ;
@@ -444,40 +446,35 @@ impl WorkspaceBuildScripts {
444
446
445
447
cmd. arg ( "--keep-going" ) ;
446
448
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)
448
476
}
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" ) ;
478
477
}
479
-
480
- Ok ( cmd)
481
478
}
482
479
}
483
480
0 commit comments