mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 21:54:42 +00:00
Pass cargo.target to rustc
This commit is contained in:
parent
0ab4340cdb
commit
14dde99627
3 changed files with 15 additions and 7 deletions
|
@ -543,7 +543,7 @@ impl ProjectWorkspace {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_rustc_cfg_options() -> CfgOptions {
|
||||
pub fn get_rustc_cfg_options(target: Option<&String>) -> CfgOptions {
|
||||
let mut cfg_options = CfgOptions::default();
|
||||
|
||||
// Some nightly-only cfgs, which are required for stdlib
|
||||
|
@ -558,10 +558,18 @@ pub fn get_rustc_cfg_options() -> CfgOptions {
|
|||
|
||||
match (|| -> Result<String> {
|
||||
// `cfg(test)` and `cfg(debug_assertion)` are handled outside, so we suppress them here.
|
||||
let output = Command::new("rustc")
|
||||
.args(&["--print", "cfg", "-O"])
|
||||
.output()
|
||||
.context("Failed to get output from rustc --print cfg -O")?;
|
||||
let output = if let Some(target) = target {
|
||||
Command::new("rustc")
|
||||
.args(&["--print", "cfg", "-O", "--target", target.as_str()])
|
||||
.output()
|
||||
.context("Failed to get output from rustc --print cfg -O")?
|
||||
} else {
|
||||
Command::new("rustc")
|
||||
.args(&["--print", "cfg", "-O"])
|
||||
.output()
|
||||
.context("Failed to get output from rustc --print cfg -O")?
|
||||
};
|
||||
|
||||
if !output.status.success() {
|
||||
bail!(
|
||||
"rustc --print cfg -O exited with exit code ({})",
|
||||
|
|
|
@ -149,7 +149,7 @@ pub(crate) fn load(
|
|||
|
||||
// FIXME: cfg options?
|
||||
let default_cfg_options = {
|
||||
let mut opts = get_rustc_cfg_options();
|
||||
let mut opts = get_rustc_cfg_options(None);
|
||||
opts.insert_atom("test".into());
|
||||
opts.insert_atom("debug_assertion".into());
|
||||
opts
|
||||
|
|
|
@ -131,7 +131,7 @@ impl WorldState {
|
|||
|
||||
// FIXME: Read default cfgs from config
|
||||
let default_cfg_options = {
|
||||
let mut opts = get_rustc_cfg_options();
|
||||
let mut opts = get_rustc_cfg_options(config.cargo.target.as_ref());
|
||||
opts.insert_atom("test".into());
|
||||
opts.insert_atom("debug_assertion".into());
|
||||
opts
|
||||
|
|
Loading…
Reference in a new issue