mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 15:14:32 +00:00
Set debug_assertions and miri cfgs as config defaults, allowing them to be overwritten
This commit is contained in:
parent
8989dcffd6
commit
0485a85ee2
6 changed files with 35 additions and 14 deletions
|
@ -1,3 +1,4 @@
|
|||
//! Cargo-like environment variables injection.
|
||||
use base_db::Env;
|
||||
use rustc_hash::FxHashMap;
|
||||
use toolchain::Tool;
|
||||
|
|
|
@ -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 = match rustc_cfgs {
|
||||
|
|
|
@ -1454,8 +1454,14 @@ fn sysroot_to_crate_graph(
|
|||
None,
|
||||
rustc_cfg,
|
||||
&CfgOverrides {
|
||||
global: CfgDiff::new(vec![CfgAtom::Flag("debug_assertions".into())], vec![])
|
||||
.unwrap(),
|
||||
global: CfgDiff::new(
|
||||
vec![
|
||||
CfgAtom::Flag("debug_assertions".into()),
|
||||
CfgAtom::Flag("miri".into()),
|
||||
],
|
||||
vec![],
|
||||
)
|
||||
.unwrap(),
|
||||
..Default::default()
|
||||
},
|
||||
&WorkspaceBuildScripts::default(),
|
||||
|
@ -1519,6 +1525,7 @@ fn sysroot_to_crate_graph(
|
|||
let mut cfg_options = CfgOptions::default();
|
||||
cfg_options.extend(rustc_cfg);
|
||||
cfg_options.insert_atom("debug_assertions".into());
|
||||
cfg_options.insert_atom("miri".into());
|
||||
cfg_options
|
||||
});
|
||||
let sysroot_crates: FxHashMap<SysrootCrate, CrateId> = stitched
|
||||
|
|
|
@ -124,7 +124,12 @@ config_data! {
|
|||
/// avoid checking unnecessary things.
|
||||
cargo_buildScripts_useRustcWrapper: bool = true,
|
||||
/// 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.
|
||||
cargo_extraArgs: Vec<String> = vec![],
|
||||
/// Extra environment variables that will be set when running cargo, rustc
|
||||
|
@ -1591,12 +1596,9 @@ impl Config {
|
|||
global: CfgDiff::new(
|
||||
self.cargo_cfgs()
|
||||
.iter()
|
||||
.map(|(key, val)| {
|
||||
if val.is_empty() {
|
||||
CfgAtom::Flag(key.into())
|
||||
} else {
|
||||
CfgAtom::KeyValue { key: key.into(), value: val.into() }
|
||||
}
|
||||
.map(|(key, val)| match val {
|
||||
Some(val) => CfgAtom::KeyValue { key: key.into(), value: val.into() },
|
||||
None => CfgAtom::Flag(key.into()),
|
||||
})
|
||||
.collect(),
|
||||
vec![],
|
||||
|
@ -2667,6 +2669,9 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
|
|||
"FxHashMap<Box<str>, usize>" => set! {
|
||||
"type": "object",
|
||||
},
|
||||
"FxHashMap<String, Option<String>>" => set! {
|
||||
"type": "object",
|
||||
},
|
||||
"Option<usize>" => set! {
|
||||
"type": ["null", "integer"],
|
||||
"minimum": 0,
|
||||
|
|
|
@ -88,10 +88,18 @@ or build-script sources change and are saved.
|
|||
Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to
|
||||
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.
|
||||
|
||||
--
|
||||
[[rust-analyzer.cargo.extraArgs]]rust-analyzer.cargo.extraArgs (default: `[]`)::
|
||||
+
|
||||
|
|
|
@ -610,7 +610,10 @@
|
|||
},
|
||||
"rust-analyzer.cargo.cfgs": {
|
||||
"markdownDescription": "List of cfg options to enable with the given values.",
|
||||
"default": {},
|
||||
"default": {
|
||||
"debug_assertions": null,
|
||||
"miri": null
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"rust-analyzer.cargo.extraArgs": {
|
||||
|
|
Loading…
Reference in a new issue