From c7bf53b4d659f6838c3f11044034e139cf01f939 Mon Sep 17 00:00:00 2001 From: Itamar Oren Date: Fri, 6 Nov 2026 20:46:11 -0800 Subject: [PATCH 1/2] gh-140266: Only pass _PYTHON_HOST_PLATFORM when cross compiling configure sets _PYTHON_HOST_PLATFORM only for cross builds, but passed it to the build Python for every --with-build-python build. In a native build it was empty, so sysconfig.get_platform() returned "" and build-details.json ended up with "platform": "". Co-authored-by: Zanie Blue Co-Authored-By: Claude Fable 5.1 --- .../Build/2026-11-06-12-00-00.gh-issue-140266.K3hP9z.rst | 3 +++ configure | 7 ++++++- configure.ac | 6 +++++- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Build/2026-11-06-12-00-00.gh-issue-140266.K3hP9z.rst diff --git a/Misc/NEWS.d/next/Build/2026-11-06-12-00-00.gh-issue-140266.K3hP9z.rst b/Misc/NEWS.d/next/Build/2026-11-06-12-00-00.gh-issue-140266.K3hP9z.rst new file mode 100644 index 000000000000000..399aca8a9bcff6c --- /dev/null +++ b/Misc/NEWS.d/next/Build/2026-11-06-12-00-00.gh-issue-140266.K3hP9z.rst @@ -0,0 +1,3 @@ +Fix ``"platform": ""`` in ``build-details.json`` for native builds configured +with :option:`--with-build-python`: :envvar:`!_PYTHON_HOST_PLATFORM` is now +only passed to the build interpreter when cross compiling. diff --git a/configure b/configure index fca5669c3756b4d..9abbe58a86d375a 100755 --- a/configure +++ b/configure @@ -3829,7 +3829,12 @@ fi fi ac_cv_prog_PYTHON_FOR_REGEN=$with_build_python PYTHON_FOR_FREEZE="$with_build_python" - PYTHON_FOR_BUILD='_PYTHON_PROJECT_BASE=$(abs_builddir) _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(srcdir)/Lib _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata_$(ABIFLAGS)_$(MACHDEP)_$(MULTIARCH) _PYTHON_SYSCONFIGDATA_PATH=$(shell test -f pybuilddir.txt && echo $(abs_builddir)/`cat pybuilddir.txt`) '$with_build_python + PYTHON_FOR_BUILD='_PYTHON_PROJECT_BASE=$(abs_builddir) PYTHONPATH=$(srcdir)/Lib _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata_$(ABIFLAGS)_$(MACHDEP)_$(MULTIARCH) _PYTHON_SYSCONFIGDATA_PATH=$(shell test -f pybuilddir.txt && echo $(abs_builddir)/`cat pybuilddir.txt`) '$with_build_python + if test "x$cross_compiling" = xyes +then : + PYTHON_FOR_BUILD='_PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) '"$PYTHON_FOR_BUILD" + +fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $with_build_python" >&5 printf "%s\n" "$with_build_python" >&6; } diff --git a/configure.ac b/configure.ac index 753f997a20da4a2..6d7ed9b77da339e 100644 --- a/configure.ac +++ b/configure.ac @@ -170,7 +170,11 @@ AC_ARG_WITH([build-python], dnl Build Python interpreter is used for regeneration and freezing. ac_cv_prog_PYTHON_FOR_REGEN=$with_build_python PYTHON_FOR_FREEZE="$with_build_python" - PYTHON_FOR_BUILD='_PYTHON_PROJECT_BASE=$(abs_builddir) _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(srcdir)/Lib _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata_$(ABIFLAGS)_$(MACHDEP)_$(MULTIARCH) _PYTHON_SYSCONFIGDATA_PATH=$(shell test -f pybuilddir.txt && echo $(abs_builddir)/`cat pybuilddir.txt`) '$with_build_python + PYTHON_FOR_BUILD='_PYTHON_PROJECT_BASE=$(abs_builddir) PYTHONPATH=$(srcdir)/Lib _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata_$(ABIFLAGS)_$(MACHDEP)_$(MULTIARCH) _PYTHON_SYSCONFIGDATA_PATH=$(shell test -f pybuilddir.txt && echo $(abs_builddir)/`cat pybuilddir.txt`) '$with_build_python + dnl _PYTHON_HOST_PLATFORM is only set when cross compiling. + AS_VAR_IF([cross_compiling], [yes], + [PYTHON_FOR_BUILD='_PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) '"$PYTHON_FOR_BUILD"] + ) AC_MSG_RESULT([$with_build_python]) ], [ AS_VAR_IF([cross_compiling], [yes], From 51fa2643fffc3fc8ab50ba74e92f464c4fb56327 Mon Sep 17 00:00:00 2001 From: "wangshaojun.jeffery" Date: Fri, 20 Nov 2026 16:34:16 +0800 Subject: [PATCH 2/2] gh-162308: Check native extension modules with the target Python Select MODULE_CHECK_COMMAND from configure's cross_compiling state. Native builds use the newly built interpreter even when --with-build-python selects an external build Python. Cross builds keep using the build Python. Pass the check mode explicitly so an inherited _PYTHON_HOST_PLATFORM cannot skip native import checks. Use the selected command both when generating missing stdlib information and when reporting extension checks, since both paths check the modules. Exercise differing builtin module configurations in the existing Linux build-Python CI job, and add a Build NEWS entry. Regenerate configure with Autoconf 2.72. Based on PR #161530 at c7bf53b4d659f6838c3f11044034e139cf01f939. Validation: - Native and x86_64-to-AArch64 configure and make all builds passed. - The original recipe reports _bisect import errors twice; the fixed native recipe and inherited-platform check report zero import failures. - test_sysconfig, test_build_details, and test_tools.test_makefile passed (61 tests run, 8 skipped). - Workflow YAML, shell syntax, and git diff --check passed. Co-authored-by: TRAE CLI --- .github/workflows/build.yml | 10 +++++++++- Makefile.pre.in | 7 ++++--- .../2026-11-20-16-30-00.gh-issue-162308.Mk7pQ2.rst | 4 ++++ configure | 12 ++++++++++++ configure.ac | 7 +++++++ 5 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Build/2026-11-20-16-30-00.gh-issue-162308.Mk7pQ2.rst diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 07087b836cb597e..eb522ba41b9a25b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -549,9 +549,17 @@ jobs: run: | "$BUILD_DIR/host-python/bin/python3" -m test test_sysconfig test_site test_embed - name: Configure cross build - run: ./configure --prefix="$BUILD_DIR/cross-python" --with-build-python="$BUILD_DIR/host-python/bin/python3" + run: | + # Exercise a native build whose builtin modules differ from the build Python. + echo '_bisect _bisectmodule.c' > Modules/Setup.local + ./configure --prefix="$BUILD_DIR/cross-python" --with-build-python="$BUILD_DIR/host-python/bin/python3" - name: Install cross Python run: make -j8 install + - name: Check native extension modules with a build Python + run: | + "$BUILD_DIR/host-python/bin/python3" -c "import sys; assert '_bisect' not in sys.builtin_module_names" + "$BUILD_DIR/cross-python/bin/python3" -c "import _bisect, sys; assert '_bisect' in sys.builtin_module_names" + PYTHONSTRICTEXTENSIONBUILD=1 _PYTHON_HOST_PLATFORM=linux-x86_64 make checksharedmods - name: Display build info run: | "$BUILD_DIR/cross-python/bin/python3" -m test.pythoninfo diff --git a/Makefile.pre.in b/Makefile.pre.in index f1b5eb3bba34fd1..03e48061a8e9fbd 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -331,6 +331,7 @@ HOSTRUNNER= @HOSTRUNNER@ PYTHON_FOR_REGEN?=@PYTHON_FOR_REGEN@ UPDATE_FILE=$(PYTHON_FOR_REGEN) $(srcdir)/Tools/build/update_file.py PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@ +MODULE_CHECK_COMMAND=@MODULE_CHECK_COMMAND@ # Single-platform builds depend on $(BUILDPYTHON). Cross builds use an # external "build Python" and have an empty PYTHON_FOR_BUILD_DEPS. PYTHON_FOR_BUILD_DEPS=@PYTHON_FOR_BUILD_DEPS@ @@ -1604,11 +1605,11 @@ sharedmods: $(SHAREDMODS) pybuilddir.txt .PHONY: checksharedmods checksharedmods: sharedmods $(PYTHON_FOR_BUILD_DEPS) $(BUILDPYTHON) @if [ -n "@MISSING_STDLIB_CONFIG@" ]; then \ - $(RUNSHARED) $(PYTHON_FOR_BUILD) $(srcdir)/Tools/build/check_extension_modules.py --generate-missing-stdlib-info --with-missing-stdlib-config="@MISSING_STDLIB_CONFIG@"; \ + $(RUNSHARED) $(MODULE_CHECK_COMMAND) --generate-missing-stdlib-info --with-missing-stdlib-config="@MISSING_STDLIB_CONFIG@"; \ else \ - $(RUNSHARED) $(PYTHON_FOR_BUILD) $(srcdir)/Tools/build/check_extension_modules.py --generate-missing-stdlib-info; \ + $(RUNSHARED) $(MODULE_CHECK_COMMAND) --generate-missing-stdlib-info; \ fi - @$(RUNSHARED) $(PYTHON_FOR_BUILD) $(srcdir)/Tools/build/check_extension_modules.py + @$(RUNSHARED) $(MODULE_CHECK_COMMAND) .PHONY: rundsymutil rundsymutil: sharedmods $(PYTHON_FOR_BUILD_DEPS) $(BUILDPYTHON) diff --git a/Misc/NEWS.d/next/Build/2026-11-20-16-30-00.gh-issue-162308.Mk7pQ2.rst b/Misc/NEWS.d/next/Build/2026-11-20-16-30-00.gh-issue-162308.Mk7pQ2.rst new file mode 100644 index 000000000000000..90a734551591f83 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2026-11-20-16-30-00.gh-issue-162308.Mk7pQ2.rst @@ -0,0 +1,4 @@ +Use the newly built interpreter to check extension modules in native builds +configured with :option:`--with-build-python`. This also applies when +generating missing standard library module information. Cross builds continue +to use the build interpreter without importing target extension modules. diff --git a/configure b/configure index 9abbe58a86d375a..79c143f1dd0bdcd 100755 --- a/configure +++ b/configure @@ -1041,6 +1041,7 @@ FREEZE_MODULE FREEZE_MODULE_BOOTSTRAP_DEPS FREEZE_MODULE_BOOTSTRAP PYTHON_FOR_FREEZE +MODULE_CHECK_COMMAND PYTHON_FOR_BUILD host_os host_vendor @@ -3854,6 +3855,17 @@ fi +# Module import checks must run with the target interpreter on native builds. +if test "x$cross_compiling" = xyes +then : + MODULE_CHECK_COMMAND='$(PYTHON_FOR_BUILD) $(srcdir)/Tools/build/check_extension_modules.py --cross-compiling' +else case e in #( + e) MODULE_CHECK_COMMAND='./$(BUILDPYTHON) -E $(srcdir)/Tools/build/check_extension_modules.py --no-cross-compiling' + ;; +esac +fi + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for Python interpreter freezing" >&5 printf %s "checking for Python interpreter freezing... " >&6; } { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $PYTHON_FOR_FREEZE" >&5 diff --git a/configure.ac b/configure.ac index 6d7ed9b77da339e..fa77530d2b0480e 100644 --- a/configure.ac +++ b/configure.ac @@ -186,6 +186,13 @@ AC_ARG_WITH([build-python], ) AC_SUBST([PYTHON_FOR_BUILD]) +# Module import checks must run with the target interpreter on native builds. +AS_VAR_IF([cross_compiling], [yes], + [MODULE_CHECK_COMMAND='$(PYTHON_FOR_BUILD) $(srcdir)/Tools/build/check_extension_modules.py --cross-compiling'], + [MODULE_CHECK_COMMAND='./$(BUILDPYTHON) -E $(srcdir)/Tools/build/check_extension_modules.py --no-cross-compiling'] +) +AC_SUBST([MODULE_CHECK_COMMAND]) + AC_MSG_CHECKING([for Python interpreter freezing]) AC_MSG_RESULT([$PYTHON_FOR_FREEZE]) AC_SUBST([PYTHON_FOR_FREEZE])