Skip to content

Commit 4cfe007

Browse files
Merge #4864
4864: Add optional target to crates in json project r=Nashenas88 a=Nashenas88 Lookup default cfgs per target when generating cfg list. Should fully address #4840 CC @woody77 Co-authored-by: Paul Daniel Faria <[email protected]> Co-authored-by: Paul Daniel Faria <[email protected]>
2 parents c815d5b + 5b96d41 commit 4cfe007

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

crates/ra_cfg/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,14 @@ impl CfgOptions {
4646
pub fn insert_key_value(&mut self, key: SmolStr, value: SmolStr) {
4747
self.key_values.insert((key, value));
4848
}
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+
}
4959
}

crates/ra_project_model/src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ impl ProjectWorkspace {
246246
let mut crate_graph = CrateGraph::default();
247247
match self {
248248
ProjectWorkspace::Json { project } => {
249+
let mut target_cfg_map = FxHashMap::<Option<&str>, CfgOptions>::default();
249250
let crates: FxHashMap<_, _> = project
250251
.crates
251252
.iter()
@@ -265,6 +266,14 @@ impl ProjectWorkspace {
265266
.proc_macro_dylib_path
266267
.clone()
267268
.map(|it| proc_macro_client.by_dylib_path(&it));
269+
270+
let target = krate.target.as_deref().or(target);
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+
268277
// FIXME: No crate name in json definition such that we cannot add OUT_DIR to env
269278
Some((
270279
CrateId(seq_index as u32),
@@ -273,7 +282,7 @@ impl ProjectWorkspace {
273282
krate.edition,
274283
// FIXME json definitions can store the crate name
275284
None,
276-
krate.cfg.clone(),
285+
cfg_options,
277286
env,
278287
proc_macro.unwrap_or_default(),
279288
),

crates/ra_project_model/src/project_json.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub struct Crate {
3131
pub(crate) edition: Edition,
3232
pub(crate) deps: Vec<Dependency>,
3333
pub(crate) cfg: CfgOptions,
34+
pub(crate) target: Option<String>,
3435
pub(crate) out_dir: Option<AbsPathBuf>,
3536
pub(crate) proc_macro_dylib_path: Option<AbsPathBuf>,
3637
}
@@ -65,6 +66,7 @@ impl ProjectJson {
6566
}
6667
cfg
6768
},
69+
target: crate_data.target,
6870
out_dir: crate_data.out_dir.map(|it| base.join(it)),
6971
proc_macro_dylib_path: crate_data.proc_macro_dylib_path.map(|it| base.join(it)),
7072
})
@@ -86,6 +88,7 @@ struct CrateData {
8688
deps: Vec<DepData>,
8789
#[serde(default)]
8890
cfg: FxHashSet<String>,
91+
target: Option<String>,
8992
out_dir: Option<PathBuf>,
9093
proc_macro_dylib_path: Option<PathBuf>,
9194
}

0 commit comments

Comments
 (0)