Skip to content

The agent that grows with you

fix(pm): keep musl installs on compatible runtime artifacts

JoaoMarcos4424487f3db61b
diff --git a/pm/lock.json b/pm/lock.json
index 81e34ed1c64..c3345126053 100644
--- a/pm/lock.json
+++ b/pm/lock.json
@@ -135,18 +135,10 @@
"sha256": "1ec37f4f092521cb785e0ccfa2d82cc4a79ec8d2a4864f5eefc50a314f2d5dec",
"url": "https://packages.termux.dev/apt/termux-main/pool/main/f/ffmpeg/ffmpeg_8.1.2-5_aarch64.deb"
},
- "linux-arm64-musl": {
- "sha256": "2de63f615df3a46ac26921ac0314f501c3536aaf9fd5197ffe03dd17cd01a404",
- "url": "https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2026-09-10-15-31/ffmpeg-n9.0.1-27-g9b0578816c-linuxarm64-gpl-9.0.tar.xz"
- },
"linux-x64": {
"sha256": "70b162b63517038ff18c8a50f4ea11f919a071f945c5881e87b0b2cd7173f8c7",
"url": "https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2026-09-10-15-31/ffmpeg-n9.0.1-27-g9b0578816c-linux64-gpl-9.0.tar.xz"
},
- "linux-x64-musl": {
- "sha256": "70b162b63517038ff18c8a50f4ea11f919a071f945c5881e87b0b2cd7173f8c7",
- "url": "https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2026-09-10-15-31/ffmpeg-n9.0.1-27-g9b0578816c-linux64-gpl-9.0.tar.xz"
- },
"win32-arm64": {
"sha256": "0f241c74c576f68dbd375f7557c2d08740783d7b8c6f892031c3830df18f672f",
"url": "https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2026-09-10-15-31/ffmpeg-n9.0.1-27-g9b0578816c-winarm64-gpl-9.0.zip"
diff --git a/pm/packages.py b/pm/packages.py
index b8c9bd92284..ebfa0ece9d2 100644
--- a/pm/packages.py
+++ b/pm/packages.py
@@ -21,7 +21,7 @@ from pm.package import (
_probe_reason,
)
from pm.registry import register
-from pm.store import ALL_TARGETS, Store, current_target, flatten_single_dir, merge_tree
+from pm.store import ALL_TARGETS, Store, _MUSL_TARGETS, current_target, flatten_single_dir, merge_tree
from pm.update import (
btbn_index,
btbn_versions,
@@ -48,8 +48,6 @@ _RUST_TRIPLE = {
"darwin-arm64": "aarch64-apple-darwin",
}
-_MUSL_TARGETS = frozenset({"linux-x64-musl", "linux-arm64-musl"})
-
_NODE_PLAT = {
"win32-x64": "win-x64",
"win32-arm64": "win-arm64",
@@ -686,8 +684,8 @@ class Gh(BinaryPackage):
@register
class Ffmpeg(_BionicDebArm, BinaryPackage, DebPackage):
- """Static ffmpeg. GPLv3 builds; always bundled.
- optional=False: ffmpeg is a required runtime tool. Sealed bundles ship
+ """FFmpeg builds for supported targets; BtbN Linux archives require glibc.
+ optional=False: ffmpeg is a required runtime tool where supported. Sealed bundles ship
it baked into the payload; every `hermes update` and `hermes pm install`
re-ensures it from the new lockfile before the venv sync
(pm.client.ensure_tools_for_sync), so a pin bump lands. Windows + Linux:
@@ -702,6 +700,7 @@ class Ffmpeg(_BionicDebArm, BinaryPackage, DebPackage):
name = "ffmpeg"
deb_package = "ffmpeg"
optional = False
+ gaps = {target: "BtbN Linux builds link glibc dynamically" for target in _MUSL_TARGETS}
def main_rel(self, target: str) -> str:
return "bin/ffmpeg"
@@ -718,8 +717,6 @@ class Ffmpeg(_BionicDebArm, BinaryPackage, DebPackage):
"win32": "bin/ffmpeg.exe",
"linux-x64": "bin/ffmpeg",
"linux-arm64": "bin/ffmpeg",
- "linux-x64-musl": "bin/ffmpeg",
- "linux-arm64-musl": "bin/ffmpeg",
"posix": "ffmpeg",
}
flatten = True
@@ -731,10 +728,11 @@ class Ffmpeg(_BionicDebArm, BinaryPackage, DebPackage):
def fetch_url(self, version: str, target: str) -> str:
if target == "linux-arm64-bionic":
return f"https://packages.termux.dev/apt/termux-main/pool/main/f/ffmpeg/ffmpeg_{version}_aarch64.deb"
- lookup_target = target.removesuffix("-musl") if target in _MUSL_TARGETS else target
- osname, arch = lookup_target.split("-")
+ if target in _MUSL_TARGETS:
+ raise InstallError(self.name, f"unavailable on {target}: {self.missing_reason(target)}")
+ osname, arch = target.split("-")
if osname in ("win32", "linux"):
- artifact = btbn_index().get(lookup_target, {}).get(version)
+ artifact = btbn_index().get(target, {}).get(version)
if artifact is not None:
tag, asset = artifact
return f"https://github.com/BtbN/FFmpeg-Builds/releases/download/{tag}/{asset}"
@@ -749,10 +747,11 @@ class Ffmpeg(_BionicDebArm, BinaryPackage, DebPackage):
"retry when the upstream index is available, or keep the existing pin")
def latest_versions(self, target: str, locked=None) -> list[str]:
- lookup_target = target.removesuffix("-musl") if target in _MUSL_TARGETS else target
- if lookup_target in ("win32-x64", "win32-arm64", "linux-x64", "linux-arm64"):
- return btbn_versions(lookup_target)
- return martin_riedl_versions(lookup_target)
+ if target in _MUSL_TARGETS:
+ return []
+ if target in ("win32-x64", "win32-arm64", "linux-x64", "linux-arm64"):
+ return btbn_versions(target)
+ return martin_riedl_versions(target)
@register
diff --git a/pm/registry.py b/pm/registry.py
index 11df8101e17..3bf0876cff4 100644
--- a/pm/registry.py
+++ b/pm/registry.py
@@ -51,9 +51,14 @@ def all_packages() -> list[str]:
def source_install_packages(names: list[str]) -> list[str]:
- """Select runtime roots; internal tools enter only through dependencies."""
+ """Select supported runtime roots; internal tools enter only through dependencies."""
+ from pm.store import current_target
+
+ target = current_target()
return [name for name in names
- if not get_package(name).internal and (name == "python" or not get_package(name).optional)]
+ if not get_package(name).internal
+ and (name == "python" or not get_package(name).optional)
+ and get_package(name).missing_reason(target) is None]
def tool_roots(names: list[str]) -> list[str]:
diff --git a/pm/security_packages.py b/pm/security_packages.py
index 896b0a42609..804de3883f5 100644
--- a/pm/security_packages.py
+++ b/pm/security_packages.py
@@ -11,9 +11,9 @@ from urllib.parse import urlparse
from pm import paths
from pm.lock import Lockfile
from pm.package import InstallError
-from pm.packages import BinaryPackage, _MUSL_TARGETS, _RUST_TRIPLE
+from pm.packages import BinaryPackage, _RUST_TRIPLE
from pm.registry import register
-from pm.store import flatten_single_dir
+from pm.store import _MUSL_TARGETS, flatten_single_dir
@register
diff --git a/pm/store.py b/pm/store.py
index 75a63122043..c3ad39c9d1b 100644
--- a/pm/store.py
+++ b/pm/store.py
@@ -98,6 +98,9 @@ def _is_bionic_libc() -> bool:
return bool(sysconfig.get_config_var("ANDROID_API_LEVEL"))
+_MUSL_TARGETS = frozenset({"linux-x64-musl", "linux-arm64-musl"})
+
+
def _elf_loader_is_musl(binary: Path) -> bool | None:
"""Read an ELF's interpreter string without executing foreign bytes."""
try:
@@ -126,21 +129,22 @@ def _native_linux_uses_musl() -> bool | None:
def _is_musl_libc() -> bool:
"""True on native Linux musl userlands (Alpine, Void-musl, etc.).
- libc is part of PM's artifact identity. Prefer Python's build metadata,
- then inspect a native userland ELF: a bootstrap interpreter may itself be
- a glibc build running through a compatibility shim and misreport the host
- libc. A bare musl-loader existence check is only the last resort because
- glibc hosts may install musl as a secondary toolchain.
+ libc is part of PM's artifact identity. The native userland takes
+ precedence over a bootstrap Python built for a different libc.
+ Python build metadata breaks ties when native binaries cannot be inspected;
+ a musl loader on disk alone is the last resort because glibc hosts may
+ install musl as a secondary toolchain.
"""
+ native = _native_linux_uses_musl()
+ if native is not None:
+ return native
+
import sysconfig
for key in ("HOST_GNU_TYPE", "MULTIARCH"):
value = str(sysconfig.get_config_var(key) or "").lower()
if "musl" in value:
return True
- native = _native_linux_uses_musl()
- if native is not None:
- return native
return any(Path("/lib").glob("ld-musl-*.so.1"))
diff --git a/scripts/gen-bootstrap-pins.py b/scripts/gen-bootstrap-pins.py
old mode 100755
new mode 100644
index 7a0ed9836ba..9e856bfbea2
--- a/scripts/gen-bootstrap-pins.py
+++ b/scripts/gen-bootstrap-pins.py
@@ -34,7 +34,7 @@ from pm.artifact_mirror import mirror_url # noqa: E402
BEGIN_MARK = "# --- BEGIN GENERATED: bootstrap pins (scripts/gen-bootstrap-pins.py) ---"
END_MARK = "# --- END GENERATED: bootstrap pins ---"
-_POSIX_TARGETS = ("linux-x64", "linux-arm64", "darwin-x64", "darwin-arm64")
+_POSIX_TARGETS = ("linux-x64", "linux-arm64", "linux-x64-musl", "linux-arm64-musl", "darwin-x64", "darwin-arm64")
_WINDOWS_TARGETS = ("win32-x64", "win32-arm64")
diff --git a/scripts/install.sh b/scripts/install.sh
old mode 100755
new mode 100644
index fdaa4833de1..f30a28385a8
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -179,6 +179,16 @@ uv_bootstrap_pin() {
UV_PIN_MIRROR="https://hermes-assets.nousresearch.com/upstream/sha256/bb66cb52e7b1823aed1183630d8d8e5c958840d584a4c55ec10a4cfc168dcca2"
UV_PIN_SHA256="bb66cb52e7b1823aed1183630d8d8e5c958840d584a4c55ec10a4cfc168dcca2"
;;
+ linux-x64-musl)
+ UV_PIN_URL="https://github.com/astral-sh/uv/releases/download/0.12.3/uv-x86_64-unknown-linux-musl.tar.gz"
+ UV_PIN_MIRROR="https://hermes-assets.nousresearch.com/upstream/sha256/0643b9fb8c9fb27458e709ce6ff939695013c41975ff7b02d3f3b138d8d4bdb3"
+ UV_PIN_SHA256="0643b9fb8c9fb27458e709ce6ff939695013c41975ff7b02d3f3b138d8d4bdb3"
+ ;;
+ linux-arm64-musl)
+ UV_PIN_URL="https://github.com/astral-sh/uv/releases/download/0.12.3/uv-aarch64-unknown-linux-musl.tar.gz"
+ UV_PIN_MIRROR="https://hermes-assets.nousresearch.com/upstream/sha256/fa513fca1eb2913334c944fe9adbdd410274a1cbe8dd05d03699a9eb85311d4e"
+ UV_PIN_SHA256="fa513fca1eb2913334c944fe9adbdd410274a1cbe8dd05d03699a9eb85311d4e"
+ ;;
darwin-x64)
UV_PIN_URL="https://github.com/astral-sh/uv/releases/download/0.12.3/uv-x86_64-apple-darwin.tar.gz"
UV_PIN_MIRROR="https://hermes-assets.nousresearch.com/upstream/sha256/4c9f52262a14da336e4a42ed24992d12d0c956acde87619e4611d321dffa602b"
@@ -207,7 +217,13 @@ uv_bootstrap_target() {
*) return 1 ;;
esac
case "$(uname -s)" in
- Linux) echo "linux-$_arch" ;;
+ Linux)
+ if ldd --version 2>&1 | grep -qi musl; then
+ echo "linux-$_arch-musl"
+ else
+ echo "linux-$_arch"
+ fi
+ ;;
Darwin) echo "darwin-$_arch" ;;
*) return 1 ;;
esac
diff --git a/tests/pm/test_pm_musl.py b/tests/pm/test_pm_musl.py
index 0d33ec42981..add8b69bea1 100644
--- a/tests/pm/test_pm_musl.py
+++ b/tests/pm/test_pm_musl.py
@@ -29,6 +29,7 @@ def test_current_target_detects_musl_from_python_build_metadata(monkeypatch):
monkeypatch.setattr(store, "_native_machine", lambda: "x86_64")
monkeypatch.setattr(store, "_is_bionic_libc", lambda: False)
+ monkeypatch.setattr(store, "_native_linux_uses_musl", lambda: None)
monkeypatch.setattr(
sysconfig,
"get_config_var",
@@ -59,6 +60,15 @@ def test_musl_detection_falls_back_to_native_userland(monkeypatch):
assert store._is_musl_libc() is True
+def test_native_glibc_overrides_foreign_musl_bootstrap(monkeypatch):
+ from pm import store
+
+ monkeypatch.setattr(store, "_native_linux_uses_musl", lambda: False)
+ monkeypatch.setattr(sysconfig, "get_config_var", lambda _key: "x86_64-unknown-linux-musl")
+
+ assert store._is_musl_libc() is False
+
+
def test_bionic_remains_more_specific_than_musl(monkeypatch):
from pm import store
@@ -74,7 +84,7 @@ def test_required_runtime_has_native_musl_pins(target):
"""Every runtime tool PM selects by default has an artifact for musl."""
lock = Lockfile(REPO_ROOT / "pm" / "lock.json")
- for name in ("python", "uv", "node", "npm", "ffmpeg", "ripgrep"):
+ for name in ("python", "uv", "node", "npm", "ripgrep"):
assert get_package(name).missing_reason(target) is None, name
assert lock.artifacts(name, target), f"{name} has no {target} artifact"
@@ -96,24 +106,24 @@ def test_interpreter_and_js_runtime_never_reuse_glibc_rows(target):
def test_static_linux_tools_reuse_the_reviewed_bytes(target, base):
lock = Lockfile(REPO_ROOT / "pm" / "lock.json")
- for name in ("ffmpeg", "ripgrep", "gh", "bws", "iron-proxy"):
+ for name in ("ripgrep", "gh", "bws", "iron-proxy"):
assert lock.artifacts(name, target) == lock.artifacts(name, base)
-def test_ffmpeg_musl_resolution_uses_static_linux_index(monkeypatch):
- from pm import packages
-
- package = packages.Ffmpeg()
- advertised = {
- "linux-x64": {
- "9.0.1": ("autobuild-test", "ffmpeg-test-linux64-static.tar.xz")
- }
- }
- monkeypatch.setattr(packages, "btbn_index", lambda: advertised)
-
- url = package.fetch_url("9.0.1", "linux-x64-musl")
[email protected]("target", _MUSL_TARGETS)
+def test_musl_default_closure_excludes_incompatible_ffmpeg(monkeypatch, target):
+ from pm import store
+ from pm.package import InstallError
+ from pm.registry import source_install_packages, tool_roots
- assert url.endswith("/autobuild-test/ffmpeg-test-linux64-static.tar.xz")
+ lock = Lockfile(REPO_ROOT / "pm" / "lock.json")
+ monkeypatch.setattr(store, "current_target", lambda: target)
+ assert get_package("ffmpeg").missing_reason(target)
+ assert lock.artifacts("ffmpeg", target) == []
+ assert "ffmpeg" not in source_install_packages(lock.names())
+ assert "ffmpeg" not in tool_roots(lock.names())
+ with pytest.raises(InstallError, match="unavailable on"):
+ get_package("ffmpeg").fetch_url(lock.version("ffmpeg"), target)
@pytest.mark.parametrize("target", _MUSL_TARGETS)
diff --git a/tests/scripts/install/test_install_sh_musl_uv_bootstrap.py b/tests/scripts/install/test_install_sh_musl_uv_bootstrap.py
new file mode 100644
index 00000000000..e69d0a861fc
--- /dev/null
+++ b/tests/scripts/install/test_install_sh_musl_uv_bootstrap.py
@@ -0,0 +1,32 @@
+"""The standalone shell installer selects the lockfile's native uv pin."""
+
+import json
+import subprocess
+from pathlib import Path
+
+import pytest
+
+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):
+ 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"; }
+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],
+ check=True, capture_output=True, text=True,
+ )
+ row = json.loads((ROOT / "pm" / "lock.json").read_text())["packages"]["uv"]["artifacts"][target]
+ assert result.stdout.splitlines() == [target, row["url"], row["sha256"]]