Properly propagate the optimization flags to C extensions

Resolves: RHEL-49615
This commit is contained in:
Charalampos Stratakis 2024-07-25 19:16:27 +02:00
parent a5cbec13ee
commit 8640cc2e82
2 changed files with 15 additions and 8 deletions

View File

@ -20,7 +20,7 @@ URL: https://www.python.org/
#global prerel ... #global prerel ...
%global upstream_version %{general_version}%{?prerel} %global upstream_version %{general_version}%{?prerel}
Version: %{general_version}%{?prerel:~%{prerel}} Version: %{general_version}%{?prerel:~%{prerel}}
Release: 2%{?dist} Release: 3%{?dist}
License: Python-2.0.1 License: Python-2.0.1
@ -207,8 +207,6 @@ Provides: bundled(python3dist(packaging)) = 23
# The -O flag for the compiler, debug builds # The -O flag for the compiler, debug builds
# -Wno-cpp avoids some warnings with -O0 # -Wno-cpp avoids some warnings with -O0
%global optflags_debug -O0 -Wno-cpp %global optflags_debug -O0 -Wno-cpp
# Remove the default -O2 flag, our flags are applied in %%build/%%install
%global __global_compiler_flags %(echo '%{__global_compiler_flags}' | sed 's/-O[[:digit:]]//')
# Disable automatic bytecompilation. The python3 binary is not yet be # Disable automatic bytecompilation. The python3 binary is not yet be
# available in /usr/bin when Python is built. Also, the bytecompilation fails # available in /usr/bin when Python is built. Also, the bytecompilation fails
@ -812,6 +810,7 @@ BuildPython() {
ConfName=$1 ConfName=$1
ExtraConfigArgs=$2 ExtraConfigArgs=$2
MoreCFlags=$3 MoreCFlags=$3
MoreCFlagsNodist=$4
# Each build is done in its own directory # Each build is done in its own directory
ConfDir=build/$ConfName ConfDir=build/$ConfName
@ -851,7 +850,7 @@ BuildPython() {
$ExtraConfigArgs \ $ExtraConfigArgs \
%{nil} %{nil}
%global flags_override EXTRA_CFLAGS="$MoreCFlags" CFLAGS_NODIST="$CFLAGS_NODIST $MoreCFlags" %global flags_override EXTRA_CFLAGS="$MoreCFlags" CFLAGS_NODIST="$CFLAGS_NODIST $MoreCFlags $MoreCFlagsNodist"
%if %{without bootstrap} %if %{without bootstrap}
# Regenerate generated files (needs python3) # Regenerate generated files (needs python3)
@ -874,11 +873,13 @@ BuildPython() {
# See also: https://bugzilla.redhat.com/show_bug.cgi?id=1818857 # See also: https://bugzilla.redhat.com/show_bug.cgi?id=1818857
BuildPython debug \ BuildPython debug \
"--without-ensurepip --with-pydebug" \ "--without-ensurepip --with-pydebug" \
"%{optflags_debug}" "%{optflags_debug}" \
""
%endif # with debug_build %endif # with debug_build
BuildPython optimized \ BuildPython optimized \
"--without-ensurepip %{optimizations_flag}" \ "--without-ensurepip %{optimizations_flag}" \
"" \
"%{optflags_optimized}" "%{optflags_optimized}"
# ====================================================== # ======================================================
@ -991,7 +992,7 @@ InstallPython debug \
# Now the optimized build: # Now the optimized build:
InstallPython optimized \ InstallPython optimized \
%{py_INSTSONAME_optimized} \ %{py_INSTSONAME_optimized} \
"%{optflags_optimized}" \ "" \
%{LDVERSION_optimized} %{LDVERSION_optimized}
# Install directories for additional packages # Install directories for additional packages
@ -1713,6 +1714,9 @@ CheckPython optimized
# ====================================================== # ======================================================
%changelog %changelog
* Thu Jul 25 2024 Charalampos Stratakis <cstratak@redhat.com> - 3.12.4-3
- Properly propagate the optimization flags to C extensions
* Wed Jul 17 2024 Charalampos Stratakis <cstratak@redhat.com> - 3.12.4-2 * Wed Jul 17 2024 Charalampos Stratakis <cstratak@redhat.com> - 3.12.4-2
- Build Python with -O3 - Build Python with -O3
- https://fedoraproject.org/wiki/Changes/Python_built_with_gcc_O3 - https://fedoraproject.org/wiki/Changes/Python_built_with_gcc_O3

View File

@ -34,9 +34,12 @@
- debugtest: - debugtest:
dir: python/selftest dir: python/selftest
run: "VERSION={{ pybasever }} PYTHON=python{{ pybasever }}d X='-i test_check_probes' ./parallel.sh" run: "VERSION={{ pybasever }} PYTHON=python{{ pybasever }}d X='-i test_check_probes' ./parallel.sh"
- optimizedflags: - optimizedflags_self:
dir: python/flags dir: python/flags
run: "python{{ pybasever }} ./assertflags.py -O3" run: "python{{ pybasever }} ./assertflags.py -O3 PY_BUILTIN_MODULE_CFLAGS PY_CFLAGS_NODIST PY_CORE_CFLAGS PY_STDMODULE_CFLAGS"
- optimizedflags_3rd:
dir: python/flags
run: "python{{ pybasever }} ./assertflags.py -O2 CFLAGS PY_CFLAGS"
- debugflags: - debugflags:
dir: python/flags dir: python/flags
run: "python{{ pybasever }}d ./assertflags.py -O0" run: "python{{ pybasever }}d ./assertflags.py -O0"