Skip to content

gh-162323: Preserve the build platform in sysconfig.get_platform() - #162336

Open
hetaozdh wants to merge 1 commit into
python:mainfrom
hetaozdh:codex/gh-162323-sysconfig-build-platform
Open

hetaozdh wants to merge 1 commit into
python:mainfrom
hetaozdh:codex/gh-162323-sysconfig-build-platform

Conversation

@hetaozdh

@hetaozdh hetaozdh commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #162323.

On POSIX, sysconfig.get_platform() derives its result from the running kernel. The same Python build can therefore report different platforms when moved between compatible systems. For example, a 32-bit x86 build may report linux-i686 on its build machine but linux-x86_64 on a 64-bit kernel.

Record the platform as HOST_PLATFORM when generating the POSIX configuration data, and use that value at runtime. Keep platform detection available while bootstrapping the build, and preserve the _PYTHON_HOST_PLATFORM override for cross-compilation.

Also use the compiler target from MULTIARCH to correct architecture detection for native 32-bit x86 and ARM builds on 64-bit Linux kernels.

Add regression tests for architecture mismatches, cross-compilation overrides, and platform persistence in both generated configuration formats.

Validation

./python.exe -m test test_sysconfig test_build_details test__osx_support test_venv

All four test modules passed on macOS ARM64 with a free-threaded build: 144 tests, including 18 skips. Linux architecture mismatches are covered using mocked configuration and uname values.

AI assistance was used to investigate the issue and prepare the implementation and tests.

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #36052876 | 📁 Comparing 8e9b41b against main (e0d0f2e)

  🔍 Preview build  

2 files changed
± library/sysconfig.html
± whatsnew/changelog.html

@rgommers rgommers 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.

sysconfig.get_platform() already has a mix of build-time and runtime semantics. For example, on macOS 26 it returns macosx-11.0-arm64 for a Python built with a deployment target of 11.0. Similarly, on Windows it reflects the interpreter architecture rather than the machine architecture.

Reporting the interpreter architecture rather than the kernel architecture on Linux seems reasonable and consistent with existing behavior on other platforms. However, freezing the entire platform string at build time is a much broader change, with several backwards compatibility implications.

  • On platforms like FreeBSD and AIX, where the OS version component reflects the runtime environment, this may break wheel compatibility detection and result in incorrectly tagged newly built wheels.
  • On 32-bit ARM, the distinction between armv7l and armv8l matters for wheel compatibility. Freezing the architecture at build time can result in both missing and incorrectly accepted compatibility tags.
  • When cross-compiling CPython for 32-bit ARM, configure.ac sets the platform to linux-arm. Persisting that value would likely break manylinux wheel compatibility detection in pip and interpreter architecture detection in uv.

I'd suggest limiting the change to ensuring that the architecture component correctly reflects the interpreter rather than the kernel, while retaining the existing semantics of the OS version component. This requires particular care on 32-bit ARM and for cross-compiled interpreters. Note that the major installers already implement workarounds for the 32-bit interpreter on a 64-bit kernel issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sysconfig.get_platform should match the build platform

2 participants