From 92973c13924b82e74473bdcee16ce788f4cd3c9b Mon Sep 17 00:00:00 2001 From: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> Date: Fri, 7 Mar 2025 05:56:49 +1000 Subject: [PATCH] Fix detect-targets musl fallback for android and alpine (#2076) Android does not have `-unknown-` in target and alpine uses `-alpine-` instead of `-unknown-`, so the musl fallback must be taken special care when generating Signed-off-by: Jiahao XU --- crates/detect-targets/src/detect/linux.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/detect-targets/src/detect/linux.rs b/crates/detect-targets/src/detect/linux.rs index 04a88924..1b81f688 100644 --- a/crates/detect-targets/src/detect/linux.rs +++ b/crates/detect-targets/src/detect/linux.rs @@ -22,7 +22,14 @@ pub(super) async fn detect_targets(target: String) -> Vec { (postfix, Libc::Unknown) }; - let musl_fallback_target = || format!("{prefix}-{}{abi}", "musl"); + let cpu_arch = target + .split_once('-') + .expect("unwrap: target always has a - for cpu_arch") + .0; + + // For android the `-unknown-` is omitted, for alpine it has `-alpine-` + // instead of `-unknown-`. + let musl_fallback_target = || format!("{cpu_arch}-unknown-linux-musl{abi}"); match libc { // guess_host_triple cannot detect whether the system is using glibc, @@ -33,11 +40,6 @@ pub(super) async fn detect_targets(target: String) -> Vec { // // As such, we need to launch the test ourselves. Libc::Gnu | Libc::Musl => { - let cpu_arch = target - .split_once('-') - .expect("unwrap: target always has a - for cpu_arch") - .0; - let handles: Vec<_> = { let cpu_arch_suffix = cpu_arch.replace('_', "-"); let filename = format!("ld-linux-{cpu_arch_suffix}.so.2");