Skip to content

Commit ef68371

Browse files
authored
Build without -Wconversion on GCC 9 (#1760)
<!-- Thank you for your contribution! --> ## What do these changes do? The re-tagged `v7.1.0` run got past the cp310 and cp311 armv7l wheels after #1759, then failed on cp312: GCC 9, which the `manylinux_2_31_armv7l` image ships, flags `_PyLong_CompactValue()` in CPython's own `cpython/longintrepr.h` under `-Wsign-conversion`, and `-Werror` makes that fatal. It is not specific to 32-bit or ARM: GCC 9 on x86_64 fails the same way for every CPython from 3.12 on, so building the sdist with Ubuntu 20.04's default compiler would break too. GCC 10, 11 and 12 are clean. `setup.py` now asks the configured compiler for its predefined macros and drops `-Wconversion` when it is GCC older than 10. Clang, MSVC and a compiler that cannot be probed keep the flags unchanged, so CI still builds with `-Wconversion` everywhere it did. The changelog entry goes into the unpublished 7.1.0 section next to the #1759 one, since the tag gets moved to this merge commit. ## Are there changes in behavior for the user? No; the C extension builds again with GCC 9. ## Is it a substantial burden for the maintainers to support this? No; the check can go once GCC 9 stops mattering. ## Related issue number Follow-up to #1759. Failed run: https://github.com/aio-libs/multidict/actions/runs/37833640970 ## Checklist - [x] I think the code is well written - [ ] Unit tests for the changes exist N/A, build fix; verified with GCC 9 builds as described below - [x] Documentation reflects the changes - [ ] If you provide code modification, please add yourself to `CONTRIBUTORS.txt` N/A - [ ] Add a new news fragment into the `CHANGES/` folder N/A, the entry is added to the unreleased 7.1.0 section of `CHANGES.rst` directly - [x] `make doc-spelling` passes and any new technical words are added to `docs/spelling_wordlist.txt` Drafted with Claude Code (Claude Opus 5.5); reviewed by @asvetlov. <details> <summary>Agent run details (optional, for reviewers)</summary> GCC 9.4 (Ubuntu 20.04 container), `-fsyntax-only` with the release flags against the CPython headers copied from `manylinux_2_31_armv7l`, `-m32 -funsigned-char`: 3.12 to 3.15t fail on `longintrepr.h` on master; the same on x86_64 against 3.12.7 to 3.15.0rc2 headers. GCC 10, 11 and 12 compile cleanly. `pip wheel` of master in the GCC 9 container with CPython 3.12.12 fails; with this `setup.py` it builds the wheel. With the host's GCC 15 both extensions still compile with `-Wconversion`, and the suite passes. Local cibuildwheel 4.2.1 under QEMU from this branch's sdist is still running: manylinux armv7l with tests, the other odd arches (aarch64, ppc64le, s390x, riscv64 for manylinux and musllinux, musllinux armv7l) build-only. Results will be added here. </details>
1 parent e812c4f commit ef68371

2 files changed

Lines changed: 42 additions & 4 deletions

File tree

‎CHANGES.rst‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ Bug fixes
5151
---------
5252

5353
- Fixed building the C extension on platforms where ``char`` is unsigned,
54-
such as ARM, PowerPC, s390x and RISC-V, which failed on a sign conversion
55-
warning since ``-Wconversion`` took effect -- by :user:`asvetlov`.
54+
such as ARM, PowerPC, s390x and RISC-V, and with GCC 9, which flags
55+
CPython's own headers from 3.12 on; both failed on a sign conversion
56+
warning since ``-Wconversion`` took effect. GCC 9 builds the extension
57+
without ``-Wconversion`` -- by :user:`asvetlov`.
5658

5759
*Related issues and pull requests on GitHub:*
58-
:issue:`1759`.
60+
:issue:`1759`, :issue:`1760`.
5961

6062
- Fixed :func:`~multidict.getversion` returning only the low 32 bits of
6163
the version on Windows and on 32-bit platforms, where two different

‎setup.py‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import os
22
import platform
3+
import re
4+
import subprocess
35
import sys
46

57
from setuptools import Extension, setup
8+
from setuptools.command.build_ext import build_ext
69

710
NO_EXTENSIONS = bool(os.environ.get("MULTIDICT_NO_EXTENSIONS"))
811
DEBUG_BUILD = bool(os.environ.get("MULTIDICT_DEBUG_BUILD"))
@@ -67,6 +70,39 @@
6770
]
6871

6972

73+
def _gcc_major(compiler):
74+
"""GCC's major version, or None for clang, MSVC and anything unknown."""
75+
cc = getattr(compiler, "compiler_so", None)
76+
if not cc:
77+
return None
78+
try:
79+
out = subprocess.run(
80+
[*cc, "-dM", "-E", "-x", "c", os.devnull],
81+
capture_output=True,
82+
check=True,
83+
text=True,
84+
).stdout
85+
except (OSError, subprocess.CalledProcessError):
86+
return None
87+
gnuc = re.search(r"^#define __GNUC__ (\d+)$", out, re.M)
88+
if gnuc is None or re.search(r"^#define __clang__ ", out, re.M):
89+
return None
90+
return int(gnuc.group(1))
91+
92+
93+
class BuildExt(build_ext):
94+
def build_extensions(self):
95+
major = _gcc_major(self.compiler)
96+
if major is not None and major < 10:
97+
# GCC 9 flags _PyLong_CompactValue() in CPython 3.12+'s own
98+
# headers under -Wsign-conversion.
99+
for ext in self.extensions:
100+
ext.extra_compile_args = [
101+
f for f in ext.extra_compile_args if f != "-Wconversion"
102+
]
103+
super().build_extensions()
104+
105+
70106
if not NO_EXTENSIONS:
71107
try:
72108
from Cython.Build import cythonize
@@ -96,7 +132,7 @@
96132
print("*********************")
97133
print("* Accelerated build *")
98134
print("*********************")
99-
setup(ext_modules=extensions)
135+
setup(ext_modules=extensions, cmdclass={"build_ext": BuildExt})
100136
else:
101137
print("*********************")
102138
print("* Pure Python build *")

0 commit comments

Comments
 (0)