-
-
Notifications
You must be signed in to change notification settings - Fork 314
Use standard extension configuration for CPython 3.12+ #1180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
163441c
defce0f
4b5c2e9
91f8a5f
431203c
e089aab
37f4528
a33d26f
75aaef8
4c867b2
6f54839
670f889
25f44c1
3362de8
9311946
330490c
a77eb2c
901d9f2
47a7f34
8d605bd
43af7bf
6d546ed
ac6dbd6
49e1f0b
2c7047d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,21 @@ export PKG_CONFIG_PATH=${TOOLS_PATH}/deps/share/pkgconfig:${TOOLS_PATH}/deps/lib | |
| # Ensure that `pkg-config` invocations include the static libraries | ||
| export PKG_CONFIG="pkg-config --static" | ||
|
|
||
| # Dependency pkg-config files use /tools/deps as their prefix. macOS builds | ||
| # extract dependencies into a temporary directory, so have pkgconf relocate | ||
| # their prefix based on the location of each .pc file. | ||
| if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then | ||
| export PKG_CONFIG="${PKG_CONFIG} --define-prefix" | ||
|
|
||
| if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_12}" ]; then | ||
| # On macOS, CPython prefers the system libffi and provides no way to | ||
| # select a non-system version. Disable its system-library probe so | ||
| # _ctypes uses the bundled libffi instead. | ||
| # https://github.com/python/cpython/issues/155813 | ||
| export ac_cv_lib_ffi_ffi_call=no | ||
| fi | ||
| fi | ||
|
|
||
| # configure somehow has problems locating llvm-profdata even though it is in | ||
| # PATH. The macro it is using allows us to specify its path via an | ||
| # environment variable. | ||
|
|
@@ -203,23 +218,12 @@ if [[ -n "${PYTHON_MEETS_MAXIMUM_VERSION_3_10}" ]]; then | |
| patch -p1 -i "${ROOT}/patch-posixmodule-remove-system.patch" | ||
| fi | ||
|
|
||
| # Python 3.11 has configure support for configuring extension modules. We really, | ||
| # really, really want to use this feature because it looks promising. But at the | ||
| # time we added this code the functionality didn't support all extension modules | ||
| # nor did it easily support static linking, including static linking of extra | ||
| # libraries (which appears to be a limitation of `makesetup`). So for now we | ||
| # disable the functionality and require our auto-generated Setup.local to provide | ||
| # everything. | ||
| if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_11}" ]; then | ||
| if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_12}" ]; then | ||
| # This sets MODULE_<NAME>_STATE=disabled in the Makefile for all extension | ||
| # modules that are not unavailable (n/a) based on the platform. | ||
| # Valid STATE variables are needed to create the _missing_stdlib_info.py | ||
| # file during the build in Python 3.15+ | ||
| patch -p1 -i "${ROOT}/patch-configure-disable-stdlib-mod-3.12.patch" | ||
| else | ||
| patch -p1 -i "${ROOT}/patch-configure-disable-stdlib-mod.patch" | ||
| fi | ||
| # CPython 3.11 does not configure every standard-library extension, so disable | ||
| # its incomplete generated rules and supply all rules through Setup.local. | ||
| # CPython 3.12+ uses Setup.stdlib with a small Setup.local for per-module | ||
| # link-type overrides. | ||
| if [ "${PYTHON_MAJMIN_VERSION}" = "3.11" ]; then | ||
| patch -p1 -i "${ROOT}/patch-configure-disable-stdlib-mod.patch" | ||
|
|
||
| # This hack also prevents the conditional definition of the pwd module in | ||
| # Setup.bootstrap.in from working. So we remove that conditional. | ||
|
|
@@ -247,17 +251,6 @@ else | |
| patch -p1 -i "${ROOT}/patch-pgo-file-pool-3.11.patch" | ||
| fi | ||
|
|
||
| # There's a post-build Python script that verifies modules were | ||
| # built correctly. Ideally we'd invoke this. But our nerfing of | ||
| # the configure-based module building and replacing it with our | ||
| # own Setup-derived version completely breaks assumptions in this | ||
| # script. So leave it off for now... at our own peril. | ||
| if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_15}" ]; then | ||
| patch -p1 -i "${ROOT}/patch-checksharedmods-disable-3.15.patch" | ||
| elif [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_12}" ]; then | ||
| patch -p1 -i "${ROOT}/patch-checksharedmods-disable.patch" | ||
| fi | ||
|
|
||
| # CPython < 3.11 always linked against libcrypt. We backport part of | ||
| # upstream commit be21706f3760bec8bd11f85ce02ed6792b07f51f to avoid this | ||
| # behavior. | ||
|
|
@@ -385,13 +378,6 @@ if [[ "${CC}" = "clang" && -n "${PYTHON_MEETS_MINIMUM_VERSION_3_14}" ]]; then | |
| EXTRA_CONFIGURE_FLAGS="${EXTRA_CONFIGURE_FLAGS} --with-tail-call-interp" | ||
| fi | ||
|
|
||
| # On Python 3.12+ we need to link the special hacl library provided some SHA-256 | ||
| # implementations. Since we hack up the regular extension building mechanism, we | ||
| # need to reinvent this wheel. | ||
| if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_12}" ]; then | ||
| LDFLAGS="${LDFLAGS} -LModules/_hacl" | ||
| fi | ||
|
|
||
| # On PPC we need to prevent the glibc 2.22 __tls_get_addr_opt symbol | ||
| # from being introduced to preserve runtime compatibility with older | ||
| # glibc. | ||
|
|
@@ -421,6 +407,23 @@ CONFIGURE_FLAGS=" | |
| --without-ensurepip | ||
| ${EXTRA_CONFIGURE_FLAGS}" | ||
|
|
||
| if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_12}" ]; then | ||
| # Build standard-library extensions as built-ins by default. Setup.local | ||
| # overrides only the extensions that must remain shared or disabled. | ||
| CONFIGURE_FLAGS="${CONFIGURE_FLAGS} MODULE_BUILDTYPE=static --enable-loadable-sqlite-extensions" | ||
| fi | ||
|
|
||
| if [[ "${PYTHON_MAJMIN_VERSION}" = "3.12" && "${PYBUILD_PLATFORM}" = macos* ]]; then | ||
| # CPython 3.12 always uses UNIVERSAL on macOS for libmpdec, | ||
| # while the bundled dependency requires CONFIG_64. | ||
| export LIBMPDEC_CFLAGS="-DCONFIG_64=1" | ||
| fi | ||
|
|
||
| if [[ "${PYTHON_MAJMIN_VERSION}" = "3.12" && "${TARGET_TRIPLE}" == *-linux-* ]]; then | ||
| # The panelw archive needs ncursesw during configure's link probe. | ||
| export PANEL_CFLAGS="-I${TOOLS_PATH}/deps/include/ncursesw" | ||
| export PANEL_LIBS="-lpanelw -lncursesw" | ||
| fi | ||
|
|
||
| # Build a libpython3.x.so, but statically link the interpreter against | ||
| # libpython. | ||
|
|
@@ -641,13 +644,6 @@ if [[ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_13}" && "${TARGET_TRIPLE}" == x86_64* | |
| PROFILE_TASK="${PROFILE_TASK} --ignore test.test_bytes.BytesTest.test_from_format" | ||
| fi | ||
|
|
||
| # ./configure tries to auto-detect whether it can build 128-bit and 256-bit SIMD helpers for HACL, | ||
| # but on x86-64 that requires v2 and v3 respectively, and on arm64 the performance is bad as noted | ||
| # in the comments, so just don't even try. (We should check if we can make this conditional) | ||
| if [[ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_14}" ]]; then | ||
| patch -p1 -i "${ROOT}/patch-python-configure-hacl-no-simd.patch" | ||
| fi | ||
|
|
||
| # We use ndbm on macOS and BerkeleyDB elsewhere. | ||
| if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then | ||
| CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --with-dbmliborder=ndbm" | ||
|
|
@@ -777,6 +773,12 @@ BOLT_COMMON_FLAGS="${BOLT_COMMON_FLAGS:-}" BOLT_APPLY_FLAGS="${BOLT_APPLY_FLAGS: | |
| # Supplement produced Makefile with our modifications. | ||
| cat ../Makefile.extra >> Makefile | ||
|
|
||
| if [[ "${PYBUILD_PLATFORM}" = macos* && -n "${PYTHON_MEETS_MINIMUM_VERSION_3_12}" ]]; then | ||
| # configure-derived MODLIBS uses plain -l flags. Hide symbols from bundled | ||
| # static dependency libraries in both libpython and the interpreter. | ||
| printf '\nMODLIBS := $(subst -l,-Xlinker -hidden-l,$(MODLIBS))\n' >> Makefile | ||
| fi | ||
|
|
||
| # Debian's PPC64LE GCC 6 defaults to PIE but selects the non-PIE startup object unless -pie is | ||
| # passed explicitly. Add it only to LINKFORSHARED, which CPython uses when linking executables. | ||
| # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81170. | ||
|
|
@@ -1112,9 +1114,6 @@ if linux_uapi_include_arch: | |
| "", | ||
| ) | ||
| replace_in_all("-isystem %s/deps/linux-uapi/usr/include" % tools_path, "") | ||
| # See https://github.com/python/cpython/issues/145810#issuecomment-4068139183 | ||
| replace_in_all("-LModules/_hacl", "") | ||
|
Comment on lines
-1115
to
-1116
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This flag is no longer being added to LDFLAGS (see the removal of lines 388-394) so it no longer leaks into sysconfig.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For verification I checked the The pattern that used to be replaced does not appear in sysconfig or elsewhere. |
||
|
|
||
| EOF | ||
|
|
||
| ${BUILD_PYTHON} "${ROOT}/hack_sysconfig.py" "${ROOT}/out/python" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #!/usr/bin/env bash | ||
| # This Source Code Form is subject to the terms of the Mozilla Public | ||
| # License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| # file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
|
||
| set -ex | ||
|
|
||
| ROOT=$(pwd) | ||
|
|
||
| export PATH=${TOOLS_PATH}/${TOOLCHAIN}/bin:${TOOLS_PATH}/host/bin:$PATH | ||
|
|
||
| tar -xf "pkgconf-${PKGCONF_VERSION}.tar.xz" | ||
|
|
||
| pushd "pkgconf-${PKGCONF_VERSION}" | ||
|
|
||
| CC="${HOST_CC}" CXX="${HOST_CXX}" CFLAGS="${EXTRA_HOST_CFLAGS} -fPIC" CPPFLAGS="${EXTRA_HOST_CFLAGS} -fPIC" LDFLAGS="${EXTRA_HOST_LDFLAGS}" ./configure \ | ||
| --build="${BUILD_TRIPLE}" \ | ||
| --prefix=/tools/host \ | ||
| --disable-shared \ | ||
| --disable-dependency-tracking \ | ||
| --with-system-libdir=/usr/lib \ | ||
| --with-system-includedir=/usr/include | ||
|
|
||
| make -j "${NUM_CPUS}" | ||
| make -j "${NUM_CPUS}" install DESTDIR="${ROOT}/out" | ||
|
|
||
| ln -s pkgconf "${ROOT}/out/tools/host/bin/pkg-config" | ||
|
|
||
| "${ROOT}/out/tools/host/bin/pkg-config" --version |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this resolved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Portions of this comment are incorrect, the behavior of configure is safe.
The check that configure performs is to determine if the compiler supports the necessary flags (
-msse,-mavx2, etc) to allow the SIMD helpers to be built.On Linux x86-64 these flags are supported by LLVM so the helpers are built:
A runtime check is performed before dispatching to these function, the availability of these helpers does not change the baseline x86-64 requirement.
On macOS arm64 the check fails and the SIMD helpers are not built:
On macOS x86-64 the check succeeds and the universal2 versions of the SIMD helpers are built. The universal2 wrapper prevents the SIMD implementations from being included when building the arm64 portion of the universal2 library but this never comes into play because only the x86-64 portion of the library is built.
The runtime check is done so these helpers are only used when the host indicates support. When running on native x86-64 hardware this depends on the host CPU. When running on Apple Silicon under Rosetta2, the behavior depends on what features Rosetta advertises. The performance is intended by upstream and can be optimized by the user by using to the build that matches the host architecture.