@@ -13,7 +13,7 @@ use base_db::{
1313} ;
1414use cfg:: { CfgAtom , CfgDiff , CfgOptions } ;
1515use intern:: { Symbol , sym} ;
16- use paths:: { AbsPath , AbsPathBuf , Utf8PathBuf } ;
16+ use paths:: { AbsPath , AbsPathBuf , Utf8Path , Utf8PathBuf } ;
1717use rustc_hash:: { FxHashMap , FxHashSet } ;
1818use semver:: Version ;
1919use span:: { Edition , FileId } ;
@@ -1216,6 +1216,7 @@ fn cargo_to_crate_graph(
12161216 load,
12171217 crate_ws_data. clone ( ) ,
12181218 ) ;
1219+ let cargo_path = sysroot. tool_path ( Tool :: Cargo , cargo. workspace_root ( ) , cargo. env ( ) ) ;
12191220
12201221 let cfg_options = CfgOptions :: from_iter ( rustc_cfg) ;
12211222
@@ -1290,6 +1291,7 @@ fn cargo_to_crate_graph(
12901291 } else {
12911292 Arc :: new ( pkg_data. manifest . parent ( ) . to_path_buf ( ) )
12921293 } ,
1294+ & cargo_path,
12931295 ) ;
12941296 if let TargetKind :: Lib { .. } = kind {
12951297 lib_tgt = Some ( ( crate_id, name. clone ( ) ) ) ;
@@ -1397,6 +1399,7 @@ fn cargo_to_crate_graph(
13971399 } ,
13981400 // FIXME: This looks incorrect but I don't think this causes problems.
13991401 crate_ws_data,
1402+ & cargo_path,
14001403 ) ;
14011404 }
14021405 }
@@ -1475,6 +1478,7 @@ fn handle_rustc_crates(
14751478 override_cfg : & CfgOverrides ,
14761479 build_scripts : & WorkspaceBuildScripts ,
14771480 crate_ws_data : Arc < CrateWorkspaceData > ,
1481+ cargo_path : & Utf8Path ,
14781482) {
14791483 let mut rustc_pkg_crates = FxHashMap :: default ( ) ;
14801484 // The root package of the rustc-dev component is rustc_driver, so we match that
@@ -1525,6 +1529,7 @@ fn handle_rustc_crates(
15251529 } else {
15261530 Arc :: new ( pkg_data. manifest . parent ( ) . to_path_buf ( ) )
15271531 } ,
1532+ cargo_path,
15281533 ) ;
15291534 pkg_to_lib_crate. insert ( pkg, crate_id) ;
15301535 // Add dependencies on core / std / alloc for this crate
@@ -1582,11 +1587,12 @@ fn add_target_crate_root(
15821587 build_data : Option < ( & BuildScriptOutput , bool ) > ,
15831588 cfg_options : CfgOptions ,
15841589 file_id : FileId ,
1585- cargo_name : & str ,
1590+ cargo_crate_name : & str ,
15861591 kind : TargetKind ,
15871592 origin : CrateOrigin ,
15881593 crate_ws_data : Arc < CrateWorkspaceData > ,
15891594 proc_macro_cwd : Arc < AbsPathBuf > ,
1595+ cargo_path : & Utf8Path ,
15901596) -> CrateBuilderId {
15911597 let edition = pkg. edition ;
15921598 let potential_cfg_options = if pkg. features . is_empty ( ) {
@@ -1613,16 +1619,16 @@ fn add_target_crate_root(
16131619
16141620 let mut env = cargo. env ( ) . clone ( ) ;
16151621 inject_cargo_package_env ( & mut env, pkg) ;
1616- inject_cargo_env ( & mut env) ;
1617- inject_rustc_tool_env ( & mut env, cargo_name , kind) ;
1622+ inject_cargo_env ( & mut env, & cargo_path ) ;
1623+ inject_rustc_tool_env ( & mut env, cargo_crate_name , kind) ;
16181624
16191625 if let Some ( envs) = build_data. map ( |( it, _) | & it. envs ) {
16201626 env. extend_from_other ( envs) ;
16211627 }
16221628 let crate_id = crate_graph. add_crate_root (
16231629 file_id,
16241630 edition,
1625- Some ( CrateDisplayName :: from_canonical_name ( cargo_name ) ) ,
1631+ Some ( CrateDisplayName :: from_canonical_name ( cargo_crate_name ) ) ,
16261632 Some ( pkg. version . to_string ( ) ) ,
16271633 cfg_options,
16281634 potential_cfg_options,
@@ -1636,7 +1642,9 @@ fn add_target_crate_root(
16361642 let proc_macro = match build_data {
16371643 Some ( ( BuildScriptOutput { proc_macro_dylib_path, .. } , has_errors) ) => {
16381644 match proc_macro_dylib_path {
1639- ProcMacroDylibPath :: Path ( path) => Ok ( ( cargo_name. to_owned ( ) , path. clone ( ) ) ) ,
1645+ ProcMacroDylibPath :: Path ( path) => {
1646+ Ok ( ( cargo_crate_name. to_owned ( ) , path. clone ( ) ) )
1647+ }
16401648 ProcMacroDylibPath :: NotBuilt => Err ( ProcMacroLoadingError :: NotYetBuilt ) ,
16411649 ProcMacroDylibPath :: NotProcMacro | ProcMacroDylibPath :: DylibNotFound
16421650 if has_errors =>
0 commit comments