Add fallbacks for get_targets_from_rustc

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-06-06 23:07:25 +10:00
parent cce378e2c5
commit 6b764b0b3f
No known key found for this signature in database
GPG key ID: 591C0B03040416D6

View file

@ -21,9 +21,20 @@ pub const TARGET: &str = env!("TARGET");
/// for more information.
pub async fn detect_targets() -> ArrayVec<Box<str>, 2> {
if let Some(target) = get_targets_from_rustc().await {
return from_array([target]);
let mut v = from_array([target]);
#[cfg(target_os = "linux")]
if v[0].contains("gnu") {
v.push(target.replace("gnu", "musl").into_boxed_str());
}
#[cfg(target_os = "macos")]
if &*v[0] == macos::AARCH64 {
v.push(macos::X86.into());
}
v
} else {
#[cfg(target_os = "linux")]
{
linux::detect_targets_linux().await
@ -36,6 +47,7 @@ pub async fn detect_targets() -> ArrayVec<Box<str>, 2> {
{
vec![TARGET.into()]
}
}
}
// Figure out what the host target is, from rustc or from this program's own build target
@ -139,8 +151,8 @@ mod macos {
use super::{from_array, ArrayVec};
use guess_host_triple::guess_host_triple;
const AARCH64: &str = "aarch64-apple-darwin";
const X86: &str = "x86_64-apple-darwin";
pub(super) const AARCH64: &str = "aarch64-apple-darwin";
pub(super) const X86: &str = "x86_64-apple-darwin";
pub(super) fn detect_targets_macos() -> ArrayVec<Box<str>, 2> {
if guess_host_triple() == Some(AARCH64) {