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

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

1 participant