fix(install): apply gh-r libc preference after CPU narrowing

The previous fix excluded musl assets in the OS-pattern stage, which
runs before the CPU filter. Repos that ship their x86_64 Linux build
only as musl while providing non-musl builds solely for ARM (dua-cli,
git-absorb, mcfly, navi, ripgrep, tre, xh, zoxide) ended up with a
wrong-architecture asset or none at all.

Make the Linux OS pattern libc-neutral and emit the detected host libc
as a fourth field from .zi::get-architecture. The narrowing loop now
uses the libc token as its lowest-priority filter, and an explicit
post-CPU step drops musl assets on glibc hosts (or requires them on
musl hosts) only when alternatives survive, so a musl-only architecture
still resolves.

Full tests/gh-r.zunit suite: 151 passed, 0 failed, 7 skipped. tokei
selects -linux-gnu (ships both variants), bicep selects bicep-linux-x64,
musl-only tools select their musl asset; Alpine hosts verified to
prefer musl with intact fallback.

Signed-off-by: Vladislav Doster <mvdoster@gmail.com>
This commit is contained in:
Vladislav Doster 2026-07-18 01:20:04 -05:00
parent cf0b2fe476
commit 21e007b3f9

View file

@ -1408,12 +1408,8 @@ builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh" || {
fi
;;
(Linux)
_sys='linux'
[[ $OSTYPE == *musl* || "$(command ldd --version 2>&1)" == *musl* ]] && _clib="musl"
if [[ $_clib == musl ]]; then
_sys='musl*~^*linux*'
else
_sys='linux*~*musl'
fi
;;
(MINGW* | MSYS* | CYGWIN* | Windows_NT)
_sys='pc-windows-gnu'
@ -1439,7 +1435,7 @@ builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh" || {
+zi-log "{e} {b}gh-r{rst}Unsupported CPU: {obj}$_cpu{rst}"
;;
esac
echo "${_sys};${_cpu};${_os}"
echo "${_sys};${_cpu};${_os};${_clib}"
} # ]]]
# FUNCTION: .zinit-get-latest-gh-r-url-part [[[
# Gets version string of latest release of given Github
@ -1507,6 +1503,17 @@ builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh" || {
fi
done
# A musl asset is correct only when the host libc is musl — but runs after
# the CPU filter so a musl-only arch (e.g. only x86_64 build is musl) still resolves.
if (( $#list > 1 )); then
if [[ $parts[4] == musl ]]; then
filtered=( ${(M)list[@]:#(#i)*musl*} )
else
filtered=( ${list[@]:#(#i)*musl*} )
fi
(( $#filtered > 0 )) && list=( ${filtered[@]} )
fi
if (( $#list > 1 )) { filtered=( ${list[@]:#(#i)*.(sha[[:digit:]]#|asc)} ) && (( $#filtered > 0 )) && list=( ${filtered[@]} ); }
if (( !$#list )); then