Skip to content

The agent that grows with you

fix(installer): detect musl uv when ldd is unavailable

JoaoMarcos4487d12436233e
diff --git a/scripts/install.sh b/scripts/install.sh
index f30a28385a8..9643eccc2be 100644
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -218,7 +218,17 @@ uv_bootstrap_target() {
esac
case "$(uname -s)" in
Linux)
- if ldd --version 2>&1 | grep -qi musl; then
+ # Minimal musl roots may have the loader but no ldd. Trust a
+ # recognizable ldd result before falling back to the loader:
+ # a glibc host may carry musl as a secondary toolchain.
+ local _libc
+ _libc="$(ldd --version 2>&1 || true)"
+ _libc="${_libc,,}"
+ if [[ "$_libc" == *musl* ]]; then
+ echo "linux-$_arch-musl"
+ elif [[ "$_libc" == *glibc* || "$_libc" == *"gnu libc"* || "$_libc" == *"gnu c library"* ]]; then
+ echo "linux-$_arch"
+ elif compgen -G '/lib/ld-musl-*.so.1' >/dev/null; then
echo "linux-$_arch-musl"
else
echo "linux-$_arch"
diff --git a/tests/scripts/install/test_install_sh_musl_uv_bootstrap.py b/tests/scripts/install/test_install_sh_musl_uv_bootstrap.py
index e69d0a861fc..3a8b54ae977 100644
--- a/tests/scripts/install/test_install_sh_musl_uv_bootstrap.py
+++ b/tests/scripts/install/test_install_sh_musl_uv_bootstrap.py
@@ -11,21 +11,43 @@ pytestmark = pytest.mark.platforms("linux")
ROOT = Path(__file__).resolve().parents[3]
[email protected]("libc,suffix", [("musl libc", "-musl"), ("GNU libc", "")])
-def test_bootstrap_selects_native_uv_pin(libc, suffix):
+ "libc,loader_present,suffix",
+ [
+ ("musl libc", False, "-musl"),
+ ("GNU libc", False, ""),
+ ("absent", True, "-musl"),
+ ("BusyBox", True, "-musl"),
+ ("GNU libc", True, ""),
+ ("absent", False, ""),
+ ],
+)
+def test_bootstrap_selects_native_uv_pin(libc, loader_present, suffix):
machine = subprocess.check_output(["uname", "-m"], text=True).strip()
arch = {"x86_64": "x64", "aarch64": "arm64"}[machine]
target = f"linux-{arch}{suffix}"
script = """
source "$1" --manifest
libc_output="$2"
-ldd() { printf '%s\\n' "$libc_output"; }
+loader_present="$3"
+ldd() {
+ [ "$libc_output" != absent ] || return 127
+ printf '%s\\n' "$libc_output"
+}
+compgen() {
+ if [ "$1" = -G ] && [ "$2" = '/lib/ld-musl-*.so.1' ]; then
+ [ "$loader_present" = yes ]
+ else
+ builtin compgen "$@"
+ fi
+}
target="$(uv_bootstrap_target)"
uv_bootstrap_pin "$target"
printf '%s\\n%s\\n%s\\n' "$target" "$UV_PIN_URL" "$UV_PIN_SHA256"
"""
result = subprocess.run(
- ["bash", "-c", script, "_", str(ROOT / "scripts" / "install.sh"), libc],
+ ["bash", "-c", script, "_", str(ROOT / "scripts" / "install.sh"), libc,
+ "yes" if loader_present else "no"],
check=True, capture_output=True, text=True,
)
row = json.loads((ROOT / "pm" / "lock.json").read_text())["packages"]["uv"]["artifacts"][target]