diff options
author | Paul Daniel Faria <[email protected]> | 2020-06-12 18:08:51 +0100 |
---|---|---|
committer | Paul Daniel Faria <[email protected]> | 2020-07-04 18:49:44 +0100 |
commit | db99f2dd7e8e244b858926bbf1d2a49e25f44733 (patch) | |
tree | 8c57a0a494e1a6e6250b5081276f57e8467a92cd | |
parent | c815d5b49660e9b93c6a70039abef5fa02ae8013 (diff) |
Add optional target to crates in json project, lookup default cfgs per target when generating cfg list
-rw-r--r-- | crates/ra_cfg/src/lib.rs | 10 | ||||
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 11 | ||||
-rw-r--r-- | crates/ra_project_model/src/project_json.rs | 3 |
3 files changed, 23 insertions, 1 deletions
diff --git a/crates/ra_cfg/src/lib.rs b/crates/ra_cfg/src/lib.rs index 57feabcb2..f9c73ece1 100644 --- a/crates/ra_cfg/src/lib.rs +++ b/crates/ra_cfg/src/lib.rs | |||
@@ -46,4 +46,14 @@ impl CfgOptions { | |||
46 | pub fn insert_key_value(&mut self, key: SmolStr, value: SmolStr) { | 46 | pub fn insert_key_value(&mut self, key: SmolStr, value: SmolStr) { |
47 | self.key_values.insert((key, value)); | 47 | self.key_values.insert((key, value)); |
48 | } | 48 | } |
49 | |||
50 | pub fn append(&mut self, other: &CfgOptions) { | ||
51 | for atom in &other.atoms { | ||
52 | self.atoms.insert(atom.clone()); | ||
53 | } | ||
54 | |||
55 | for (key, value) in &other.key_values { | ||
56 | self.key_values.insert((key.clone(), value.clone())); | ||
57 | } | ||
58 | } | ||
49 | } | 59 | } |
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 464c3b2e3..4b50b9b69 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -246,6 +246,7 @@ impl ProjectWorkspace { | |||
246 | let mut crate_graph = CrateGraph::default(); | 246 | let mut crate_graph = CrateGraph::default(); |
247 | match self { | 247 | match self { |
248 | ProjectWorkspace::Json { project } => { | 248 | ProjectWorkspace::Json { project } => { |
249 | let mut target_cfg_map = FxHashMap::<Option<&str>, CfgOptions>::default(); | ||
249 | let crates: FxHashMap<_, _> = project | 250 | let crates: FxHashMap<_, _> = project |
250 | .crates | 251 | .crates |
251 | .iter() | 252 | .iter() |
@@ -265,6 +266,14 @@ impl ProjectWorkspace { | |||
265 | .proc_macro_dylib_path | 266 | .proc_macro_dylib_path |
266 | .clone() | 267 | .clone() |
267 | .map(|it| proc_macro_client.by_dylib_path(&it)); | 268 | .map(|it| proc_macro_client.by_dylib_path(&it)); |
269 | |||
270 | let target = krate.target.as_deref(); | ||
271 | let target_cfgs = target_cfg_map | ||
272 | .entry(target.clone()) | ||
273 | .or_insert_with(|| get_rustc_cfg_options(target.as_deref())); | ||
274 | let mut cfg_options = krate.cfg.clone(); | ||
275 | cfg_options.append(target_cfgs); | ||
276 | |||
268 | // FIXME: No crate name in json definition such that we cannot add OUT_DIR to env | 277 | // FIXME: No crate name in json definition such that we cannot add OUT_DIR to env |
269 | Some(( | 278 | Some(( |
270 | CrateId(seq_index as u32), | 279 | CrateId(seq_index as u32), |
@@ -273,7 +282,7 @@ impl ProjectWorkspace { | |||
273 | krate.edition, | 282 | krate.edition, |
274 | // FIXME json definitions can store the crate name | 283 | // FIXME json definitions can store the crate name |
275 | None, | 284 | None, |
276 | krate.cfg.clone(), | 285 | cfg_options, |
277 | env, | 286 | env, |
278 | proc_macro.unwrap_or_default(), | 287 | proc_macro.unwrap_or_default(), |
279 | ), | 288 | ), |
diff --git a/crates/ra_project_model/src/project_json.rs b/crates/ra_project_model/src/project_json.rs index b0fe09333..b96227949 100644 --- a/crates/ra_project_model/src/project_json.rs +++ b/crates/ra_project_model/src/project_json.rs | |||
@@ -31,6 +31,7 @@ pub struct Crate { | |||
31 | pub(crate) edition: Edition, | 31 | pub(crate) edition: Edition, |
32 | pub(crate) deps: Vec<Dependency>, | 32 | pub(crate) deps: Vec<Dependency>, |
33 | pub(crate) cfg: CfgOptions, | 33 | pub(crate) cfg: CfgOptions, |
34 | pub(crate) target: Option<String>, | ||
34 | pub(crate) out_dir: Option<AbsPathBuf>, | 35 | pub(crate) out_dir: Option<AbsPathBuf>, |
35 | pub(crate) proc_macro_dylib_path: Option<AbsPathBuf>, | 36 | pub(crate) proc_macro_dylib_path: Option<AbsPathBuf>, |
36 | } | 37 | } |
@@ -65,6 +66,7 @@ impl ProjectJson { | |||
65 | } | 66 | } |
66 | cfg | 67 | cfg |
67 | }, | 68 | }, |
69 | target: crate_data.target, | ||
68 | out_dir: crate_data.out_dir.map(|it| base.join(it)), | 70 | out_dir: crate_data.out_dir.map(|it| base.join(it)), |
69 | proc_macro_dylib_path: crate_data.proc_macro_dylib_path.map(|it| base.join(it)), | 71 | proc_macro_dylib_path: crate_data.proc_macro_dylib_path.map(|it| base.join(it)), |
70 | }) | 72 | }) |
@@ -86,6 +88,7 @@ struct CrateData { | |||
86 | deps: Vec<DepData>, | 88 | deps: Vec<DepData>, |
87 | #[serde(default)] | 89 | #[serde(default)] |
88 | cfg: FxHashSet<String>, | 90 | cfg: FxHashSet<String>, |
91 | target: Option<String>, | ||
89 | out_dir: Option<PathBuf>, | 92 | out_dir: Option<PathBuf>, |
90 | proc_macro_dylib_path: Option<PathBuf>, | 93 | proc_macro_dylib_path: Option<PathBuf>, |
91 | } | 94 | } |