mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +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
@ -56,6 +56,9 @@ pub struct CargoConfig {
|
|||||||
|
|
||||||
/// Runs cargo check on launch to figure out the correct values of OUT_DIR
|
/// Runs cargo check on launch to figure out the correct values of OUT_DIR
|
||||||
pub load_out_dirs_from_check: bool,
|
pub load_out_dirs_from_check: bool,
|
||||||
|
|
||||||
|
/// rustc target
|
||||||
|
pub target: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for CargoConfig {
|
impl Default for CargoConfig {
|
||||||
@ -65,6 +68,7 @@ impl Default for CargoConfig {
|
|||||||
all_features: true,
|
all_features: true,
|
||||||
features: Vec::new(),
|
features: Vec::new(),
|
||||||
load_out_dirs_from_check: false,
|
load_out_dirs_from_check: false,
|
||||||
|
target: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -160,6 +164,9 @@ impl CargoWorkspace {
|
|||||||
if let Some(parent) = cargo_toml.parent() {
|
if let Some(parent) = cargo_toml.parent() {
|
||||||
meta.current_dir(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(|| {
|
let meta = meta.exec().with_context(|| {
|
||||||
format!("Failed to run `cargo metadata --manifest-path {}`", cargo_toml.display())
|
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();
|
let mut cfg_options = CfgOptions::default();
|
||||||
|
|
||||||
// Some nightly-only cfgs, which are required for stdlib
|
// Some nightly-only cfgs, which are required for stdlib
|
||||||
@ -558,10 +558,12 @@ pub fn get_rustc_cfg_options() -> CfgOptions {
|
|||||||
|
|
||||||
match (|| -> Result<String> {
|
match (|| -> Result<String> {
|
||||||
// `cfg(test)` and `cfg(debug_assertion)` are handled outside, so we suppress them here.
|
// `cfg(test)` and `cfg(debug_assertion)` are handled outside, so we suppress them here.
|
||||||
let output = Command::new("rustc")
|
let mut cmd = Command::new("rustc");
|
||||||
.args(&["--print", "cfg", "-O"])
|
cmd.args(&["--print", "cfg", "-O"]);
|
||||||
.output()
|
if let Some(target) = target {
|
||||||
.context("Failed to get output from rustc --print cfg -O")?;
|
cmd.args(&["--target", target.as_str()]);
|
||||||
|
}
|
||||||
|
let output = cmd.output().context("Failed to get output from rustc --print cfg -O")?;
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
bail!(
|
bail!(
|
||||||
"rustc --print cfg -O exited with exit code ({})",
|
"rustc --print cfg -O exited with exit code ({})",
|
||||||
|
@ -149,7 +149,7 @@ pub(crate) fn load(
|
|||||||
|
|
||||||
// FIXME: cfg options?
|
// FIXME: cfg options?
|
||||||
let default_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("test".into());
|
||||||
opts.insert_atom("debug_assertion".into());
|
opts.insert_atom("debug_assertion".into());
|
||||||
opts
|
opts
|
||||||
|
@ -131,6 +131,7 @@ impl Config {
|
|||||||
set(value, "/cargo/allFeatures", &mut self.cargo.all_features);
|
set(value, "/cargo/allFeatures", &mut self.cargo.all_features);
|
||||||
set(value, "/cargo/features", &mut self.cargo.features);
|
set(value, "/cargo/features", &mut self.cargo.features);
|
||||||
set(value, "/cargo/loadOutDirsFromCheck", &mut self.cargo.load_out_dirs_from_check);
|
set(value, "/cargo/loadOutDirsFromCheck", &mut self.cargo.load_out_dirs_from_check);
|
||||||
|
set(value, "/cargo/target", &mut self.cargo.target);
|
||||||
|
|
||||||
match get(value, "/procMacro/enable") {
|
match get(value, "/procMacro/enable") {
|
||||||
Some(true) => {
|
Some(true) => {
|
||||||
|
@ -131,7 +131,7 @@ impl WorldState {
|
|||||||
|
|
||||||
// FIXME: Read default cfgs from config
|
// FIXME: Read default cfgs from config
|
||||||
let default_cfg_options = {
|
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("test".into());
|
||||||
opts.insert_atom("debug_assertion".into());
|
opts.insert_atom("debug_assertion".into());
|
||||||
opts
|
opts
|
||||||
|
@ -233,6 +233,14 @@
|
|||||||
"default": false,
|
"default": false,
|
||||||
"markdownDescription": "Run `cargo check` on startup to get the correct value for package OUT_DIRs"
|
"markdownDescription": "Run `cargo check` on startup to get the correct value for package OUT_DIRs"
|
||||||
},
|
},
|
||||||
|
"rust-analyzer.cargo.target": {
|
||||||
|
"type": [
|
||||||
|
"null",
|
||||||
|
"string"
|
||||||
|
],
|
||||||
|
"default": null,
|
||||||
|
"description": "Specify the compilation target"
|
||||||
|
},
|
||||||
"rust-analyzer.rustfmt.extraArgs": {
|
"rust-analyzer.rustfmt.extraArgs": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
|
Loading…
Reference in New Issue
Block a user