You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
checksharedmods uses the wrong Python interpreter in native builds with --with-build-python #162308
[PR #161530](#161530) proposes setting _PYTHON_HOST_PLATFORM only during cross-compilation.
Previously, when --with-build-python was specified, _PYTHON_HOST_PLATFORM was set even for native builds (to an empty string). This caused incorrect platform information, as described in [#140266](#140266).
It also caused Tools/build/check_extension_modules.py to treat native builds as cross-compilation:
default="_PYTHON_HOST_PLATFORM"inos.environ
Consequently, it used check_module_cross() instead of check_module_import(), skipping actual extension module imports.
PR #161530 corrects this behavior, but also exposes another issue in Makefile.pre.in:
In a native build, PYTHON_FOR_BUILD points to the external interpreter when --with-build-python is specified, rather than the newly built ./python.
This can cause incorrect extension module validation if the two interpreters have different module configurations.
Example
Consider a native build where:
The external build Python has _bisect and _bz2 as shared extensions.
The target CPython builds these modules as built-ins.
When check_module_import() runs under the external build Python, it fails with:
[ERROR] _bisect failed to import: '_bisect' is not a built-in module
[ERROR] Cannot mark builtin module '_bisect' as failed!
[ERROR] _bz2 failed to import: '_bz2' is not a built-in module
[ERROR] Cannot mark builtin module '_bz2' as failed!
These errors reflect the external build Python's module configuration, not necessarily a problem with the target CPython.
Expected behavior
For native builds, checksharedmods should use the newly built target interpreter (./$(BUILDPYTHON)) to validate extension modules, regardless of whether --with-build-python is specified.
For cross-compilation, it should continue using the external build Python with cross-compilation checks.
Would it make sense to adjust the checksharedmods recipe to select the interpreter based on whether the build is cross-compiling, rather than always using PYTHON_FOR_BUILD?
I agree this is worth fixing before gh-161530 lands. That PR would expose the issue by making checksharedmods try to import the target's extensions with the external build Python.
Using the newly built Python for checksharedmods in native builds sounds reasonable to me. I haven't reviewed gh-162337 closely yet.
@superajun-wsj, I noticed you closed gh-162311. Did you run into anything we should take into account when reviewing gh-162337, or were you planning a follow-up?
@itamaro Thank you for your reply. We will keep an eye on this issue. #162311 was closed because we need to complete the CLA process first. Of course, we warmly welcome patches from other contributors that can resolve this issue.
Activity
Merge upstream main and retain native module-check selection
itamaro commentedon Nov 21, 2026
I agree this is worth fixing before gh-161530 lands. That PR would expose the issue by making
checksharedmodstry to import the target's extensions with the external build Python.Using the newly built Python for
checksharedmodsin native builds sounds reasonable to me. I haven't reviewed gh-162337 closely yet.@superajun-wsj, I noticed you closed gh-162311. Did you run into anything we should take into account when reviewing gh-162337, or were you planning a follow-up?
superajun-wsj commentedon Nov 21, 2026
@itamaro Thank you for your reply. We will keep an eye on this issue. #162311 was closed because we need to complete the CLA process first. Of course, we warmly welcome patches from other contributors that can resolve this issue.