diff options
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r-- | crates/ra_project_model/src/cargo_workspace.rs | 15 | ||||
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 1 |
2 files changed, 14 insertions, 2 deletions
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index 59f46a2a0..16fff9f1c 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs | |||
@@ -87,6 +87,7 @@ pub struct PackageData { | |||
87 | pub dependencies: Vec<PackageDependency>, | 87 | pub dependencies: Vec<PackageDependency>, |
88 | pub edition: Edition, | 88 | pub edition: Edition, |
89 | pub features: Vec<String>, | 89 | pub features: Vec<String>, |
90 | pub cfgs: Vec<String>, | ||
90 | pub out_dir: Option<PathBuf>, | 91 | pub out_dir: Option<PathBuf>, |
91 | pub proc_macro_dylib_path: Option<PathBuf>, | 92 | pub proc_macro_dylib_path: Option<PathBuf>, |
92 | } | 93 | } |
@@ -172,10 +173,12 @@ impl CargoWorkspace { | |||
172 | })?; | 173 | })?; |
173 | 174 | ||
174 | let mut out_dir_by_id = FxHashMap::default(); | 175 | let mut out_dir_by_id = FxHashMap::default(); |
176 | let mut cfgs = FxHashMap::default(); | ||
175 | let mut proc_macro_dylib_paths = FxHashMap::default(); | 177 | let mut proc_macro_dylib_paths = FxHashMap::default(); |
176 | if cargo_features.load_out_dirs_from_check { | 178 | if cargo_features.load_out_dirs_from_check { |
177 | let resources = load_extern_resources(cargo_toml, cargo_features)?; | 179 | let resources = load_extern_resources(cargo_toml, cargo_features)?; |
178 | out_dir_by_id = resources.out_dirs; | 180 | out_dir_by_id = resources.out_dirs; |
181 | cfgs = resources.cfgs; | ||
179 | proc_macro_dylib_paths = resources.proc_dylib_paths; | 182 | proc_macro_dylib_paths = resources.proc_dylib_paths; |
180 | } | 183 | } |
181 | 184 | ||
@@ -201,6 +204,7 @@ impl CargoWorkspace { | |||
201 | edition, | 204 | edition, |
202 | dependencies: Vec::new(), | 205 | dependencies: Vec::new(), |
203 | features: Vec::new(), | 206 | features: Vec::new(), |
207 | cfgs: cfgs.get(&id).cloned().unwrap_or_default(), | ||
204 | out_dir: out_dir_by_id.get(&id).cloned(), | 208 | out_dir: out_dir_by_id.get(&id).cloned(), |
205 | proc_macro_dylib_path: proc_macro_dylib_paths.get(&id).cloned(), | 209 | proc_macro_dylib_path: proc_macro_dylib_paths.get(&id).cloned(), |
206 | }); | 210 | }); |
@@ -282,6 +286,7 @@ impl CargoWorkspace { | |||
282 | pub struct ExternResources { | 286 | pub struct ExternResources { |
283 | out_dirs: FxHashMap<PackageId, PathBuf>, | 287 | out_dirs: FxHashMap<PackageId, PathBuf>, |
284 | proc_dylib_paths: FxHashMap<PackageId, PathBuf>, | 288 | proc_dylib_paths: FxHashMap<PackageId, PathBuf>, |
289 | cfgs: FxHashMap<PackageId, Vec<String>>, | ||
285 | } | 290 | } |
286 | 291 | ||
287 | pub fn load_extern_resources( | 292 | pub fn load_extern_resources( |
@@ -307,8 +312,14 @@ pub fn load_extern_resources( | |||
307 | for message in cargo_metadata::parse_messages(output.stdout.as_slice()) { | 312 | for message in cargo_metadata::parse_messages(output.stdout.as_slice()) { |
308 | if let Ok(message) = message { | 313 | if let Ok(message) = message { |
309 | match message { | 314 | match message { |
310 | Message::BuildScriptExecuted(BuildScript { package_id, out_dir, .. }) => { | 315 | Message::BuildScriptExecuted(BuildScript { package_id, out_dir, cfgs, .. }) => { |
311 | res.out_dirs.insert(package_id, out_dir); | 316 | res.out_dirs.insert(package_id.clone(), out_dir); |
317 | res.cfgs.insert( | ||
318 | package_id, | ||
319 | // FIXME: Current `cargo_metadata` uses `PathBuf` instead of `String`, | ||
320 | // change when https://github.com/oli-obk/cargo_metadata/pulls/112 reaches crates.io | ||
321 | cfgs.iter().filter_map(|c| c.to_str().map(|s| s.to_owned())).collect(), | ||
322 | ); | ||
312 | } | 323 | } |
313 | 324 | ||
314 | Message::CompilerArtifact(message) => { | 325 | Message::CompilerArtifact(message) => { |
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index c2b33c1dc..8703429d4 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -399,6 +399,7 @@ impl ProjectWorkspace { | |||
399 | let cfg_options = { | 399 | let cfg_options = { |
400 | let mut opts = default_cfg_options.clone(); | 400 | let mut opts = default_cfg_options.clone(); |
401 | opts.insert_features(cargo[pkg].features.iter().map(Into::into)); | 401 | opts.insert_features(cargo[pkg].features.iter().map(Into::into)); |
402 | opts.insert_cfgs(cargo[pkg].cfgs.iter().map(Into::into)); | ||
402 | opts | 403 | opts |
403 | }; | 404 | }; |
404 | let mut env = Env::default(); | 405 | let mut env = Env::default(); |