aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-12-17 18:32:13 +0000
committerGitHub <[email protected]>2020-12-17 18:32:13 +0000
commitb55cb897e5104ef30a3d13fe36cb97d6bf6a3597 (patch)
tree7f4c106f52341744575e876eb41ea13c626c49ef /crates
parentb0e5d1efdbf81fccf655b202d2433700d6e312e1 (diff)
parentfaed47b3d31d2bf533aac489046ed9efc30f239d (diff)
Merge #6912
6912: Default to host platform for cargo metadata r=jonhoo a=jonhoo This modifies the logic for calling cargo metadata so that it will use the host platform if no explicit target platform is given. This is needed since cargo metadata defaults to outputting information for _all_ targets. Fixes #6908. Co-authored-by: Jon Gjengset <[email protected]> Co-authored-by: Jon Gjengset <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/project_model/src/cargo_workspace.rs31
1 files changed, 29 insertions, 2 deletions
diff --git a/crates/project_model/src/cargo_workspace.rs b/crates/project_model/src/cargo_workspace.rs
index 894c5c952..bb3b6f2ef 100644
--- a/crates/project_model/src/cargo_workspace.rs
+++ b/crates/project_model/src/cargo_workspace.rs
@@ -16,6 +16,7 @@ use paths::{AbsPath, AbsPathBuf};
16use rustc_hash::FxHashMap; 16use rustc_hash::FxHashMap;
17 17
18use crate::cfg_flag::CfgFlag; 18use crate::cfg_flag::CfgFlag;
19use crate::utf8_stdout;
19 20
20/// `CargoWorkspace` represents the logical structure of, well, a Cargo 21/// `CargoWorkspace` represents the logical structure of, well, a Cargo
21/// workspace. It pretty closely mirrors `cargo metadata` output. 22/// workspace. It pretty closely mirrors `cargo metadata` output.
@@ -166,8 +167,34 @@ impl CargoWorkspace {
166 if let Some(parent) = cargo_toml.parent() { 167 if let Some(parent) = cargo_toml.parent() {
167 meta.current_dir(parent.to_path_buf()); 168 meta.current_dir(parent.to_path_buf());
168 } 169 }
169 if let Some(target) = config.target.as_ref() { 170 let target = if let Some(target) = config.target.as_ref() {
170 meta.other_options(vec![String::from("--filter-platform"), target.clone()]); 171 Some(target.clone())
172 } else {
173 // cargo metadata defaults to giving information for _all_ targets.
174 // In the absence of a preference from the user, we use the host platform.
175 let mut rustc = Command::new(toolchain::rustc());
176 rustc.current_dir(cargo_toml.parent().unwrap()).arg("-vV");
177 log::debug!("Discovering host platform by {:?}", rustc);
178 match utf8_stdout(rustc) {
179 Ok(stdout) => {
180 let field = "host: ";
181 let target = stdout.lines().find_map(|l| l.strip_prefix(field));
182 if let Some(target) = target {
183 Some(target.to_string())
184 } else {
185 // If we fail to resolve the host platform, it's not the end of the world.
186 log::info!("rustc -vV did not report host platform, got:\n{}", stdout);
187 None
188 }
189 }
190 Err(e) => {
191 log::warn!("Failed to discover host platform: {}", e);
192 None
193 }
194 }
195 };
196 if let Some(target) = target {
197 meta.other_options(vec![String::from("--filter-platform"), target]);
171 } 198 }
172 let mut meta = meta.exec().with_context(|| { 199 let mut meta = meta.exec().with_context(|| {
173 format!("Failed to run `cargo metadata --manifest-path {}`", cargo_toml.display()) 200 format!("Failed to run `cargo metadata --manifest-path {}`", cargo_toml.display())