aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/project_model/src/workspace.rs76
1 files changed, 38 insertions, 38 deletions
diff --git a/crates/project_model/src/workspace.rs b/crates/project_model/src/workspace.rs
index 786d7e5ec..695fac398 100644
--- a/crates/project_model/src/workspace.rs
+++ b/crates/project_model/src/workspace.rs
@@ -2,11 +2,7 @@
2//! metadata` or `rust-project.json`) into representation stored in the salsa 2//! metadata` or `rust-project.json`) into representation stored in the salsa
3//! database -- `CrateGraph`. 3//! database -- `CrateGraph`.
4 4
5use std::{ 5use std::{collections::VecDeque, fmt, fs, path::Path, process::Command};
6 fmt, fs,
7 path::{Component, Path},
8 process::Command,
9};
10 6
11use anyhow::{Context, Result}; 7use anyhow::{Context, Result};
12use base_db::{CrateDisplayName, CrateGraph, CrateId, CrateName, Edition, Env, FileId, ProcMacro}; 8use base_db::{CrateDisplayName, CrateGraph, CrateId, CrateName, Edition, Env, FileId, ProcMacro};
@@ -446,37 +442,40 @@ fn cargo_to_crate_graph(
446 let mut rustc_pkg_crates = FxHashMap::default(); 442 let mut rustc_pkg_crates = FxHashMap::default();
447 443
448 // If the user provided a path to rustc sources, we add all the rustc_private crates 444 // If the user provided a path to rustc sources, we add all the rustc_private crates
449 // and create dependencies on them for the crates in the current workspace 445 // and create dependencies on them for the crates which opt-in to that
450 if let Some(rustc_workspace) = rustc { 446 if let Some(rustc_workspace) = rustc {
451 for pkg in rustc_workspace.packages() { 447 // rustc-dev crates start from 'rustc_driver'
452 for &tgt in rustc_workspace[pkg].targets.iter() { 448 // Therefore, we collect all crates which are transitive dependencies of rustc_driver
453 if rustc_workspace[tgt].kind != TargetKind::Lib { 449 if let Some(root_pkg) = rustc_workspace
454 continue; 450 .packages()
455 } 451 .find(|package| rustc_workspace[*package].name == "rustc_driver")
456 // Exclude alloc / core / std 452 {
457 if rustc_workspace[tgt] 453 let mut queue = VecDeque::new();
458 .root 454 queue.push_back(root_pkg);
459 .components() 455 while let Some(pkg) = queue.pop_front() {
460 .any(|c| c == Component::Normal("library".as_ref())) 456 for dep in &rustc_workspace[pkg].dependencies {
461 { 457 queue.push_back(dep.pkg);
462 continue;
463 } 458 }
464 459 for &tgt in rustc_workspace[pkg].targets.iter() {
465 if let Some(file_id) = load(&rustc_workspace[tgt].root) { 460 if rustc_workspace[tgt].kind != TargetKind::Lib {
466 let crate_id = add_target_crate_root( 461 continue;
467 &mut crate_graph, 462 }
468 &rustc_workspace[pkg], 463 if let Some(file_id) = load(&rustc_workspace[tgt].root) {
469 rustc_build_data_map.and_then(|it| it.get(&rustc_workspace[pkg].id)), 464 let crate_id = add_target_crate_root(
470 &cfg_options, 465 &mut crate_graph,
471 proc_macro_loader, 466 &rustc_workspace[pkg],
472 file_id, 467 rustc_build_data_map.and_then(|it| it.get(&rustc_workspace[pkg].id)),
473 ); 468 &cfg_options,
474 pkg_to_lib_crate.insert(pkg, crate_id); 469 proc_macro_loader,
475 // Add dependencies on the core / std / alloc for rustc 470 file_id,
476 for (name, krate) in public_deps.iter() { 471 );
477 add_dep(&mut crate_graph, crate_id, name.clone(), *krate); 472 pkg_to_lib_crate.insert(pkg, crate_id);
473 // Add dependencies on the core / std / alloc for rustc
474 for (name, krate) in public_deps.iter() {
475 add_dep(&mut crate_graph, crate_id, name.clone(), *krate);
476 }
477 rustc_pkg_crates.entry(pkg).or_insert_with(Vec::new).push(crate_id);
478 } 478 }
479 rustc_pkg_crates.entry(pkg).or_insert_with(Vec::new).push(crate_id);
480 } 479 }
481 } 480 }
482 } 481 }
@@ -493,7 +492,7 @@ fn cargo_to_crate_graph(
493 } 492 }
494 } 493 }
495 494
496 // Add dependencies for all the crates of the current workspace to rustc_private libraries 495 // Add dependencies for all crates which opt in to rustc_private libraries
497 for dep in rustc_workspace.packages() { 496 for dep in rustc_workspace.packages() {
498 let name = CrateName::normalize_dashes(&rustc_workspace[dep].name); 497 let name = CrateName::normalize_dashes(&rustc_workspace[dep].name);
499 498
@@ -507,13 +506,14 @@ fn cargo_to_crate_graph(
507 continue; 506 continue;
508 } 507 }
509 for &from in pkg_crates.get(&pkg).into_iter().flatten() { 508 for &from in pkg_crates.get(&pkg).into_iter().flatten() {
509 // Avoid creating duplicate dependencies
510 if !crate_graph[from].dependencies.iter().any(|d| d.name == name) { 510 if !crate_graph[from].dependencies.iter().any(|d| d.name == name) {
511 add_dep(&mut crate_graph, from, name.clone(), to); 511 add_dep(&mut crate_graph, from, name.clone(), to);
512 } else { 512 } else {
513 // eprintln!( 513 eprintln!(
514 // "Skipped {} for {:?}", 514 "Skipped {} for {:?}",
515 // &name, &crate_graph[from].display_name 515 &name, &crate_graph[from].display_name
516 // ); 516 );
517 } 517 }
518 } 518 }
519 } 519 }