diff options
Diffstat (limited to 'crates/ra_project_model/src')
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 37845ca56..a6274709d 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -14,7 +14,7 @@ use std::{ | |||
14 | 14 | ||
15 | use anyhow::{bail, Context, Result}; | 15 | use anyhow::{bail, Context, Result}; |
16 | use ra_cfg::CfgOptions; | 16 | use ra_cfg::CfgOptions; |
17 | use ra_db::{CrateGraph, CrateName, Edition, Env, FileId}; | 17 | use ra_db::{CrateGraph, CrateName, Edition, Env, ExternSource, ExternSourceId, FileId}; |
18 | use rustc_hash::FxHashMap; | 18 | use rustc_hash::FxHashMap; |
19 | use serde_json::from_reader; | 19 | use serde_json::from_reader; |
20 | 20 | ||
@@ -162,6 +162,7 @@ impl ProjectWorkspace { | |||
162 | pub fn to_crate_graph( | 162 | pub fn to_crate_graph( |
163 | &self, | 163 | &self, |
164 | default_cfg_options: &CfgOptions, | 164 | default_cfg_options: &CfgOptions, |
165 | outdirs: &FxHashMap<String, (ExternSourceId, String)>, | ||
165 | load: &mut dyn FnMut(&Path) -> Option<FileId>, | 166 | load: &mut dyn FnMut(&Path) -> Option<FileId>, |
166 | ) -> CrateGraph { | 167 | ) -> CrateGraph { |
167 | let mut crate_graph = CrateGraph::default(); | 168 | let mut crate_graph = CrateGraph::default(); |
@@ -185,6 +186,8 @@ impl ProjectWorkspace { | |||
185 | } | 186 | } |
186 | opts | 187 | opts |
187 | }; | 188 | }; |
189 | |||
190 | // FIXME: No crate name in json definition such that we cannot add OUT_DIR to env | ||
188 | crates.insert( | 191 | crates.insert( |
189 | crate_id, | 192 | crate_id, |
190 | crate_graph.add_crate_root( | 193 | crate_graph.add_crate_root( |
@@ -194,6 +197,7 @@ impl ProjectWorkspace { | |||
194 | None, | 197 | None, |
195 | cfg_options, | 198 | cfg_options, |
196 | Env::default(), | 199 | Env::default(), |
200 | Default::default(), | ||
197 | ), | 201 | ), |
198 | ); | 202 | ); |
199 | } | 203 | } |
@@ -231,12 +235,20 @@ impl ProjectWorkspace { | |||
231 | opts | 235 | opts |
232 | }; | 236 | }; |
233 | 237 | ||
238 | let mut env = Env::default(); | ||
239 | let mut extern_source = ExternSource::default(); | ||
240 | if let Some((id, path)) = outdirs.get(krate.name(&sysroot)) { | ||
241 | env.set("OUT_DIR", path.clone()); | ||
242 | extern_source.set_extern_path(&path, *id); | ||
243 | } | ||
244 | |||
234 | let crate_id = crate_graph.add_crate_root( | 245 | let crate_id = crate_graph.add_crate_root( |
235 | file_id, | 246 | file_id, |
236 | Edition::Edition2018, | 247 | Edition::Edition2018, |
237 | Some(krate.name(&sysroot).to_string()), | 248 | Some(krate.name(&sysroot).to_string()), |
238 | cfg_options, | 249 | cfg_options, |
239 | Env::default(), | 250 | env, |
251 | extern_source, | ||
240 | ); | 252 | ); |
241 | sysroot_crates.insert(krate, crate_id); | 253 | sysroot_crates.insert(krate, crate_id); |
242 | } | 254 | } |
@@ -275,12 +287,19 @@ impl ProjectWorkspace { | |||
275 | opts.insert_features(pkg.features(&cargo).iter().map(Into::into)); | 287 | opts.insert_features(pkg.features(&cargo).iter().map(Into::into)); |
276 | opts | 288 | opts |
277 | }; | 289 | }; |
290 | let mut env = Env::default(); | ||
291 | let mut extern_source = ExternSource::default(); | ||
292 | if let Some((id, path)) = outdirs.get(pkg.name(&cargo)) { | ||
293 | env.set("OUT_DIR", path.clone()); | ||
294 | extern_source.set_extern_path(&path, *id); | ||
295 | } | ||
278 | let crate_id = crate_graph.add_crate_root( | 296 | let crate_id = crate_graph.add_crate_root( |
279 | file_id, | 297 | file_id, |
280 | edition, | 298 | edition, |
281 | Some(pkg.name(&cargo).to_string()), | 299 | Some(pkg.name(&cargo).to_string()), |
282 | cfg_options, | 300 | cfg_options, |
283 | Env::default(), | 301 | env, |
302 | extern_source, | ||
284 | ); | 303 | ); |
285 | if tgt.kind(&cargo) == TargetKind::Lib { | 304 | if tgt.kind(&cargo) == TargetKind::Lib { |
286 | lib_tgt = Some(crate_id); | 305 | lib_tgt = Some(crate_id); |