Skip to content

Commit 14dde99

Browse files
committed
Pass cargo.target to rustc
1 parent 0ab4340 commit 14dde99

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

crates/ra_project_model/src/lib.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ impl ProjectWorkspace {
543543
}
544544
}
545545

546-
pub fn get_rustc_cfg_options() -> CfgOptions {
546+
pub fn get_rustc_cfg_options(target: Option<&String>) -> CfgOptions {
547547
let mut cfg_options = CfgOptions::default();
548548

549549
// Some nightly-only cfgs, which are required for stdlib
@@ -558,10 +558,18 @@ pub fn get_rustc_cfg_options() -> CfgOptions {
558558

559559
match (|| -> Result<String> {
560560
// `cfg(test)` and `cfg(debug_assertion)` are handled outside, so we suppress them here.
561-
let output = Command::new("rustc")
562-
.args(&["--print", "cfg", "-O"])
563-
.output()
564-
.context("Failed to get output from rustc --print cfg -O")?;
561+
let output = if let Some(target) = target {
562+
Command::new("rustc")
563+
.args(&["--print", "cfg", "-O", "--target", target.as_str()])
564+
.output()
565+
.context("Failed to get output from rustc --print cfg -O")?
566+
} else {
567+
Command::new("rustc")
568+
.args(&["--print", "cfg", "-O"])
569+
.output()
570+
.context("Failed to get output from rustc --print cfg -O")?
571+
};
572+
565573
if !output.status.success() {
566574
bail!(
567575
"rustc --print cfg -O exited with exit code ({})",

crates/rust-analyzer/src/cli/load_cargo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ pub(crate) fn load(
149149

150150
// FIXME: cfg options?
151151
let default_cfg_options = {
152-
let mut opts = get_rustc_cfg_options();
152+
let mut opts = get_rustc_cfg_options(None);
153153
opts.insert_atom("test".into());
154154
opts.insert_atom("debug_assertion".into());
155155
opts

crates/rust-analyzer/src/world.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl WorldState {
131131

132132
// FIXME: Read default cfgs from config
133133
let default_cfg_options = {
134-
let mut opts = get_rustc_cfg_options();
134+
let mut opts = get_rustc_cfg_options(config.cargo.target.as_ref());
135135
opts.insert_atom("test".into());
136136
opts.insert_atom("debug_assertion".into());
137137
opts

0 commit comments

Comments
 (0)