Refactor get_target_from_rustc impl

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-06-07 12:14:27 +10:00
parent 96336e4dd9
commit 9ee2609b25
No known key found for this signature in database
GPG key ID: 591C0B03040416D6

View file

@ -101,16 +101,18 @@ pub async fn detect_targets() -> Targets {
/// Figure out what the host target is using `rustc`.
/// If `rustc` is absent, then it would return `None`.
async fn get_target_from_rustc() -> Option<Box<str>> {
match Command::new("rustc").arg("-vV").output().await {
Ok(Output { status, stdout, .. }) if status.success() => Cursor::new(stdout)
let Output { status, stdout, .. } = Command::new("rustc").arg("-vV").output().await.ok()?;
if !status.success() {
return None;
}
Cursor::new(stdout)
.lines()
.filter_map(|line| line.ok())
.find_map(|line| {
line.strip_prefix("host: ")
.map(|host| host.to_owned().into_boxed_str())
}),
_ => None,
}
})
}
#[cfg(target_os = "linux")]