@@ -16,12 +16,13 @@ use la_arena::ArenaMap;
1616use paths:: { AbsPath , AbsPathBuf , Utf8PathBuf } ;
1717use rustc_hash:: { FxHashMap , FxHashSet } ;
1818use serde:: Deserialize as _;
19- use stdx:: { always , never} ;
19+ use stdx:: never;
2020use toolchain:: Tool ;
2121
2222use crate :: {
2323 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,
2526} ;
2627
2728/// Output of the build script and proc-macro building steps for a workspace.
@@ -77,7 +78,7 @@ impl WorkspaceBuildScripts {
7778 let current_dir = workspace. workspace_root ( ) ;
7879
7980 let allowed_features = workspace. workspace_features ( ) ;
80- let cmd = Self :: build_command (
81+ let ( _guard , cmd) = Self :: build_command (
8182 config,
8283 & allowed_features,
8384 workspace. manifest_path ( ) ,
@@ -98,7 +99,7 @@ impl WorkspaceBuildScripts {
9899 ) -> io:: Result < Vec < WorkspaceBuildScripts > > {
99100 assert_eq ! ( config. invocation_strategy, InvocationStrategy :: Once ) ;
100101
101- let cmd = Self :: build_command (
102+ let ( _guard , cmd) = Self :: build_command (
102103 config,
103104 & Default :: default ( ) ,
104105 // This is not gonna be used anyways, so just construct a dummy here
@@ -379,10 +380,6 @@ impl WorkspaceBuildScripts {
379380 progress ( format ! (
380381 "building compile-time-deps: proc-macro {name} built"
381382 ) ) ;
382- always ! (
383- data. proc_macro_dylib_path == ProcMacroDylibPath :: NotBuilt ,
384- "received multiple compiler artifacts for the same package: {message:?}"
385- ) ;
386383 if data. proc_macro_dylib_path == ProcMacroDylibPath :: NotBuilt {
387384 data. proc_macro_dylib_path = ProcMacroDylibPath :: NotProcMacro ;
388385 }
@@ -434,14 +431,15 @@ impl WorkspaceBuildScripts {
434431 current_dir : & AbsPath ,
435432 sysroot : & Sysroot ,
436433 toolchain : Option < & semver:: Version > ,
437- ) -> io:: Result < Command > {
434+ ) -> io:: Result < ( Option < temp_dir :: TempDir > , Command ) > {
438435 match config. run_build_script_command . as_deref ( ) {
439436 Some ( [ program, args @ ..] ) => {
440437 let mut cmd = toolchain:: command ( program, current_dir, & config. extra_env ) ;
441438 cmd. args ( args) ;
442- Ok ( cmd)
439+ Ok ( ( None , cmd) )
443440 }
444441 _ => {
442+ let mut requires_unstable_options = false ;
445443 let mut cmd = sysroot. tool ( Tool :: Cargo , current_dir, & config. extra_env ) ;
446444
447445 cmd. args ( [ "check" , "--quiet" , "--workspace" , "--message-format=json" ] ) ;
@@ -457,7 +455,19 @@ impl WorkspaceBuildScripts {
457455 if let Some ( target) = & config. target {
458456 cmd. args ( [ "--target" , target] ) ;
459457 }
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+ }
461471 match & config. features {
462472 CargoFeatures :: All => {
463473 cmd. arg ( "--all-features" ) ;
@@ -479,6 +489,7 @@ impl WorkspaceBuildScripts {
479489 }
480490
481491 if manifest_path. is_rust_manifest ( ) {
492+ requires_unstable_options = true ;
482493 cmd. arg ( "-Zscript" ) ;
483494 }
484495
@@ -488,7 +499,7 @@ impl WorkspaceBuildScripts {
488499 // available in current toolchain's cargo, use it to build compile time deps only.
489500 const COMP_TIME_DEPS_MIN_TOOLCHAIN_VERSION : semver:: Version = semver:: Version {
490501 major : 1 ,
491- minor : 89 ,
502+ minor : 189 ,
492503 patch : 0 ,
493504 pre : semver:: Prerelease :: EMPTY ,
494505 build : semver:: BuildMetadata :: EMPTY ,
@@ -498,8 +509,7 @@ impl WorkspaceBuildScripts {
498509 toolchain. is_some_and ( |v| * v >= COMP_TIME_DEPS_MIN_TOOLCHAIN_VERSION ) ;
499510
500511 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 ;
503513 cmd. arg ( "--compile-time-deps" ) ;
504514 // we can pass this unconditionally, because we won't actually build the
505515 // binaries, and as such, this will succeed even on targets without libtest
@@ -522,7 +532,11 @@ impl WorkspaceBuildScripts {
522532 cmd. env ( "RA_RUSTC_WRAPPER" , "1" ) ;
523533 }
524534 }
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) )
526540 }
527541 }
528542 }
0 commit comments