diff options
author | JasperDeSutter <[email protected]> | 2019-11-24 10:33:12 +0000 |
---|---|---|
committer | JasperDeSutter <[email protected]> | 2019-11-24 15:55:56 +0000 |
commit | 6a8b4f873aa42f3522d3a92384019272b6ccefd2 (patch) | |
tree | 23235e959e23796bb05c811742375aeaf8143953 /crates/ra_project_model/src | |
parent | ea3124c12a52f28163a6375b6a5e3c79fc14312d (diff) |
add proc-macro crate type handling
Diffstat (limited to 'crates/ra_project_model/src')
-rw-r--r-- | crates/ra_project_model/src/cargo_workspace.rs | 8 | ||||
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 17 | ||||
-rw-r--r-- | crates/ra_project_model/src/sysroot.rs | 6 |
3 files changed, 30 insertions, 1 deletions
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index c128e608d..351997dcd 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs | |||
@@ -54,11 +54,13 @@ struct TargetData { | |||
54 | name: String, | 54 | name: String, |
55 | root: PathBuf, | 55 | root: PathBuf, |
56 | kind: TargetKind, | 56 | kind: TargetKind, |
57 | is_proc_macro: bool, | ||
57 | } | 58 | } |
58 | 59 | ||
59 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 60 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
60 | pub enum TargetKind { | 61 | pub enum TargetKind { |
61 | Bin, | 62 | Bin, |
63 | /// Any kind of Cargo lib crate-type (dylib, rlib, proc-macro, ...). | ||
62 | Lib, | 64 | Lib, |
63 | Example, | 65 | Example, |
64 | Test, | 66 | Test, |
@@ -74,6 +76,7 @@ impl TargetKind { | |||
74 | "test" => TargetKind::Test, | 76 | "test" => TargetKind::Test, |
75 | "bench" => TargetKind::Bench, | 77 | "bench" => TargetKind::Bench, |
76 | "example" => TargetKind::Example, | 78 | "example" => TargetKind::Example, |
79 | "proc-macro" => TargetKind::Lib, | ||
77 | _ if kind.contains("lib") => TargetKind::Lib, | 80 | _ if kind.contains("lib") => TargetKind::Lib, |
78 | _ => continue, | 81 | _ => continue, |
79 | }; | 82 | }; |
@@ -123,6 +126,9 @@ impl Target { | |||
123 | pub fn kind(self, ws: &CargoWorkspace) -> TargetKind { | 126 | pub fn kind(self, ws: &CargoWorkspace) -> TargetKind { |
124 | ws.targets[self].kind | 127 | ws.targets[self].kind |
125 | } | 128 | } |
129 | pub fn is_proc_macro(self, ws: &CargoWorkspace) -> bool { | ||
130 | ws.targets[self].is_proc_macro | ||
131 | } | ||
126 | } | 132 | } |
127 | 133 | ||
128 | impl CargoWorkspace { | 134 | impl CargoWorkspace { |
@@ -155,11 +161,13 @@ impl CargoWorkspace { | |||
155 | let pkg_data = &mut packages[pkg]; | 161 | let pkg_data = &mut packages[pkg]; |
156 | pkg_by_id.insert(id, pkg); | 162 | pkg_by_id.insert(id, pkg); |
157 | for meta_tgt in meta_pkg.targets { | 163 | for meta_tgt in meta_pkg.targets { |
164 | let is_proc_macro = meta_tgt.kind.as_slice() == &["proc-macro"]; | ||
158 | let tgt = targets.alloc(TargetData { | 165 | let tgt = targets.alloc(TargetData { |
159 | pkg, | 166 | pkg, |
160 | name: meta_tgt.name, | 167 | name: meta_tgt.name, |
161 | root: meta_tgt.src_path.clone(), | 168 | root: meta_tgt.src_path.clone(), |
162 | kind: TargetKind::new(meta_tgt.kind.as_slice()), | 169 | kind: TargetKind::new(meta_tgt.kind.as_slice()), |
170 | is_proc_macro, | ||
163 | }); | 171 | }); |
164 | pkg_data.targets.push(tgt); | 172 | pkg_data.targets.push(tgt); |
165 | } | 173 | } |
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 { | |||
210 | 210 | ||
211 | let libcore = sysroot.core().and_then(|it| sysroot_crates.get(&it).copied()); | 211 | let libcore = sysroot.core().and_then(|it| sysroot_crates.get(&it).copied()); |
212 | let libstd = sysroot.std().and_then(|it| sysroot_crates.get(&it).copied()); | 212 | let libstd = sysroot.std().and_then(|it| sysroot_crates.get(&it).copied()); |
213 | let libproc_macro = | ||
214 | sysroot.proc_macro().and_then(|it| sysroot_crates.get(&it).copied()); | ||
213 | 215 | ||
214 | let mut pkg_to_lib_crate = FxHashMap::default(); | 216 | let mut pkg_to_lib_crate = FxHashMap::default(); |
215 | let mut pkg_crates = FxHashMap::default(); | 217 | let mut pkg_crates = FxHashMap::default(); |
@@ -236,6 +238,21 @@ impl ProjectWorkspace { | |||
236 | lib_tgt = Some(crate_id); | 238 | lib_tgt = Some(crate_id); |
237 | pkg_to_lib_crate.insert(pkg, crate_id); | 239 | pkg_to_lib_crate.insert(pkg, crate_id); |
238 | } | 240 | } |
241 | if tgt.is_proc_macro(&cargo) { | ||
242 | if let Some(proc_macro) = libproc_macro { | ||
243 | if let Err(_) = crate_graph.add_dep( | ||
244 | crate_id, | ||
245 | "proc_macro".into(), | ||
246 | proc_macro, | ||
247 | ) { | ||
248 | log::error!( | ||
249 | "cyclic dependency on proc_macro for {}", | ||
250 | pkg.name(&cargo) | ||
251 | ) | ||
252 | } | ||
253 | } | ||
254 | } | ||
255 | |||
239 | pkg_crates.entry(pkg).or_insert_with(Vec::new).push(crate_id); | 256 | pkg_crates.entry(pkg).or_insert_with(Vec::new).push(crate_id); |
240 | } | 257 | } |
241 | } | 258 | } |
diff --git a/crates/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs index 3d827809e..8a7757c41 100644 --- a/crates/ra_project_model/src/sysroot.rs +++ b/crates/ra_project_model/src/sysroot.rs | |||
@@ -35,6 +35,10 @@ impl Sysroot { | |||
35 | self.by_name("std") | 35 | self.by_name("std") |
36 | } | 36 | } |
37 | 37 | ||
38 | pub fn proc_macro(&self) -> Option<SysrootCrate> { | ||
39 | self.by_name("proc_macro") | ||
40 | } | ||
41 | |||
38 | pub fn crates<'a>(&'a self) -> impl Iterator<Item = SysrootCrate> + ExactSizeIterator + 'a { | 42 | pub fn crates<'a>(&'a self) -> impl Iterator<Item = SysrootCrate> + ExactSizeIterator + 'a { |
39 | self.crates.iter().map(|(id, _data)| id) | 43 | self.crates.iter().map(|(id, _data)| id) |
40 | } | 44 | } |
@@ -70,7 +74,7 @@ impl Sysroot { | |||
70 | } | 74 | } |
71 | } | 75 | } |
72 | if let Some(alloc) = sysroot.by_name("alloc") { | 76 | if let Some(alloc) = sysroot.by_name("alloc") { |
73 | if let Some(core) = sysroot.by_name("core") { | 77 | if let Some(core) = sysroot.core() { |
74 | sysroot.crates[alloc].deps.push(core); | 78 | sysroot.crates[alloc].deps.push(core); |
75 | } | 79 | } |
76 | } | 80 | } |