diff options
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r-- | crates/ra_project_model/src/cargo_workspace.rs | 14 | ||||
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 10 | ||||
-rw-r--r-- | crates/ra_project_model/src/sysroot.rs | 4 |
3 files changed, 22 insertions, 6 deletions
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index 28dadea9d..cf88911b7 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs | |||
@@ -1,6 +1,7 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use std::path::{Path, PathBuf}; | 3 | use std::path::{Path, PathBuf}; |
4 | use std::str::FromStr; | ||
4 | 5 | ||
5 | use cargo_metadata::{CargoOpt, MetadataCommand}; | 6 | use cargo_metadata::{CargoOpt, MetadataCommand}; |
6 | use ra_arena::{impl_arena_id, Arena, RawId}; | 7 | use ra_arena::{impl_arena_id, Arena, RawId}; |
@@ -140,18 +141,21 @@ impl CargoWorkspace { | |||
140 | let ws_members = &meta.workspace_members; | 141 | let ws_members = &meta.workspace_members; |
141 | 142 | ||
142 | for meta_pkg in meta.packages { | 143 | for meta_pkg in meta.packages { |
143 | let is_member = ws_members.contains(&meta_pkg.id); | 144 | let cargo_metadata::Package { id, edition, name, manifest_path, .. } = meta_pkg; |
145 | let is_member = ws_members.contains(&id); | ||
146 | let edition = Edition::from_str(&edition) | ||
147 | .map_err(|e| (format!("metadata for package {} failed: {}", &name, e.msg)))?; | ||
144 | let pkg = packages.alloc(PackageData { | 148 | let pkg = packages.alloc(PackageData { |
145 | name: meta_pkg.name, | 149 | name, |
146 | manifest: meta_pkg.manifest_path.clone(), | 150 | manifest: manifest_path, |
147 | targets: Vec::new(), | 151 | targets: Vec::new(), |
148 | is_member, | 152 | is_member, |
149 | edition: Edition::from_string(&meta_pkg.edition), | 153 | edition, |
150 | dependencies: Vec::new(), | 154 | dependencies: Vec::new(), |
151 | features: Vec::new(), | 155 | features: Vec::new(), |
152 | }); | 156 | }); |
153 | let pkg_data = &mut packages[pkg]; | 157 | let pkg_data = &mut packages[pkg]; |
154 | pkg_by_id.insert(meta_pkg.id.clone(), pkg); | 158 | pkg_by_id.insert(id, pkg); |
155 | for meta_tgt in meta_pkg.targets { | 159 | for meta_tgt in meta_pkg.targets { |
156 | let tgt = targets.alloc(TargetData { | 160 | let tgt = targets.alloc(TargetData { |
157 | pkg, | 161 | pkg, |
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 8b8663a78..0e14f1b70 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -199,6 +199,7 @@ impl ProjectWorkspace { | |||
199 | } | 199 | } |
200 | } | 200 | } |
201 | 201 | ||
202 | let libcore = sysroot.core().and_then(|it| sysroot_crates.get(&it).copied()); | ||
202 | let libstd = sysroot.std().and_then(|it| sysroot_crates.get(&it).copied()); | 203 | let libstd = sysroot.std().and_then(|it| sysroot_crates.get(&it).copied()); |
203 | 204 | ||
204 | let mut pkg_to_lib_crate = FxHashMap::default(); | 205 | let mut pkg_to_lib_crate = FxHashMap::default(); |
@@ -226,7 +227,7 @@ impl ProjectWorkspace { | |||
226 | } | 227 | } |
227 | } | 228 | } |
228 | 229 | ||
229 | // Set deps to the std and to the lib target of the current package | 230 | // Set deps to the core, std and to the lib target of the current package |
230 | for &from in pkg_crates.get(&pkg).into_iter().flatten() { | 231 | for &from in pkg_crates.get(&pkg).into_iter().flatten() { |
231 | if let Some(to) = lib_tgt { | 232 | if let Some(to) = lib_tgt { |
232 | if to != from { | 233 | if to != from { |
@@ -240,6 +241,13 @@ impl ProjectWorkspace { | |||
240 | } | 241 | } |
241 | } | 242 | } |
242 | } | 243 | } |
244 | // core is added as a dependency before std in order to | ||
245 | // mimic rustcs dependency order | ||
246 | if let Some(core) = libcore { | ||
247 | if let Err(_) = crate_graph.add_dep(from, "core".into(), core) { | ||
248 | log::error!("cyclic dependency on core for {}", pkg.name(&cargo)) | ||
249 | } | ||
250 | } | ||
243 | if let Some(std) = libstd { | 251 | if let Some(std) = libstd { |
244 | if let Err(_) = crate_graph.add_dep(from, "std".into(), std) { | 252 | if let Err(_) = crate_graph.add_dep(from, "std".into(), std) { |
245 | log::error!("cyclic dependency on std for {}", pkg.name(&cargo)) | 253 | log::error!("cyclic dependency on std for {}", pkg.name(&cargo)) |
diff --git a/crates/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs index 35d6df5cb..3d827809e 100644 --- a/crates/ra_project_model/src/sysroot.rs +++ b/crates/ra_project_model/src/sysroot.rs | |||
@@ -27,6 +27,10 @@ struct SysrootCrateData { | |||
27 | } | 27 | } |
28 | 28 | ||
29 | impl Sysroot { | 29 | impl Sysroot { |
30 | pub fn core(&self) -> Option<SysrootCrate> { | ||
31 | self.by_name("core") | ||
32 | } | ||
33 | |||
30 | pub fn std(&self) -> Option<SysrootCrate> { | 34 | pub fn std(&self) -> Option<SysrootCrate> { |
31 | self.by_name("std") | 35 | self.by_name("std") |
32 | } | 36 | } |