aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model/src/cargo_workspace.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_project_model/src/cargo_workspace.rs')
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs31
1 files changed, 23 insertions, 8 deletions
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs
index c7f9bd873..291594e2a 100644
--- a/crates/ra_project_model/src/cargo_workspace.rs
+++ b/crates/ra_project_model/src/cargo_workspace.rs
@@ -83,6 +83,7 @@ pub struct PackageData {
83 pub edition: Edition, 83 pub edition: Edition,
84 pub features: Vec<String>, 84 pub features: Vec<String>,
85 pub out_dir: Option<PathBuf>, 85 pub out_dir: Option<PathBuf>,
86 pub proc_macro_dylib_path: Option<PathBuf>,
86} 87}
87 88
88#[derive(Debug, Clone)] 89#[derive(Debug, Clone)]
@@ -158,8 +159,11 @@ impl CargoWorkspace {
158 })?; 159 })?;
159 160
160 let mut out_dir_by_id = FxHashMap::default(); 161 let mut out_dir_by_id = FxHashMap::default();
162 let mut proc_macro_dylib_paths = FxHashMap::default();
161 if cargo_features.load_out_dirs_from_check { 163 if cargo_features.load_out_dirs_from_check {
162 out_dir_by_id = load_out_dirs(cargo_toml, cargo_features); 164 let resources = load_extern_resources(cargo_toml, cargo_features);
165 out_dir_by_id = resources.out_dirs;
166 proc_macro_dylib_paths = resources.proc_dylib_paths;
163 } 167 }
164 168
165 let mut pkg_by_id = FxHashMap::default(); 169 let mut pkg_by_id = FxHashMap::default();
@@ -183,6 +187,7 @@ impl CargoWorkspace {
183 dependencies: Vec::new(), 187 dependencies: Vec::new(),
184 features: Vec::new(), 188 features: Vec::new(),
185 out_dir: out_dir_by_id.get(&id).cloned(), 189 out_dir: out_dir_by_id.get(&id).cloned(),
190 proc_macro_dylib_path: proc_macro_dylib_paths.get(&id).cloned(),
186 }); 191 });
187 let pkg_data = &mut packages[pkg]; 192 let pkg_data = &mut packages[pkg];
188 pkg_by_id.insert(id, pkg); 193 pkg_by_id.insert(id, pkg);
@@ -246,10 +251,13 @@ impl CargoWorkspace {
246 } 251 }
247} 252}
248 253
249pub fn load_out_dirs( 254#[derive(Debug, Clone, Default)]
250 cargo_toml: &Path, 255pub struct ExternResources {
251 cargo_features: &CargoFeatures, 256 out_dirs: FxHashMap<PackageId, PathBuf>,
252) -> FxHashMap<PackageId, PathBuf> { 257 proc_dylib_paths: FxHashMap<PackageId, PathBuf>,
258}
259
260pub fn load_extern_resources(cargo_toml: &Path, cargo_features: &CargoFeatures) -> ExternResources {
253 let mut args: Vec<String> = vec![ 261 let mut args: Vec<String> = vec![
254 "check".to_string(), 262 "check".to_string(),
255 "--message-format=json".to_string(), 263 "--message-format=json".to_string(),
@@ -267,14 +275,21 @@ pub fn load_out_dirs(
267 args.extend(cargo_features.features.iter().cloned()); 275 args.extend(cargo_features.features.iter().cloned());
268 } 276 }
269 277
270 let mut acc = FxHashMap::default(); 278 let mut acc = ExternResources::default();
271 let res = run_cargo(&args, cargo_toml.parent(), &mut |message| { 279 let res = run_cargo(&args, cargo_toml.parent(), &mut |message| {
272 match message { 280 match message {
273 Message::BuildScriptExecuted(BuildScript { package_id, out_dir, .. }) => { 281 Message::BuildScriptExecuted(BuildScript { package_id, out_dir, .. }) => {
274 acc.insert(package_id, out_dir); 282 acc.out_dirs.insert(package_id, out_dir);
275 } 283 }
276 284
277 Message::CompilerArtifact(_) => (), 285 Message::CompilerArtifact(message) => {
286 if message.target.kind.contains(&"proc-macro".to_string()) {
287 let package_id = message.package_id;
288 if let Some(filename) = message.filenames.get(0) {
289 acc.proc_dylib_paths.insert(package_id, filename.clone());
290 }
291 }
292 }
278 Message::CompilerMessage(_) => (), 293 Message::CompilerMessage(_) => (),
279 Message::Unknown => (), 294 Message::Unknown => (),
280 } 295 }