From 2ec415b1c8ab6434ed0a82e11dc0fc90f7e5cbea Mon Sep 17 00:00:00 2001 From: "wangshaojun.jeffery" Date: Fri, 20 Nov 2026 16:34:16 +0800 Subject: [PATCH] gh-162308: Check native extension modules with the target Python Select the module checker from configure's cross-compiling state. Native builds use the target Python with RUNSHARED; cross builds use the external build Python without adding the target library path. Pass the check mode explicitly for both extension checks and missing stdlib info generation. Exercise differing builtin module configurations in the existing Linux build-Python CI job, using a strict check without _PYTHON_HOST_PLATFORM. Add a Build NEWS entry and regenerate configure with Autoconf 2.72. 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 50b0469867c1a4..650211815fd8d7 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 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 650838d68286c7..c265f9b3e1e44c 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -332,6 +332,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@ @@ -1605,11 +1606,11 @@ sharedmods: $(SHAREDMODS) pybuilddir.txt .PHONY: checksharedmods checksharedmods: sharedmods $(PYTHON_FOR_BUILD_DEPS) $(BUILDPYTHON) @if [ -n "@MISSING_STDLIB_CONFIG@" ]; then \ - $(RUNSHARED_FOR_BUILD) $(PYTHON_FOR_BUILD) $(srcdir)/Tools/build/check_extension_modules.py --generate-missing-stdlib-info --with-missing-stdlib-config="@MISSING_STDLIB_CONFIG@"; \ + $(MODULE_CHECK_COMMAND) --generate-missing-stdlib-info --with-missing-stdlib-config="@MISSING_STDLIB_CONFIG@"; \ else \ - $(RUNSHARED_FOR_BUILD) $(PYTHON_FOR_BUILD) $(srcdir)/Tools/build/check_extension_modules.py --generate-missing-stdlib-info; \ + $(MODULE_CHECK_COMMAND) --generate-missing-stdlib-info; \ fi - @$(RUNSHARED_FOR_BUILD) $(PYTHON_FOR_BUILD) $(srcdir)/Tools/build/check_extension_modules.py + @$(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 00000000000000..90a734551591f8 --- /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 b33ea2fb0c9bce..da44380d27a1ab 100755 --- a/configure +++ b/configure @@ -1042,6 +1042,7 @@ FREEZE_MODULE FREEZE_MODULE_BOOTSTRAP_DEPS FREEZE_MODULE_BOOTSTRAP PYTHON_FOR_FREEZE +MODULE_CHECK_COMMAND PYTHON_FOR_BUILD host_os host_vendor @@ -3855,6 +3856,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='$(RUNSHARED) ./$(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 b0368ae4b94e95..c73f8f2fd28a1c 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='$(RUNSHARED) ./$(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])