diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-26 17:09:32 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-26 17:09:32 +0000 |
commit | b1594f108041813c9fa32538950c15c55202cbd5 (patch) | |
tree | cef1e662a7acf2807422e7c232014c5326ac37b6 /crates/ra_project_model/src/lib.rs | |
parent | 20c110e57f24aa54154942ee40921e9129fbc595 (diff) | |
parent | db162df264a222021dbc7f1f93af94029f3948d9 (diff) |
Merge #3727
3727: Introduce ra_proc_macro r=matklad a=edwin0cheng
This PR implemented:
1. Reading dylib path of proc-macro crate from cargo check , similar to how `OUTDIR` is obtained.
2. Added a new crate `ra_proc_macro` and implement the foot-work for reading result from external proc-macro expander.
3. Added a struct `ProcMacroClient` , which will be responsible to the client side communication to the External process.
Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_project_model/src/lib.rs')
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index a3ef9acdc..444d3bb3f 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -23,6 +23,7 @@ pub use crate::{ | |||
23 | json_project::JsonProject, | 23 | json_project::JsonProject, |
24 | sysroot::Sysroot, | 24 | sysroot::Sysroot, |
25 | }; | 25 | }; |
26 | pub use ra_proc_macro::ProcMacroClient; | ||
26 | 27 | ||
27 | #[derive(Clone, PartialEq, Eq, Hash, Debug)] | 28 | #[derive(Clone, PartialEq, Eq, Hash, Debug)] |
28 | pub struct CargoTomlNotFoundError { | 29 | pub struct CargoTomlNotFoundError { |
@@ -173,6 +174,29 @@ impl ProjectWorkspace { | |||
173 | } | 174 | } |
174 | } | 175 | } |
175 | 176 | ||
177 | pub fn proc_macro_dylib_paths(&self) -> Vec<PathBuf> { | ||
178 | match self { | ||
179 | ProjectWorkspace::Json { project } => { | ||
180 | let mut proc_macro_dylib_paths = Vec::with_capacity(project.crates.len()); | ||
181 | for krate in &project.crates { | ||
182 | if let Some(out_dir) = &krate.proc_macro_dylib_path { | ||
183 | proc_macro_dylib_paths.push(out_dir.to_path_buf()); | ||
184 | } | ||
185 | } | ||
186 | proc_macro_dylib_paths | ||
187 | } | ||
188 | ProjectWorkspace::Cargo { cargo, sysroot: _sysroot } => { | ||
189 | let mut proc_macro_dylib_paths = Vec::with_capacity(cargo.packages().len()); | ||
190 | for pkg in cargo.packages() { | ||
191 | if let Some(dylib_path) = &cargo[pkg].proc_macro_dylib_path { | ||
192 | proc_macro_dylib_paths.push(dylib_path.to_path_buf()); | ||
193 | } | ||
194 | } | ||
195 | proc_macro_dylib_paths | ||
196 | } | ||
197 | } | ||
198 | } | ||
199 | |||
176 | pub fn n_packages(&self) -> usize { | 200 | pub fn n_packages(&self) -> usize { |
177 | match self { | 201 | match self { |
178 | ProjectWorkspace::Json { project } => project.crates.len(), | 202 | ProjectWorkspace::Json { project } => project.crates.len(), |
@@ -186,6 +210,7 @@ impl ProjectWorkspace { | |||
186 | &self, | 210 | &self, |
187 | default_cfg_options: &CfgOptions, | 211 | default_cfg_options: &CfgOptions, |
188 | extern_source_roots: &FxHashMap<PathBuf, ExternSourceId>, | 212 | extern_source_roots: &FxHashMap<PathBuf, ExternSourceId>, |
213 | proc_macro_client: &ProcMacroClient, | ||
189 | load: &mut dyn FnMut(&Path) -> Option<FileId>, | 214 | load: &mut dyn FnMut(&Path) -> Option<FileId>, |
190 | ) -> CrateGraph { | 215 | ) -> CrateGraph { |
191 | let mut crate_graph = CrateGraph::default(); | 216 | let mut crate_graph = CrateGraph::default(); |
@@ -219,7 +244,10 @@ impl ProjectWorkspace { | |||
219 | extern_source.set_extern_path(&out_dir, extern_source_id); | 244 | extern_source.set_extern_path(&out_dir, extern_source_id); |
220 | } | 245 | } |
221 | } | 246 | } |
222 | 247 | let proc_macro = krate | |
248 | .proc_macro_dylib_path | ||
249 | .clone() | ||
250 | .map(|it| proc_macro_client.by_dylib_path(&it)); | ||
223 | // FIXME: No crate name in json definition such that we cannot add OUT_DIR to env | 251 | // FIXME: No crate name in json definition such that we cannot add OUT_DIR to env |
224 | crates.insert( | 252 | crates.insert( |
225 | crate_id, | 253 | crate_id, |
@@ -231,6 +259,7 @@ impl ProjectWorkspace { | |||
231 | cfg_options, | 259 | cfg_options, |
232 | env, | 260 | env, |
233 | extern_source, | 261 | extern_source, |
262 | proc_macro.unwrap_or_default(), | ||
234 | ), | 263 | ), |
235 | ); | 264 | ); |
236 | } | 265 | } |
@@ -270,6 +299,8 @@ impl ProjectWorkspace { | |||
270 | 299 | ||
271 | let env = Env::default(); | 300 | let env = Env::default(); |
272 | let extern_source = ExternSource::default(); | 301 | let extern_source = ExternSource::default(); |
302 | let proc_macro = vec![]; | ||
303 | |||
273 | let crate_id = crate_graph.add_crate_root( | 304 | let crate_id = crate_graph.add_crate_root( |
274 | file_id, | 305 | file_id, |
275 | Edition::Edition2018, | 306 | Edition::Edition2018, |
@@ -280,6 +311,7 @@ impl ProjectWorkspace { | |||
280 | cfg_options, | 311 | cfg_options, |
281 | env, | 312 | env, |
282 | extern_source, | 313 | extern_source, |
314 | proc_macro, | ||
283 | ); | 315 | ); |
284 | sysroot_crates.insert(krate, crate_id); | 316 | sysroot_crates.insert(krate, crate_id); |
285 | } | 317 | } |
@@ -327,6 +359,12 @@ impl ProjectWorkspace { | |||
327 | extern_source.set_extern_path(&out_dir, extern_source_id); | 359 | extern_source.set_extern_path(&out_dir, extern_source_id); |
328 | } | 360 | } |
329 | } | 361 | } |
362 | let proc_macro = cargo[pkg] | ||
363 | .proc_macro_dylib_path | ||
364 | .as_ref() | ||
365 | .map(|it| proc_macro_client.by_dylib_path(&it)) | ||
366 | .unwrap_or_default(); | ||
367 | |||
330 | let crate_id = crate_graph.add_crate_root( | 368 | let crate_id = crate_graph.add_crate_root( |
331 | file_id, | 369 | file_id, |
332 | edition, | 370 | edition, |
@@ -334,6 +372,7 @@ impl ProjectWorkspace { | |||
334 | cfg_options, | 372 | cfg_options, |
335 | env, | 373 | env, |
336 | extern_source, | 374 | extern_source, |
375 | proc_macro.clone(), | ||
337 | ); | 376 | ); |
338 | if cargo[tgt].kind == TargetKind::Lib { | 377 | if cargo[tgt].kind == TargetKind::Lib { |
339 | lib_tgt = Some((crate_id, cargo[tgt].name.clone())); | 378 | lib_tgt = Some((crate_id, cargo[tgt].name.clone())); |