From b7edffe244581b428a4b4da4ff6a08ab461b018f Mon Sep 17 00:00:00 2001 From: Christophe MASSOLIN Date: Mon, 27 Apr 2020 00:11:04 +0200 Subject: Started rust-analyzer.cargo.defaultTarget implementation --- crates/ra_project_model/src/cargo_workspace.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'crates/ra_project_model/src') diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index 362ee30fe..810833b64 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs @@ -42,6 +42,11 @@ impl ops::Index for CargoWorkspace { } } +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct RustcConfig { + pub default_target: Option, +} + #[derive(Clone, Debug, PartialEq, Eq)] pub struct CargoConfig { /// Do not activate the `default` feature. @@ -56,6 +61,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 config + pub rustc: RustcConfig, } impl Default for CargoConfig { @@ -65,6 +73,7 @@ impl Default for CargoConfig { all_features: true, features: Vec::new(), load_out_dirs_from_check: false, + rustc: RustcConfig { default_target: None }, } } } @@ -160,6 +169,9 @@ impl CargoWorkspace { if let Some(parent) = cargo_toml.parent() { meta.current_dir(parent); } + if let Some(target) = cargo_features.rustc.default_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()) })?; -- cgit v1.2.3 From ed5af989f431b9bfabf6f67350587add05a1942c Mon Sep 17 00:00:00 2001 From: Christophe MASSOLIN Date: Tue, 28 Apr 2020 00:15:54 +0200 Subject: [config] rename cargo.defaultTarget --- crates/ra_project_model/src/cargo_workspace.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/ra_project_model/src') diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index 810833b64..1dfee6b47 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs @@ -62,8 +62,8 @@ 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 config - pub rustc: RustcConfig, + /// rustc target + pub default_target: Option, } impl Default for CargoConfig { @@ -73,7 +73,7 @@ impl Default for CargoConfig { all_features: true, features: Vec::new(), load_out_dirs_from_check: false, - rustc: RustcConfig { default_target: None }, + default_target: None, } } } @@ -169,7 +169,7 @@ impl CargoWorkspace { if let Some(parent) = cargo_toml.parent() { meta.current_dir(parent); } - if let Some(target) = cargo_features.rustc.default_target.as_ref() { + if let Some(target) = cargo_features.default_target.as_ref() { meta.other_options(&[String::from("--filter-platform"), target.clone()]); } let meta = meta.exec().with_context(|| { -- cgit v1.2.3 From e7523511ce201763e093d5f5563c20d0e0fc5d54 Mon Sep 17 00:00:00 2001 From: Christophe MASSOLIN Date: Tue, 28 Apr 2020 00:17:23 +0200 Subject: [config] remove RustcConfig --- crates/ra_project_model/src/cargo_workspace.rs | 5 ----- 1 file changed, 5 deletions(-) (limited to 'crates/ra_project_model/src') diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index 1dfee6b47..31499b468 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs @@ -42,11 +42,6 @@ impl ops::Index for CargoWorkspace { } } -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct RustcConfig { - pub default_target: Option, -} - #[derive(Clone, Debug, PartialEq, Eq)] pub struct CargoConfig { /// Do not activate the `default` feature. -- cgit v1.2.3 From 0ab4340cdb31ac4d50f039f0a56ebaff86710eb7 Mon Sep 17 00:00:00 2001 From: Christophe MASSOLIN Date: Tue, 5 May 2020 18:01:54 +0200 Subject: Rename `defaultTarget` to target --- crates/ra_project_model/src/cargo_workspace.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_project_model/src') diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index 31499b468..59f46a2a0 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs @@ -58,7 +58,7 @@ pub struct CargoConfig { pub load_out_dirs_from_check: bool, /// rustc target - pub default_target: Option, + pub target: Option, } impl Default for CargoConfig { @@ -68,7 +68,7 @@ impl Default for CargoConfig { all_features: true, features: Vec::new(), load_out_dirs_from_check: false, - default_target: None, + target: None, } } } @@ -164,7 +164,7 @@ impl CargoWorkspace { if let Some(parent) = cargo_toml.parent() { meta.current_dir(parent); } - if let Some(target) = cargo_features.default_target.as_ref() { + if let Some(target) = cargo_features.target.as_ref() { meta.other_options(&[String::from("--filter-platform"), target.clone()]); } let meta = meta.exec().with_context(|| { -- cgit v1.2.3 From 14dde99627119f76fd9970dcd07f883be5bc7101 Mon Sep 17 00:00:00 2001 From: Christophe MASSOLIN Date: Tue, 5 May 2020 18:15:13 +0200 Subject: Pass cargo.target to rustc --- crates/ra_project_model/src/lib.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'crates/ra_project_model/src') diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 731cbd291..8fa895aa6 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs @@ -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 { // `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 ({})", -- cgit v1.2.3 From 04e32fbffca22e632594218e8dfafdc39281c6f7 Mon Sep 17 00:00:00 2001 From: Christophe MASSOLIN Date: Tue, 5 May 2020 18:23:47 +0200 Subject: Remove code duplicates --- crates/ra_project_model/src/lib.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'crates/ra_project_model/src') diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 8fa895aa6..c2b33c1dc 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs @@ -558,18 +558,12 @@ pub fn get_rustc_cfg_options(target: Option<&String>) -> CfgOptions { match (|| -> Result { // `cfg(test)` and `cfg(debug_assertion)` are handled outside, so we suppress them here. - 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")? - }; - + 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 ({})", -- cgit v1.2.3