From 8bc0f1156959c2acfd9b1f5ae1eee2fbec07fc5a Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Thu, 23 Jun 2022 13:59:53 +1000 Subject: [PATCH] Detect `*-pc-windows-gnu` targets in `targets` And add fallback `*-pc-windows-msvc` to the returned targets. Signed-off-by: Jiahao XU --- src/target.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/target.rs b/src/target.rs index ac6b6be9..1ce8d308 100644 --- a/src/target.rs +++ b/src/target.rs @@ -32,6 +32,11 @@ pub async fn detect_targets() -> Vec { v.push(macos::X86.into()); } + #[cfg(target_os = "windows")] + if v[0].contains("gnu") { + v.push(v[0].replace("gnu", "msvc")); + } + v } else { #[cfg(target_os = "linux")] @@ -42,7 +47,11 @@ pub async fn detect_targets() -> Vec { { macos::detect_targets_macos() } - #[cfg(not(any(target_os = "linux", target_os = "macos")))] + #[cfg(target_os = "windows")] + { + windows::detect_targets_windows() + } + #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))] { vec![TARGET.into()] } @@ -145,3 +154,19 @@ mod macos { } } } + +#[cfg(target_os = "windows")] +mod windows { + use super::TARGET; + use guess_host_triple::guess_host_triple; + + 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 + } +}