setuptools: [BUG] setuptools 75.7.0 and CFLAGS
setuptools version
75.7.0
Python version
3.12.8
OS
ALTLinux
Additional environment information
No response
Description
With https://github.com/pypa/distutils/issues/299 (merged to setuptools 75.7.0) the CFLAGS behavior changed.
Docs are not updated to that change and describe the previous state.
https://setuptools.pypa.io/en/latest/userguide/ext_modules.html#compiler-and-linker-options
The compiler options appear in the command line in the following order:
- first, the options provided by the sysconfig variable CFLAGS,
- then, the options provided by the environment variables CFLAGS and CPPFLAGS,
This is the behavior used for RPM build for long time. CFLAGS was/is used to append additional distro-specific options to the CPython’s ones.
After the aforementioned change CFLAGS env variable overrides sysconfigs CFLAGS and it’s no longer possible to supply additional flags.
So it’s a behavior change.
Expected behavior
There should be a way to pass additional flags for compilers according to documentation.
How to Reproduce
Try to build an extension with CFLAGS and without to see the difference in compiler flags.
Output
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17 (11 by maintainers)
Commits related to this issue
- Update CFLAGS docs to reflect distutils change Update the docs to reflect the distutils change for https://github.com/pypa/distutils/issues/299 in af7fcbb0d56ae14753db53acd8792eddb4d8f814. Closes: h... — committed to thesamesam/setuptools by thesamesam 2 years ago
- Update CFLAGS docs to reflect distutils change Update the docs to reflect the distutils change for https://github.com/pypa/distutils/issues/299 in af7fcbb0d56ae14753db53acd8792eddb4d8f814. Closes: h... — committed to thesamesam/setuptools by thesamesam 2 years ago
- Use Py_REFCNT to access cPersistentObject refcounts These assertions failed to compile if built without `-DNDEBUG`. As of setuptools 75.7.0, setting `CFLAGS` to anything while building an extension ... — committed to cjwatson/persistent by cjwatson 2 years ago
I still think it’s worth it for the reasons I mentioned in https://github.com/pypa/setuptools/issues/4836#issuecomment-2674578747. But not only that, the flags that CPython was built with aren’t necessarily the ones used – it depends on which variables were used (
NODISTor not), and the results of CPython’s configure tests. I just can’t see a situation where you could actually rely on any side-effects from that.To put it another way: I can’t see a realistic scenario where this affects someone adversely:
CFLAGSfor other build systems, and it’d be an odd way of going about it to inject only into CPython.NDEBUG, the issue is usually “we turned off asserts, and it turned out we were relying on side-effects in an assert”, but the reverse I’ve never seen happen (though possible) – and there it depended on your Python configuration too.I understand it’s a material change, I can’t see how it’s something you should’ve relied on ever because even with the old behaviour, you couldn’t predict it in many cases. It also prevented enabling assertions if you wanted them (i.e. I see it as actively harmful given it might make one think they’re testing something they’re not).
It causes problems to append for several cases, I can’t think of a case where it actually helps.
(For OP’s case, from a packaging perspective, it seems very strange to have been setting bare
CFLAGS="-Wall"with nothing else, not just appending-Wallto CFLAGS.)We do the same and it was part of the motivation for the change, even.
All of that said: of course, if folks want, I can take the approach you did for numpy.
I think we’re in agreement? If
CFLAGSis completely unset, you get the sysconfig value. If you setCFLAGSat all yourself, you have full control over what you set .(I was making the point that “it’s no longer possible” isn’t accurate, of course it doesn’t append for you anymore to the sysconfig flags unless you handle that. I couldn’t understand what the actual complaint was so was guessing.)
No, this isn’t true. Please assume good faith. There are several reasons:
setuptoolsto be built with another compiler than was used to build CPython (if you use a flag that is incompatible when building CPython itself…)-DNDEBUG, then suddenly it appears in all package builds)I have extensive experience packaging and it’s considered a bug when something hardcodes/calcifies CFLAGS from the build of another package. It causes all sorts of problems. Note that we are not overriding the CFLAGS used by a specific project anyway, but rather just whatever CPython happens to use – but you couldn’t rely on that anyway, as other (even Python) build systems didn’t do that.