From 2c48fa087b6cc79ebfd81af9daf4a07d8019fd67 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 22 Nov 2019 13:55:03 +0300 Subject: Add support for environment to CrateGraph --- crates/ra_project_model/src/lib.rs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'crates/ra_project_model/src/lib.rs') diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 0e14f1b70..d04a8cbe2 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs @@ -13,7 +13,7 @@ use std::{ }; use ra_cfg::CfgOptions; -use ra_db::{CrateGraph, CrateId, Edition, FileId}; +use ra_db::{CrateGraph, CrateId, Edition, Env, FileId}; use rustc_hash::FxHashMap; use serde_json::from_reader; @@ -146,7 +146,12 @@ impl ProjectWorkspace { }; crates.insert( crate_id, - crate_graph.add_crate_root(file_id, edition, cfg_options), + crate_graph.add_crate_root( + file_id, + edition, + cfg_options, + Env::default(), + ), ); } } @@ -180,8 +185,12 @@ impl ProjectWorkspace { opts }; - let crate_id = - crate_graph.add_crate_root(file_id, Edition::Edition2018, cfg_options); + let crate_id = crate_graph.add_crate_root( + file_id, + Edition::Edition2018, + cfg_options, + Env::default(), + ); sysroot_crates.insert(krate, crate_id); names.insert(crate_id, krate.name(&sysroot).to_string()); } @@ -216,8 +225,12 @@ impl ProjectWorkspace { opts.insert_features(pkg.features(&cargo).iter().map(Into::into)); opts }; - let crate_id = - crate_graph.add_crate_root(file_id, edition, cfg_options); + let crate_id = crate_graph.add_crate_root( + file_id, + edition, + cfg_options, + Env::default(), + ); names.insert(crate_id, pkg.name(&cargo).to_string()); if tgt.kind(&cargo) == TargetKind::Lib { lib_tgt = Some(crate_id); -- cgit v1.2.3 From e3f8e7d13d01fcdd1bb0f31887d1f72fc44c4d4e Mon Sep 17 00:00:00 2001 From: Marco Groppo Date: Sun, 24 Nov 2019 13:19:47 +0100 Subject: Add alloc to the sysroot --- crates/ra_project_model/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'crates/ra_project_model/src/lib.rs') diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index d04a8cbe2..638ca2f8b 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs @@ -209,6 +209,7 @@ impl ProjectWorkspace { } let libcore = sysroot.core().and_then(|it| sysroot_crates.get(&it).copied()); + let liballoc = sysroot.alloc().and_then(|it| sysroot_crates.get(&it).copied()); let libstd = sysroot.std().and_then(|it| sysroot_crates.get(&it).copied()); let mut pkg_to_lib_crate = FxHashMap::default(); @@ -261,6 +262,11 @@ impl ProjectWorkspace { log::error!("cyclic dependency on core for {}", pkg.name(&cargo)) } } + if let Some(alloc) = liballoc { + if let Err(_) = crate_graph.add_dep(from, "alloc".into(), alloc) { + log::error!("cyclic dependency on alloc for {}", pkg.name(&cargo)) + } + } if let Some(std) = libstd { if let Err(_) = crate_graph.add_dep(from, "std".into(), std) { log::error!("cyclic dependency on std for {}", pkg.name(&cargo)) -- cgit v1.2.3 From 6a8b4f873aa42f3522d3a92384019272b6ccefd2 Mon Sep 17 00:00:00 2001 From: JasperDeSutter Date: Sun, 24 Nov 2019 11:33:12 +0100 Subject: add proc-macro crate type handling --- crates/ra_project_model/src/lib.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'crates/ra_project_model/src/lib.rs') diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index d04a8cbe2..77f729a25 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs @@ -210,6 +210,8 @@ impl ProjectWorkspace { let libcore = sysroot.core().and_then(|it| sysroot_crates.get(&it).copied()); let libstd = sysroot.std().and_then(|it| sysroot_crates.get(&it).copied()); + let libproc_macro = + sysroot.proc_macro().and_then(|it| sysroot_crates.get(&it).copied()); let mut pkg_to_lib_crate = FxHashMap::default(); let mut pkg_crates = FxHashMap::default(); @@ -236,6 +238,21 @@ impl ProjectWorkspace { lib_tgt = Some(crate_id); pkg_to_lib_crate.insert(pkg, crate_id); } + if tgt.is_proc_macro(&cargo) { + if let Some(proc_macro) = libproc_macro { + if let Err(_) = crate_graph.add_dep( + crate_id, + "proc_macro".into(), + proc_macro, + ) { + log::error!( + "cyclic dependency on proc_macro for {}", + pkg.name(&cargo) + ) + } + } + } + pkg_crates.entry(pkg).or_insert_with(Vec::new).push(crate_id); } } -- cgit v1.2.3