Repository navigation
Description
Bug report
Description
[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" in os.environConsequently, 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:
checksharedmods: sharedmods $(PYTHON_FOR_BUILD_DEPS) $(BUILDPYTHON)
@$(RUNSHARED) $(PYTHON_FOR_BUILD) $(srcdir)/Tools/build/check_extension_modules.pyIn 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
_bisectand_bz2as 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?
CPython versions tested on:
3.9 ~ 3.15
Operating systems tested on:
Linux
Linked PRs
- gh-162308: Check native extension modules with the target interpreter #162311
- gh-162308: Check modules with target Python in native builds #162337
- [3.15] gh-162308: Check native extension modules with the target interpreter (GH-162311) #162560
- [3.14] gh-162308: Check native extension modules with the target interpreter (GH-162311) #162561
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.
superajun-wsj commentedon Nov 23, 2026
@itamaro We have completed the CLA signing process. MR #162311 has been reopened. Your review and comments are welcome. Thank you.
Merge branch 'main' into fix/pythongh-162308-native-module-check
pythongh-162308: Check native extension modules with the target Python
gh-162308: Check native extension modules with the target interpreter (…
pythongh-162308: Check native extension modules with the target inter…
[3.14] pythongh-162308: Check native extension modules with the targe…
[3.15] gh-162308: Check native extension modules with the target inte…
[3.14] gh-162308: Check native extension modules with the target inte…