Skip to content

Commit 8964d1e

Browse files
fix: add another heuristic for libc discovery (#564)
* fix: add another heuristic for libc discovery * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix heuristic --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent fb071da commit 8964d1e

24 files changed

+97
-24
lines changed

scripts/create-arch-wheels.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ set -eux
77

88
SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)"
99
INTEGRATION_TEST_DIR="${SCRIPT_DIR}/../tests/integration"
10-
mkdir -p "${INTEGRATION_TEST_DIR}/arch-wheels"
10+
mkdir -p "${INTEGRATION_TEST_DIR}/arch-wheels/glibc"
11+
mkdir -p "${INTEGRATION_TEST_DIR}/arch-wheels/musllinux_1_2"
1112

1213
# "mips64le" built with buildpack-deps:bookworm and renamed cp313-cp313
13-
# "386" "amd64" "arm/v5" "arm/v7" "arm64/v8"
14-
for ARCH in "ppc64le" "riscv64" "s390x"; do
14+
for ARCH in "386" "amd64" "arm/v5" "arm/v7" "arm64/v8" "ppc64le" "riscv64" "s390x"; do
1515
docker run --platform linux/${ARCH} -i --rm -v "${INTEGRATION_TEST_DIR}:/tests" debian:trixie-20250203 << "EOF"
1616
# for, "arm/v5" QEMU will report armv7l, running on aarch64 will report aarch64, force armv5l/armv7l
1717
case "$(dpkg --print-architecture)" in
@@ -21,7 +21,19 @@ case "$(dpkg --print-architecture)" in
2121
esac
2222
DEBIAN_FRONTEND=noninteractive apt-get update
2323
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends gcc python3-pip python3-dev
24-
python3 -m pip wheel --no-deps -w /tests/arch-wheels /tests/testsimple
24+
python3 -m pip wheel --no-deps -w /tests/arch-wheels/glibc /tests/testsimple
2525
EOF
26+
done
2627

28+
for ARCH in "386" "amd64" "arm/v6" "arm/v7" "arm64/v8" "ppc64le" "riscv64" "s390x"; do
29+
docker run --platform linux/${ARCH} -i --rm -v "${INTEGRATION_TEST_DIR}:/tests" alpine:3.21 << "EOF"
30+
# for, "arm/v5" QEMU will report armv7l, running on aarch64 will report aarch64, force armv5l/armv7l
31+
case "$(cat /etc/apk/arch)" in
32+
armhf) export _PYTHON_HOST_PLATFORM="linux-armv6l";;
33+
armv7) export _PYTHON_HOST_PLATFORM="linux-armv7l";;
34+
*) ;;
35+
esac
36+
apk add gcc binutils musl-dev python3-dev py3-pip
37+
python3 -m pip wheel --no-deps -w /tests/arch-wheels/musllinux_1_2 /tests/testsimple
38+
EOF
2739
done

src/auditwheel/lddtree.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,17 @@ def ldd(
522522
if libc != Libc.GLIBC:
523523
msg = f"found a dependency on GLIBC but the libc is already set to {libc}"
524524
raise InvalidLibc(msg)
525+
if libc is None:
526+
# try the filename as a last resort
527+
if path.name.endswith(("-arm-linux-musleabihf.so", "-linux-musl.so")):
528+
libc = Libc.MUSL
529+
elif path.name.endswith(("-arm-linux-gnueabihf.so", "-linux-gnu.so")):
530+
# before python 3.11, musl was also using gnu
531+
soabi = path.stem.split(".")[-1].split("-")
532+
valid_python = tuple(f"3{minor}" for minor in range(11, 100))
533+
if soabi[0] == "cpython" and soabi[1].startswith(valid_python):
534+
libc = Libc.GLIBC
535+
525536
if ldpaths is None:
526537
ldpaths = load_ld_paths(libc).copy()
527538
# Propagate the rpaths used by the main ELF since those will be

src/auditwheel/libc.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import re
66
import subprocess
77
from dataclasses import dataclass
8-
from enum import IntEnum
8+
from enum import Enum
99
from pathlib import Path
1010

1111
from .error import InvalidLibc
@@ -19,9 +19,14 @@ class LibcVersion:
1919
minor: int
2020

2121

22-
class Libc(IntEnum):
23-
GLIBC = (1,)
24-
MUSL = (2,)
22+
class Libc(Enum):
23+
value: str
24+
25+
GLIBC = "glibc"
26+
MUSL = "musl"
27+
28+
def __str__(self) -> str:
29+
return self.value
2530

2631
def get_current_version(self) -> LibcVersion:
2732
if self == Libc.MUSL:

src/auditwheel/policy/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from ..architecture import Architecture
1313
from ..elfutils import filter_undefined_symbols
14+
from ..error import InvalidLibc
1415
from ..lddtree import DynamicExecutable
1516
from ..libc import Libc
1617
from ..tools import is_subdir
@@ -62,8 +63,13 @@ def __init__(
6263
raise ValueError(msg)
6364
if libc == Libc.MUSL:
6465
if musl_policy is None:
65-
musl_version = libc.get_current_version()
66-
musl_policy = f"musllinux_{musl_version.major}_{musl_version.minor}"
66+
try:
67+
musl_version = libc.get_current_version()
68+
musl_policy = f"musllinux_{musl_version.major}_{musl_version.minor}"
69+
except InvalidLibc:
70+
logger.warning(
71+
"can't determine musl libc version, latest known version will be used."
72+
)
6773
elif _MUSL_POLICY_RE.match(musl_policy) is None:
6874
msg = f"Invalid 'musl_policy': '{musl_policy}'"
6975
raise ValueError(msg)
@@ -106,6 +112,9 @@ def __init__(
106112
self._policies.sort()
107113

108114
if self._libc_variant == Libc.MUSL:
115+
if musl_policy is None:
116+
self._musl_policy = "_".join(self._policies[1].name.split("_")[0:3])
117+
self._policies = [self._policies[0], self._policies[1]]
109118
assert len(self._policies) == 2, self._policies
110119

111120
def __iter__(self) -> Generator[Policy]:
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)