Merge pull request #18885 from qjerome/refactor-cargo-cfgs

refactor: struct holding cargo cfgs settings
This commit is contained in:
Lukas Wirth 2025-01-09 10:19:55 +00:00 committed by GitHub
commit 5c106b4efa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 14 deletions

View file

@ -571,11 +571,8 @@ config_data! {
/// avoid checking unnecessary things. /// avoid checking unnecessary things.
cargo_buildScripts_useRustcWrapper: bool = true, cargo_buildScripts_useRustcWrapper: bool = true,
/// List of cfg options to enable with the given values. /// List of cfg options to enable with the given values.
cargo_cfgs: FxHashMap<String, Option<String>> = { cargo_cfgs: Vec<String> = {
let mut m = FxHashMap::default(); vec!["debug_assertion".into(), "miri".into()]
m.insert("debug_assertions".to_owned(), None);
m.insert("miri".to_owned(), None);
m
}, },
/// Extra arguments that are passed to every cargo invocation. /// Extra arguments that are passed to every cargo invocation.
cargo_extraArgs: Vec<String> = vec![], cargo_extraArgs: Vec<String> = vec![],
@ -1944,6 +1941,13 @@ impl Config {
global: CfgDiff::new( global: CfgDiff::new(
self.cargo_cfgs(source_root) self.cargo_cfgs(source_root)
.iter() .iter()
// parse any cfg setting formatted as key=value or just key (without value)
.filter_map(|s| {
let mut sp = s.splitn(2, "=");
let key = sp.next();
let val = sp.next();
key.map(|key| (key, val))
})
.map(|(key, val)| match val { .map(|(key, val)| match val {
Some(val) => CfgAtom::KeyValue { Some(val) => CfgAtom::KeyValue {
key: Symbol::intern(key), key: Symbol::intern(key),

View file

@ -94,10 +94,10 @@ avoid checking unnecessary things.
-- --
Default: Default:
---- ----
{ [
"miri": null, "debug_assertion",
"debug_assertions": null "miri"
} ]
---- ----
List of cfg options to enable with the given values. List of cfg options to enable with the given values.

View file

@ -791,11 +791,14 @@
"properties": { "properties": {
"rust-analyzer.cargo.cfgs": { "rust-analyzer.cargo.cfgs": {
"markdownDescription": "List of cfg options to enable with the given values.", "markdownDescription": "List of cfg options to enable with the given values.",
"default": { "default": [
"miri": null, "debug_assertion",
"debug_assertions": null "miri"
}, ],
"type": "object" "type": "array",
"items": {
"type": "string"
}
} }
} }
}, },