mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-10 02:12:40 +00:00
Merge #4166
4166: Defining a default target to support cross-compilation targets r=matklad a=FuriouZz Related to #4163 Co-authored-by: Christophe MASSOLIN <christophe.massolin@gmail.com>
This commit is contained in:
commit
8803e748a6
6 changed files with 25 additions and 7 deletions
|
@ -56,6 +56,9 @@ pub struct CargoConfig {
|
|||
|
||||
/// Runs cargo check on launch to figure out the correct values of OUT_DIR
|
||||
pub load_out_dirs_from_check: bool,
|
||||
|
||||
/// rustc target
|
||||
pub target: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for CargoConfig {
|
||||
|
@ -65,6 +68,7 @@ impl Default for CargoConfig {
|
|||
all_features: true,
|
||||
features: Vec::new(),
|
||||
load_out_dirs_from_check: false,
|
||||
target: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -160,6 +164,9 @@ impl CargoWorkspace {
|
|||
if let Some(parent) = cargo_toml.parent() {
|
||||
meta.current_dir(parent);
|
||||
}
|
||||
if let Some(target) = cargo_features.target.as_ref() {
|
||||
meta.other_options(&[String::from("--filter-platform"), target.clone()]);
|
||||
}
|
||||
let meta = meta.exec().with_context(|| {
|
||||
format!("Failed to run `cargo metadata --manifest-path {}`", cargo_toml.display())
|
||||
})?;
|
||||
|
|
|
@ -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,12 @@ 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 mut cmd = Command::new("rustc");
|
||||
cmd.args(&["--print", "cfg", "-O"]);
|
||||
if let Some(target) = target {
|
||||
cmd.args(&["--target", target.as_str()]);
|
||||
}
|
||||
let output = cmd.output().context("Failed to get output from rustc --print cfg -O")?;
|
||||
if !output.status.success() {
|
||||
bail!(
|
||||
"rustc --print cfg -O exited with exit code ({})",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue