@@ -16,12 +16,13 @@ use la_arena::ArenaMap;
16
16
use paths:: { AbsPath , AbsPathBuf , Utf8PathBuf } ;
17
17
use rustc_hash:: { FxHashMap , FxHashSet } ;
18
18
use serde:: Deserialize as _;
19
- use stdx:: { always , never} ;
19
+ use stdx:: never;
20
20
use toolchain:: Tool ;
21
21
22
22
use crate :: {
23
23
CargoConfig , CargoFeatures , CargoWorkspace , InvocationStrategy , ManifestPath , Package , Sysroot ,
24
- TargetKind , utf8_stdout,
24
+ TargetKind , cargo_config_file:: make_lockfile_copy,
25
+ cargo_workspace:: MINIMUM_TOOLCHAIN_VERSION_SUPPORTING_LOCKFILE_PATH , utf8_stdout,
25
26
} ;
26
27
27
28
/// Output of the build script and proc-macro building steps for a workspace.
@@ -77,7 +78,7 @@ impl WorkspaceBuildScripts {
77
78
let current_dir = workspace. workspace_root ( ) ;
78
79
79
80
let allowed_features = workspace. workspace_features ( ) ;
80
- let cmd = Self :: build_command (
81
+ let ( _guard , cmd) = Self :: build_command (
81
82
config,
82
83
& allowed_features,
83
84
workspace. manifest_path ( ) ,
@@ -98,7 +99,7 @@ impl WorkspaceBuildScripts {
98
99
) -> io:: Result < Vec < WorkspaceBuildScripts > > {
99
100
assert_eq ! ( config. invocation_strategy, InvocationStrategy :: Once ) ;
100
101
101
- let cmd = Self :: build_command (
102
+ let ( _guard , cmd) = Self :: build_command (
102
103
config,
103
104
& Default :: default ( ) ,
104
105
// This is not gonna be used anyways, so just construct a dummy here
@@ -379,10 +380,6 @@ impl WorkspaceBuildScripts {
379
380
progress ( format ! (
380
381
"building compile-time-deps: proc-macro {name} built"
381
382
) ) ;
382
- always ! (
383
- data. proc_macro_dylib_path == ProcMacroDylibPath :: NotBuilt ,
384
- "received multiple compiler artifacts for the same package: {message:?}"
385
- ) ;
386
383
if data. proc_macro_dylib_path == ProcMacroDylibPath :: NotBuilt {
387
384
data. proc_macro_dylib_path = ProcMacroDylibPath :: NotProcMacro ;
388
385
}
@@ -434,14 +431,15 @@ impl WorkspaceBuildScripts {
434
431
current_dir : & AbsPath ,
435
432
sysroot : & Sysroot ,
436
433
toolchain : Option < & semver:: Version > ,
437
- ) -> io:: Result < Command > {
434
+ ) -> io:: Result < ( Option < temp_dir :: TempDir > , Command ) > {
438
435
match config. run_build_script_command . as_deref ( ) {
439
436
Some ( [ program, args @ ..] ) => {
440
437
let mut cmd = toolchain:: command ( program, current_dir, & config. extra_env ) ;
441
438
cmd. args ( args) ;
442
- Ok ( cmd)
439
+ Ok ( ( None , cmd) )
443
440
}
444
441
_ => {
442
+ let mut requires_unstable_options = false ;
445
443
let mut cmd = sysroot. tool ( Tool :: Cargo , current_dir, & config. extra_env ) ;
446
444
447
445
cmd. args ( [ "check" , "--quiet" , "--workspace" , "--message-format=json" ] ) ;
@@ -457,7 +455,19 @@ impl WorkspaceBuildScripts {
457
455
if let Some ( target) = & config. target {
458
456
cmd. args ( [ "--target" , target] ) ;
459
457
}
460
-
458
+ let mut temp_dir_guard = None ;
459
+ if toolchain
460
+ . is_some_and ( |v| * v >= MINIMUM_TOOLCHAIN_VERSION_SUPPORTING_LOCKFILE_PATH )
461
+ {
462
+ let lockfile_path =
463
+ <_ as AsRef < Utf8Path > >:: as_ref ( manifest_path) . with_extension ( "lock" ) ;
464
+ if let Some ( ( temp_dir, target_lockfile) ) = make_lockfile_copy ( & lockfile_path) {
465
+ temp_dir_guard = Some ( temp_dir) ;
466
+ cmd. arg ( "--lockfile-path" ) ;
467
+ cmd. arg ( target_lockfile. as_str ( ) ) ;
468
+ requires_unstable_options = true ;
469
+ }
470
+ }
461
471
match & config. features {
462
472
CargoFeatures :: All => {
463
473
cmd. arg ( "--all-features" ) ;
@@ -479,6 +489,7 @@ impl WorkspaceBuildScripts {
479
489
}
480
490
481
491
if manifest_path. is_rust_manifest ( ) {
492
+ requires_unstable_options = true ;
482
493
cmd. arg ( "-Zscript" ) ;
483
494
}
484
495
@@ -488,7 +499,7 @@ impl WorkspaceBuildScripts {
488
499
// available in current toolchain's cargo, use it to build compile time deps only.
489
500
const COMP_TIME_DEPS_MIN_TOOLCHAIN_VERSION : semver:: Version = semver:: Version {
490
501
major : 1 ,
491
- minor : 89 ,
502
+ minor : 189 ,
492
503
patch : 0 ,
493
504
pre : semver:: Prerelease :: EMPTY ,
494
505
build : semver:: BuildMetadata :: EMPTY ,
@@ -498,8 +509,7 @@ impl WorkspaceBuildScripts {
498
509
toolchain. is_some_and ( |v| * v >= COMP_TIME_DEPS_MIN_TOOLCHAIN_VERSION ) ;
499
510
500
511
if cargo_comp_time_deps_available {
501
- cmd. env ( "__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS" , "nightly" ) ;
502
- cmd. arg ( "-Zunstable-options" ) ;
512
+ requires_unstable_options = true ;
503
513
cmd. arg ( "--compile-time-deps" ) ;
504
514
// we can pass this unconditionally, because we won't actually build the
505
515
// binaries, and as such, this will succeed even on targets without libtest
@@ -522,7 +532,11 @@ impl WorkspaceBuildScripts {
522
532
cmd. env ( "RA_RUSTC_WRAPPER" , "1" ) ;
523
533
}
524
534
}
525
- Ok ( cmd)
535
+ if requires_unstable_options {
536
+ cmd. env ( "__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS" , "nightly" ) ;
537
+ cmd. arg ( "-Zunstable-options" ) ;
538
+ }
539
+ Ok ( ( temp_dir_guard, cmd) )
526
540
}
527
541
}
528
542
}
0 commit comments