aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs15
-rw-r--r--crates/ra_project_model/src/lib.rs13
2 files changed, 25 insertions, 3 deletions
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs
index 4027f020f..eb9f33ee8 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}
@@ -168,10 +169,12 @@ impl CargoWorkspace {
168 })?; 169 })?;
169 170
170 let mut out_dir_by_id = FxHashMap::default(); 171 let mut out_dir_by_id = FxHashMap::default();
172 let mut cfgs = FxHashMap::default();
171 let mut proc_macro_dylib_paths = FxHashMap::default(); 173 let mut proc_macro_dylib_paths = FxHashMap::default();
172 if cargo_features.load_out_dirs_from_check { 174 if cargo_features.load_out_dirs_from_check {
173 let resources = load_extern_resources(cargo_toml, cargo_features)?; 175 let resources = load_extern_resources(cargo_toml, cargo_features)?;
174 out_dir_by_id = resources.out_dirs; 176 out_dir_by_id = resources.out_dirs;
177 cfgs = resources.cfgs;
175 proc_macro_dylib_paths = resources.proc_dylib_paths; 178 proc_macro_dylib_paths = resources.proc_dylib_paths;
176 } 179 }
177 180
@@ -197,6 +200,7 @@ impl CargoWorkspace {
197 edition, 200 edition,
198 dependencies: Vec::new(), 201 dependencies: Vec::new(),
199 features: Vec::new(), 202 features: Vec::new(),
203 cfgs: cfgs.get(&id).cloned().unwrap_or_default(),
200 out_dir: out_dir_by_id.get(&id).cloned(), 204 out_dir: out_dir_by_id.get(&id).cloned(),
201 proc_macro_dylib_path: proc_macro_dylib_paths.get(&id).cloned(), 205 proc_macro_dylib_path: proc_macro_dylib_paths.get(&id).cloned(),
202 }); 206 });
@@ -278,6 +282,7 @@ impl CargoWorkspace {
278pub struct ExternResources { 282pub struct ExternResources {
279 out_dirs: FxHashMap<PackageId, PathBuf>, 283 out_dirs: FxHashMap<PackageId, PathBuf>,
280 proc_dylib_paths: FxHashMap<PackageId, PathBuf>, 284 proc_dylib_paths: FxHashMap<PackageId, PathBuf>,
285 cfgs: FxHashMap<PackageId, Vec<String>>,
281} 286}
282 287
283pub fn load_extern_resources( 288pub fn load_extern_resources(
@@ -303,8 +308,14 @@ pub fn load_extern_resources(
303 for message in cargo_metadata::parse_messages(output.stdout.as_slice()) { 308 for message in cargo_metadata::parse_messages(output.stdout.as_slice()) {
304 if let Ok(message) = message { 309 if let Ok(message) = message {
305 match message { 310 match message {
306 Message::BuildScriptExecuted(BuildScript { package_id, out_dir, .. }) => { 311 Message::BuildScriptExecuted(BuildScript { package_id, out_dir, cfgs, .. }) => {
307 res.out_dirs.insert(package_id, out_dir); 312 res.out_dirs.insert(package_id.clone(), out_dir);
313 res.cfgs.insert(
314 package_id,
315 // FIXME: Current `cargo_metadata` uses `PathBuf` instead of `String`,
316 // change when https://github.com/oli-obk/cargo_metadata/pulls/112 reaches crates.io
317 cfgs.iter().filter_map(|c| c.to_str().map(|s| s.to_owned())).collect(),
318 );
308 } 319 }
309 320
310 Message::CompilerArtifact(message) => { 321 Message::CompilerArtifact(message) => {
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index e4b86f1e2..88a6ffb2a 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -399,7 +399,18 @@ impl ProjectWorkspace {
399 let edition = cargo[pkg].edition; 399 let edition = cargo[pkg].edition;
400 let cfg_options = { 400 let cfg_options = {
401 let mut opts = default_cfg_options.clone(); 401 let mut opts = default_cfg_options.clone();
402 opts.insert_features(cargo[pkg].features.iter().map(Into::into)); 402 for feature in cargo[pkg].features.iter() {
403 opts.insert_key_value("feature".into(), feature.into());
404 }
405 for cfg in cargo[pkg].cfgs.iter() {
406 match cfg.find('=') {
407 Some(split) => opts.insert_key_value(
408 cfg[..split].into(),
409 cfg[split + 1..].trim_matches('"').into(),
410 ),
411 None => opts.insert_atom(cfg.into()),
412 };
413 }
403 opts 414 opts
404 }; 415 };
405 let mut env = Env::default(); 416 let mut env = Env::default();