From ec6f81935c044b83eafef4181029a034849e906c Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Fri, 1 Jul 2022 19:30:31 +1000 Subject: [PATCH] Refactor: Extract `detect_alternative_targets` Signed-off-by: Jiahao XU --- src/target.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/target.rs b/src/target.rs index fc5292f9..6fe51f0e 100644 --- a/src/target.rs +++ b/src/target.rs @@ -91,9 +91,7 @@ pub async fn detect_targets() -> Vec { } #[cfg(target_os = "windows")] - if v[0].contains("gnu") { - v.push(v[0].replace("gnu", "msvc")); - } + v.extend(windows::detect_alternative_targets(&v[0])); v } else { @@ -221,12 +219,16 @@ mod windows { use super::TARGET; use guess_host_triple::guess_host_triple; + pub(super) fn detect_alternative_targets(target: &str) -> Option { + target + .contains("gnu") + .then(|| target.replace("gnu", "msvc")) + } + pub(super) fn detect_targets_windows() -> Vec { let mut targets = vec![guess_host_triple().unwrap_or(TARGET).to_string()]; - if targets[0].contains("gnu") { - targets.push(targets[0].replace("gnu", "msvc")); - } + targets.extend(windows::detect_alternative_targets(&targets[0])); targets }