diff options
-rw-r--r-- | crates/project_model/src/workspace.rs | 104 |
1 files changed, 50 insertions, 54 deletions
diff --git a/crates/project_model/src/workspace.rs b/crates/project_model/src/workspace.rs index 3ea6ba47e..a71f96164 100644 --- a/crates/project_model/src/workspace.rs +++ b/crates/project_model/src/workspace.rs | |||
@@ -304,14 +304,14 @@ fn cargo_to_crate_graph( | |||
304 | for pkg in cargo.packages() { | 304 | for pkg in cargo.packages() { |
305 | let mut lib_tgt = None; | 305 | let mut lib_tgt = None; |
306 | for &tgt in cargo[pkg].targets.iter() { | 306 | for &tgt in cargo[pkg].targets.iter() { |
307 | if let Some(crate_id) = add_target_crate_root( | 307 | if let Some(file_id) = load(&cargo[tgt].root) { |
308 | &mut crate_graph, | 308 | let crate_id = add_target_crate_root( |
309 | &cargo[pkg], | 309 | &mut crate_graph, |
310 | &cargo[tgt], | 310 | &cargo[pkg], |
311 | &cfg_options, | 311 | &cfg_options, |
312 | proc_macro_client, | 312 | proc_macro_client, |
313 | load, | 313 | file_id, |
314 | ) { | 314 | ); |
315 | if cargo[tgt].kind == TargetKind::Lib { | 315 | if cargo[tgt].kind == TargetKind::Lib { |
316 | lib_tgt = Some((crate_id, cargo[tgt].name.clone())); | 316 | lib_tgt = Some((crate_id, cargo[tgt].name.clone())); |
317 | pkg_to_lib_crate.insert(pkg, crate_id); | 317 | pkg_to_lib_crate.insert(pkg, crate_id); |
@@ -380,14 +380,14 @@ fn cargo_to_crate_graph( | |||
380 | continue; | 380 | continue; |
381 | } | 381 | } |
382 | 382 | ||
383 | if let Some(crate_id) = add_target_crate_root( | 383 | if let Some(file_id) = load(&rustc_workspace[tgt].root) { |
384 | &mut crate_graph, | 384 | let crate_id = add_target_crate_root( |
385 | &rustc_workspace[pkg], | 385 | &mut crate_graph, |
386 | &rustc_workspace[tgt], | 386 | &rustc_workspace[pkg], |
387 | &cfg_options, | 387 | &cfg_options, |
388 | proc_macro_client, | 388 | proc_macro_client, |
389 | load, | 389 | file_id, |
390 | ) { | 390 | ); |
391 | pkg_to_lib_crate.insert(pkg, crate_id); | 391 | pkg_to_lib_crate.insert(pkg, crate_id); |
392 | // Add dependencies on the core / std / alloc for rustc | 392 | // Add dependencies on the core / std / alloc for rustc |
393 | for (name, krate) in public_deps.iter() { | 393 | for (name, krate) in public_deps.iter() { |
@@ -432,49 +432,45 @@ fn cargo_to_crate_graph( | |||
432 | fn add_target_crate_root( | 432 | fn add_target_crate_root( |
433 | crate_graph: &mut CrateGraph, | 433 | crate_graph: &mut CrateGraph, |
434 | pkg: &cargo_workspace::PackageData, | 434 | pkg: &cargo_workspace::PackageData, |
435 | tgt: &cargo_workspace::TargetData, | ||
436 | cfg_options: &CfgOptions, | 435 | cfg_options: &CfgOptions, |
437 | proc_macro_client: &ProcMacroClient, | 436 | proc_macro_client: &ProcMacroClient, |
438 | load: &mut dyn FnMut(&AbsPath) -> Option<FileId>, | 437 | file_id: FileId, |
439 | ) -> Option<CrateId> { | 438 | ) -> CrateId { |
440 | let root = tgt.root.as_path(); | 439 | let edition = pkg.edition; |
441 | if let Some(file_id) = load(root) { | 440 | let cfg_options = { |
442 | let edition = pkg.edition; | 441 | let mut opts = cfg_options.clone(); |
443 | let cfg_options = { | 442 | for feature in pkg.features.iter() { |
444 | let mut opts = cfg_options.clone(); | 443 | opts.insert_key_value("feature".into(), feature.into()); |
445 | for feature in pkg.features.iter() { | 444 | } |
446 | opts.insert_key_value("feature".into(), feature.into()); | 445 | opts.extend(pkg.cfgs.iter().cloned()); |
447 | } | 446 | opts |
448 | opts.extend(pkg.cfgs.iter().cloned()); | 447 | }; |
449 | opts | 448 | let mut env = Env::default(); |
450 | }; | 449 | if let Some(out_dir) = &pkg.out_dir { |
451 | let mut env = Env::default(); | 450 | // NOTE: cargo and rustc seem to hide non-UTF-8 strings from env! and option_env!() |
452 | if let Some(out_dir) = &pkg.out_dir { | 451 | if let Some(out_dir) = out_dir.to_str().map(|s| s.to_owned()) { |
453 | // NOTE: cargo and rustc seem to hide non-UTF-8 strings from env! and option_env!() | 452 | env.set("OUT_DIR", out_dir); |
454 | if let Some(out_dir) = out_dir.to_str().map(|s| s.to_owned()) { | ||
455 | env.set("OUT_DIR", out_dir); | ||
456 | } | ||
457 | } | 453 | } |
458 | let proc_macro = pkg | ||
459 | .proc_macro_dylib_path | ||
460 | .as_ref() | ||
461 | .map(|it| proc_macro_client.by_dylib_path(&it)) | ||
462 | .unwrap_or_default(); | ||
463 | |||
464 | let display_name = CrateDisplayName::from_canonical_name(pkg.name.clone()); | ||
465 | let crate_id = crate_graph.add_crate_root( | ||
466 | file_id, | ||
467 | edition, | ||
468 | Some(display_name), | ||
469 | cfg_options, | ||
470 | env, | ||
471 | proc_macro.clone(), | ||
472 | ); | ||
473 | |||
474 | return Some(crate_id); | ||
475 | } | 454 | } |
476 | None | 455 | let proc_macro = pkg |
456 | .proc_macro_dylib_path | ||
457 | .as_ref() | ||
458 | .map(|it| proc_macro_client.by_dylib_path(&it)) | ||
459 | .unwrap_or_default(); | ||
460 | |||
461 | let display_name = CrateDisplayName::from_canonical_name(pkg.name.clone()); | ||
462 | let crate_id = crate_graph.add_crate_root( | ||
463 | file_id, | ||
464 | edition, | ||
465 | Some(display_name), | ||
466 | cfg_options, | ||
467 | env, | ||
468 | proc_macro.clone(), | ||
469 | ); | ||
470 | |||
471 | crate_id | ||
477 | } | 472 | } |
473 | |||
478 | fn sysroot_to_crate_graph( | 474 | fn sysroot_to_crate_graph( |
479 | crate_graph: &mut CrateGraph, | 475 | crate_graph: &mut CrateGraph, |
480 | sysroot: &Sysroot, | 476 | sysroot: &Sysroot, |