Visitar URL original
fix: detect musl libc when downloading python-build-standalone by henryiii · Pull Request #2889 · pypa/cibuildwheel · GitHub
Skip to content

fix: detect musl libc when downloading python-build-standalone - #2889

Merged
henryiii merged 2 commits into
pypa:mainfrom
henryiii:fix-musl-pbs-detection
Jun 3, 2026
Merged

henryiii merged 2 commits into
pypa:mainfrom
henryiii:fix-musl-pbs-detection

Conversation

@henryiii

@henryiii henryiii commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

The current check is never true. Using ('', '') might assume musl for something like portable Python, so used a more complex check.

🤖 AI text below 🤖

Problem

platform.libc_ver() only ever reports glibc — it returns ("", "") on musl systems. The musl detection in python_build_standalone.py:

libc_identifier = "musl" if "musl" in (platform.libc_ver() or ("", "")) else "gnu"

could therefore never be true, so musl hosts (e.g. Alpine) always selected the gnu python-build-standalone asset, which won't run there.

Fix

Detect musl by shelling out to ldd --version, which prints musl libc on musl-based systems (and GLIBC/GNU libc on glibc). This probes the actual system loader rather than the host Python's linkage, so it stays correct even when cibuildwheel runs under a relocatable/statically-linked interpreter (including a python-build-standalone one). Falls back to glibc when ldd is unavailable.

Adds unit tests for musl/glibc/missing-ldd detection and the resulting libc identifier.

`platform.libc_ver()` only ever reports glibc and returns `("", "")` on
musl systems, so `"musl" in platform.libc_ver()` was never true and musl
hosts (e.g. Alpine) always selected the `gnu` python-build-standalone
asset, which won't run.

Detect musl by shelling out to `ldd --version`, which prints "musl libc"
on musl-based systems. This probes the actual system loader rather than
the host Python's linkage, so it stays correct even when cibuildwheel
runs under a relocatable/statically-linked interpreter. Falls back to
glibc when `ldd` is unavailable.

Assisted-by: ClaudeCode:claude-opus-4.8
Assisted-by: ClaudeCode:claude-opus-4.8

@joerick joerick left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Not sure how I ended up with the libc_ver() approach!

@henryiii
henryiii merged commit 4ae5909 into pypa:main Jun 3, 2026
45 checks passed
@henryiii
henryiii deleted the fix-musl-pbs-detection branch June 3, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants