aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs7
-rw-r--r--crates/ra_project_model/src/lib.rs12
-rw-r--r--crates/rust-analyzer/src/cli/load_cargo.rs2
-rw-r--r--crates/rust-analyzer/src/config.rs1
-rw-r--r--crates/rust-analyzer/src/world.rs2
-rw-r--r--editors/code/package.json8
6 files changed, 25 insertions, 7 deletions
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs
index 362ee30fe..59f46a2a0 100644
--- a/crates/ra_project_model/src/cargo_workspace.rs
+++ b/crates/ra_project_model/src/cargo_workspace.rs
@@ -56,6 +56,9 @@ pub struct CargoConfig {
56 56
57 /// Runs cargo check on launch to figure out the correct values of OUT_DIR 57 /// Runs cargo check on launch to figure out the correct values of OUT_DIR
58 pub load_out_dirs_from_check: bool, 58 pub load_out_dirs_from_check: bool,
59
60 /// rustc target
61 pub target: Option<String>,
59} 62}
60 63
61impl Default for CargoConfig { 64impl Default for CargoConfig {
@@ -65,6 +68,7 @@ impl Default for CargoConfig {
65 all_features: true, 68 all_features: true,
66 features: Vec::new(), 69 features: Vec::new(),
67 load_out_dirs_from_check: false, 70 load_out_dirs_from_check: false,
71 target: None,
68 } 72 }
69 } 73 }
70} 74}
@@ -160,6 +164,9 @@ impl CargoWorkspace {
160 if let Some(parent) = cargo_toml.parent() { 164 if let Some(parent) = cargo_toml.parent() {
161 meta.current_dir(parent); 165 meta.current_dir(parent);
162 } 166 }
167 if let Some(target) = cargo_features.target.as_ref() {
168 meta.other_options(&[String::from("--filter-platform"), target.clone()]);
169 }
163 let meta = meta.exec().with_context(|| { 170 let meta = meta.exec().with_context(|| {
164 format!("Failed to run `cargo metadata --manifest-path {}`", cargo_toml.display()) 171 format!("Failed to run `cargo metadata --manifest-path {}`", cargo_toml.display())
165 })?; 172 })?;
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index 731cbd291..c2b33c1dc 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -543,7 +543,7 @@ impl ProjectWorkspace {
543 } 543 }
544} 544}
545 545
546pub fn get_rustc_cfg_options() -> CfgOptions { 546pub fn get_rustc_cfg_options(target: Option<&String>) -> CfgOptions {
547 let mut cfg_options = CfgOptions::default(); 547 let mut cfg_options = CfgOptions::default();
548 548
549 // Some nightly-only cfgs, which are required for stdlib 549 // Some nightly-only cfgs, which are required for stdlib
@@ -558,10 +558,12 @@ pub fn get_rustc_cfg_options() -> CfgOptions {
558 558
559 match (|| -> Result<String> { 559 match (|| -> Result<String> {
560 // `cfg(test)` and `cfg(debug_assertion)` are handled outside, so we suppress them here. 560 // `cfg(test)` and `cfg(debug_assertion)` are handled outside, so we suppress them here.
561 let output = Command::new("rustc") 561 let mut cmd = Command::new("rustc");
562 .args(&["--print", "cfg", "-O"]) 562 cmd.args(&["--print", "cfg", "-O"]);
563 .output() 563 if let Some(target) = target {
564 .context("Failed to get output from rustc --print cfg -O")?; 564 cmd.args(&["--target", target.as_str()]);
565 }
566 let output = cmd.output().context("Failed to get output from rustc --print cfg -O")?;
565 if !output.status.success() { 567 if !output.status.success() {
566 bail!( 568 bail!(
567 "rustc --print cfg -O exited with exit code ({})", 569 "rustc --print cfg -O exited with exit code ({})",
diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs
index d0a71120a..023ced6cf 100644
--- a/crates/rust-analyzer/src/cli/load_cargo.rs
+++ b/crates/rust-analyzer/src/cli/load_cargo.rs
@@ -149,7 +149,7 @@ pub(crate) fn load(
149 149
150 // FIXME: cfg options? 150 // FIXME: cfg options?
151 let default_cfg_options = { 151 let default_cfg_options = {
152 let mut opts = get_rustc_cfg_options(); 152 let mut opts = get_rustc_cfg_options(None);
153 opts.insert_atom("test".into()); 153 opts.insert_atom("test".into());
154 opts.insert_atom("debug_assertion".into()); 154 opts.insert_atom("debug_assertion".into());
155 opts 155 opts
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 15b7c6912..8d85c60cf 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -131,6 +131,7 @@ impl Config {
131 set(value, "/cargo/allFeatures", &mut self.cargo.all_features); 131 set(value, "/cargo/allFeatures", &mut self.cargo.all_features);
132 set(value, "/cargo/features", &mut self.cargo.features); 132 set(value, "/cargo/features", &mut self.cargo.features);
133 set(value, "/cargo/loadOutDirsFromCheck", &mut self.cargo.load_out_dirs_from_check); 133 set(value, "/cargo/loadOutDirsFromCheck", &mut self.cargo.load_out_dirs_from_check);
134 set(value, "/cargo/target", &mut self.cargo.target);
134 135
135 match get(value, "/procMacro/enable") { 136 match get(value, "/procMacro/enable") {
136 Some(true) => { 137 Some(true) => {
diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs
index 34941931b..16020648d 100644
--- a/crates/rust-analyzer/src/world.rs
+++ b/crates/rust-analyzer/src/world.rs
@@ -131,7 +131,7 @@ impl WorldState {
131 131
132 // FIXME: Read default cfgs from config 132 // FIXME: Read default cfgs from config
133 let default_cfg_options = { 133 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());
135 opts.insert_atom("test".into()); 135 opts.insert_atom("test".into());
136 opts.insert_atom("debug_assertion".into()); 136 opts.insert_atom("debug_assertion".into());
137 opts 137 opts
diff --git a/editors/code/package.json b/editors/code/package.json
index 442b9de98..a05a69752 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -233,6 +233,14 @@
233 "default": false, 233 "default": false,
234 "markdownDescription": "Run `cargo check` on startup to get the correct value for package OUT_DIRs" 234 "markdownDescription": "Run `cargo check` on startup to get the correct value for package OUT_DIRs"
235 }, 235 },
236 "rust-analyzer.cargo.target": {
237 "type": [
238 "null",
239 "string"
240 ],
241 "default": null,
242 "description": "Specify the compilation target"
243 },
236 "rust-analyzer.rustfmt.extraArgs": { 244 "rust-analyzer.rustfmt.extraArgs": {
237 "type": "array", 245 "type": "array",
238 "items": { 246 "items": {