@@ -15,16 +15,18 @@ use span::Edition;
15
15
use stdx:: process:: spawn_with_streaming_output;
16
16
use toolchain:: Tool ;
17
17
18
+ use crate :: cargo_config_file:: make_lockfile_copy;
18
19
use crate :: { CfgOverrides , InvocationStrategy } ;
19
20
use crate :: { ManifestPath , Sysroot } ;
20
21
21
- const MINIMUM_TOOLCHAIN_VERSION_SUPPORTING_LOCKFILE_PATH : semver:: Version = semver:: Version {
22
- major : 1 ,
23
- minor : 82 ,
24
- patch : 0 ,
25
- pre : semver:: Prerelease :: EMPTY ,
26
- build : semver:: BuildMetadata :: EMPTY ,
27
- } ;
22
+ pub ( crate ) const MINIMUM_TOOLCHAIN_VERSION_SUPPORTING_LOCKFILE_PATH : semver:: Version =
23
+ semver:: Version {
24
+ major : 1 ,
25
+ minor : 82 ,
26
+ patch : 0 ,
27
+ pre : semver:: Prerelease :: EMPTY ,
28
+ build : semver:: BuildMetadata :: EMPTY ,
29
+ } ;
28
30
29
31
/// [`CargoWorkspace`] represents the logical structure of, well, a Cargo
30
32
/// workspace. It pretty closely mirrors `cargo metadata` output.
@@ -552,8 +554,10 @@ impl CargoWorkspace {
552
554
553
555
pub ( crate ) struct FetchMetadata {
554
556
command : cargo_metadata:: MetadataCommand ,
557
+ #[ expect( dead_code) ]
555
558
manifest_path : ManifestPath ,
556
559
lockfile_path : Option < Utf8PathBuf > ,
560
+ #[ expect( dead_code) ]
557
561
kind : & ' static str ,
558
562
no_deps : bool ,
559
563
no_deps_result : anyhow:: Result < cargo_metadata:: Metadata > ,
@@ -634,7 +638,7 @@ impl FetchMetadata {
634
638
command. other_options ( other_options. clone ( ) ) ;
635
639
636
640
if needs_nightly {
637
- command. env ( "RUSTC_BOOTSTRAP " , "1 " ) ;
641
+ command. env ( "__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS " , "nightly " ) ;
638
642
}
639
643
640
644
// Pre-fetch basic metadata using `--no-deps`, which:
@@ -681,11 +685,12 @@ impl FetchMetadata {
681
685
locked : bool ,
682
686
progress : & dyn Fn ( String ) ,
683
687
) -> anyhow:: Result < ( cargo_metadata:: Metadata , Option < anyhow:: Error > ) > {
688
+ _ = target_dir;
684
689
let Self {
685
690
mut command,
686
- manifest_path,
691
+ manifest_path : _ ,
687
692
lockfile_path,
688
- kind,
693
+ kind : _ ,
689
694
no_deps,
690
695
no_deps_result,
691
696
mut other_options,
@@ -696,54 +701,18 @@ impl FetchMetadata {
696
701
}
697
702
698
703
let mut using_lockfile_copy = false ;
699
- let mut _temp_dir_guard = None ;
700
- // The manifest is a rust file, so this means its a script manifest
701
- if let Some ( lockfile) = lockfile_path {
702
- _temp_dir_guard = temp_dir:: TempDir :: with_prefix ( "rust-analyzer" ) . ok ( ) ;
703
- let target_lockfile = _temp_dir_guard
704
- . and_then ( |tmp| tmp. path ( ) . join ( "Cargo.lock" ) . try_into ( ) . ok ( ) )
705
- . unwrap_or_else ( || {
706
- // When multiple workspaces share the same target dir, they might overwrite into a
707
- // single lockfile path.
708
- // See https://github.com/rust-lang/rust-analyzer/issues/20189#issuecomment-3073520255
709
- let manifest_path_hash = std:: hash:: BuildHasher :: hash_one (
710
- & std:: hash:: BuildHasherDefault :: < rustc_hash:: FxHasher > :: default ( ) ,
711
- & manifest_path,
712
- ) ;
713
- let disambiguator = format ! (
714
- "{}_{manifest_path_hash}" ,
715
- manifest_path. components( ) . nth_back( 1 ) . map_or( "" , |c| c. as_str( ) )
716
- ) ;
717
-
718
- target_dir
719
- . join ( "rust-analyzer" )
720
- . join ( "metadata" )
721
- . join ( kind)
722
- . join ( disambiguator)
723
- . join ( "Cargo.lock" )
724
- } ) ;
725
- match std:: fs:: copy ( & lockfile, & target_lockfile) {
726
- Ok ( _) => {
727
- using_lockfile_copy = true ;
728
- other_options. push ( "--lockfile-path" . to_owned ( ) ) ;
729
- other_options. push ( target_lockfile. to_string ( ) ) ;
730
- }
731
- Err ( e) if e. kind ( ) == std:: io:: ErrorKind :: NotFound => {
732
- // There exists no lockfile yet
733
- using_lockfile_copy = true ;
734
- other_options. push ( "--lockfile-path" . to_owned ( ) ) ;
735
- other_options. push ( target_lockfile. to_string ( ) ) ;
736
- }
737
- Err ( e) => {
738
- tracing:: warn!(
739
- "Failed to copy lock file from `{lockfile}` to `{target_lockfile}`: {e}" ,
740
- ) ;
741
- }
742
- }
704
+ let mut _temp_dir_guard;
705
+ if let Some ( lockfile) = lockfile_path
706
+ && let Some ( ( temp_dir, target_lockfile) ) = make_lockfile_copy ( & lockfile)
707
+ {
708
+ _temp_dir_guard = temp_dir;
709
+ other_options. push ( "--lockfile-path" . to_owned ( ) ) ;
710
+ other_options. push ( target_lockfile. to_string ( ) ) ;
711
+ using_lockfile_copy = true ;
743
712
}
744
713
if using_lockfile_copy {
714
+ command. env ( "__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS" , "nightly" ) ;
745
715
other_options. push ( "-Zunstable-options" . to_owned ( ) ) ;
746
- command. env ( "RUSTC_BOOTSTRAP" , "1" ) ;
747
716
}
748
717
// No need to lock it if we copied the lockfile, we won't modify the original after all/
749
718
// This way cargo cannot error out on us if the lockfile requires updating.
@@ -752,9 +721,6 @@ impl FetchMetadata {
752
721
}
753
722
command. other_options ( other_options) ;
754
723
755
- // FIXME: Fetching metadata is a slow process, as it might require
756
- // calling crates.io. We should be reporting progress here, but it's
757
- // unclear whether cargo itself supports it.
758
724
progress ( "cargo metadata: started" . to_owned ( ) ) ;
759
725
760
726
let res = ( || -> anyhow:: Result < ( _ , _ ) > {
0 commit comments