aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-05-05 18:25:52 +0100
committerGitHub <[email protected]>2020-05-05 18:25:52 +0100
commit8803e748a627f2ff45d441e70b3deda3f038c40e (patch)
tree7bf401e386cc5939bc6548aad91d7f652ea2e5be /crates/ra_project_model/src
parentdf7b59081fabd96c6ee5599aad58c941cfb6beb7 (diff)
parent04e32fbffca22e632594218e8dfafdc39281c6f7 (diff)
Merge #4166
4166: Defining a default target to support cross-compilation targets r=matklad a=FuriouZz Related to #4163 Co-authored-by: Christophe MASSOLIN <[email protected]>
Diffstat (limited to 'crates/ra_project_model/src')
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs7
-rw-r--r--crates/ra_project_model/src/lib.rs12
2 files changed, 14 insertions, 5 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 ({})",