Set debug_assertions and miri cfgs as config defaults, allowing them to be overwritten

This commit is contained in:
Lukas Wirth 2024-04-19 11:06:55 +02:00
parent 8989dcffd6
commit 0485a85ee2
6 changed files with 35 additions and 14 deletions

View File

@ -1,3 +1,4 @@
//! Cargo-like environment variables injection.
use base_db::Env; use base_db::Env;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use toolchain::Tool; use toolchain::Tool;

View File

@ -32,9 +32,6 @@ pub(crate) fn get(
} }
} }
// Add miri cfg, which is useful for mir eval in stdlib
res.push(CfgFlag::Atom("miri".into()));
let rustc_cfgs = get_rust_cfgs(target, extra_env, config); let rustc_cfgs = get_rust_cfgs(target, extra_env, config);
let rustc_cfgs = match rustc_cfgs { let rustc_cfgs = match rustc_cfgs {

View File

@ -1454,8 +1454,14 @@ fn sysroot_to_crate_graph(
None, None,
rustc_cfg, rustc_cfg,
&CfgOverrides { &CfgOverrides {
global: CfgDiff::new(vec![CfgAtom::Flag("debug_assertions".into())], vec![]) global: CfgDiff::new(
.unwrap(), vec![
CfgAtom::Flag("debug_assertions".into()),
CfgAtom::Flag("miri".into()),
],
vec![],
)
.unwrap(),
..Default::default() ..Default::default()
}, },
&WorkspaceBuildScripts::default(), &WorkspaceBuildScripts::default(),
@ -1519,6 +1525,7 @@ fn sysroot_to_crate_graph(
let mut cfg_options = CfgOptions::default(); let mut cfg_options = CfgOptions::default();
cfg_options.extend(rustc_cfg); cfg_options.extend(rustc_cfg);
cfg_options.insert_atom("debug_assertions".into()); cfg_options.insert_atom("debug_assertions".into());
cfg_options.insert_atom("miri".into());
cfg_options cfg_options
}); });
let sysroot_crates: FxHashMap<SysrootCrate, CrateId> = stitched let sysroot_crates: FxHashMap<SysrootCrate, CrateId> = stitched

View File

@ -124,7 +124,12 @@
/// 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, String> = FxHashMap::default(), cargo_cfgs: FxHashMap<String, Option<String>> = {
let mut m = FxHashMap::default();
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![],
/// Extra environment variables that will be set when running cargo, rustc /// Extra environment variables that will be set when running cargo, rustc
@ -1591,12 +1596,9 @@ pub fn cargo(&self) -> CargoConfig {
global: CfgDiff::new( global: CfgDiff::new(
self.cargo_cfgs() self.cargo_cfgs()
.iter() .iter()
.map(|(key, val)| { .map(|(key, val)| match val {
if val.is_empty() { Some(val) => CfgAtom::KeyValue { key: key.into(), value: val.into() },
CfgAtom::Flag(key.into()) None => CfgAtom::Flag(key.into()),
} else {
CfgAtom::KeyValue { key: key.into(), value: val.into() }
}
}) })
.collect(), .collect(),
vec![], vec![],
@ -2667,6 +2669,9 @@ macro_rules! set {
"FxHashMap<Box<str>, usize>" => set! { "FxHashMap<Box<str>, usize>" => set! {
"type": "object", "type": "object",
}, },
"FxHashMap<String, Option<String>>" => set! {
"type": "object",
},
"Option<usize>" => set! { "Option<usize>" => set! {
"type": ["null", "integer"], "type": ["null", "integer"],
"minimum": 0, "minimum": 0,

View File

@ -88,10 +88,18 @@ or build-script sources change and are saved.
Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to
avoid checking unnecessary things. avoid checking unnecessary things.
-- --
[[rust-analyzer.cargo.cfgs]]rust-analyzer.cargo.cfgs (default: `{}`):: [[rust-analyzer.cargo.cfgs]]rust-analyzer.cargo.cfgs::
+ +
-- --
Default:
----
{
"debug_assertions": null,
"miri": null
}
----
List of cfg options to enable with the given values. List of cfg options to enable with the given values.
-- --
[[rust-analyzer.cargo.extraArgs]]rust-analyzer.cargo.extraArgs (default: `[]`):: [[rust-analyzer.cargo.extraArgs]]rust-analyzer.cargo.extraArgs (default: `[]`)::
+ +

View File

@ -610,7 +610,10 @@
}, },
"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": {
"debug_assertions": null,
"miri": null
},
"type": "object" "type": "object"
}, },
"rust-analyzer.cargo.extraArgs": { "rust-analyzer.cargo.extraArgs": {