Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 831901 - distutils-r1.eclass: CFLAGS from dev-lang/python leak into packages w/ vendored distutils (was: dev-python/pandas-1.4.0: build time exploded)
Summary: distutils-r1.eclass: CFLAGS from dev-lang/python leak into packages w/ vendor...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Python Gentoo Team
URL: https://bugs.python.org/issue46381
Whiteboard:
Keywords: PullRequest
Depends on:
Blocks:
 
Reported: 2022-01-23 16:12 UTC by Gabriel Linder
Modified: 2022-03-07 07:22 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
emerge --info (emerge-info.txt,7.74 KB, text/plain)
2022-01-23 16:13 UTC, Gabriel Linder
Details
build log (pandas-1.4.0.log,357.21 KB, text/plain)
2022-01-23 19:00 UTC, Gabriel Linder
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Gabriel Linder 2022-01-23 16:12:14 UTC
With python 3.9 and 3.10, and USE=full-support in both cases :

$ time ebuild pandas-1.3.5.ebuild clean install
real	11m22.591s
user	11m9.010s
sys	0m17.659s

$ time ebuild pandas-1.4.0.ebuild clean install 
real	86m35.641s
user	86m4.450s
sys	0m24.960s

Reproducible: Always
Comment 1 Gabriel Linder 2022-01-23 16:13:02 UTC
Created attachment 763387 [details]
emerge --info
Comment 2 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2022-01-23 17:22:35 UTC
Please attach the build log.
Comment 3 Gabriel Linder 2022-01-23 19:00:04 UTC
Created attachment 763400 [details]
build log
Comment 4 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2022-01-23 22:30:53 UTC
This is really weird.  My first thought was that wheel build rebuilds stuff for you but it doesn't look like it.
Comment 5 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2022-01-23 22:33:50 UTC
Did you happen to spot visually which part of the build process took the longest?  i.e. was it "Compiling X because it changed", or the C compilation, or...?
Comment 6 Gabriel Linder 2022-01-23 23:00:32 UTC
It seems to be the steps like "creating build/temp.linux-x86_64-3.9/pandas/_libs", with a cc1 instance compiling very slowly.
Comment 7 Gabriel Linder 2022-01-23 23:50:23 UTC
I got it while inspecting the slow cc1 instances : my python interpreters were compiled with -fipa-pta for a performance test, and it seems interpreters CFLAGS are leaking to python packages when building, so pandas was using this flag as well... I deleted this unwanted flag and rebuilded my python interpreters, and now pandas build times are back to normal :

$ time ebuild pandas-1.3.5.ebuild clean install 
real	10m52.294s
user	10m38.187s
sys	0m17.444s

$ time ebuild pandas-1.4.0.ebuild clean install 
real	11m20.357s
user	11m6.101s
sys	0m16.395s

Strange that pandas <1.4 was unaffected... anyway, sorry for the noise.
Comment 8 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2022-01-24 00:17:23 UTC
No problem.  I'm glad you've figured it out.

That said, interpreter flags shouldn't really be leaking since we're (or at least should be) exporting CFLAGS.  I wonder if pep517 is affecting that.
Comment 9 Gabriel Linder 2022-01-24 00:29:19 UTC
I have another flag that is only enabled for python interpreters (namely, -fno-semantic-interposition). If you give me a python package not using pep517, I can check if this flag is used during the build.
Comment 10 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2022-01-24 10:08:36 UTC
You can try dev-python/typed-ast.
Comment 11 Gabriel Linder 2022-01-24 10:24:46 UTC
OK, tried previous pandas too :

typed-ast-1.5.1.ebuild: correct CFLAGS
pandas-1.3.5.ebuild: correct CFLAGS
pandas-1.4.0.ebuild: -fno-semantic-interposition leaked
Comment 12 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2022-01-24 10:35:06 UTC
Thank you for testing.  I'm going to look at it later today.
Comment 13 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2022-01-24 12:52:23 UTC
This is regression in distutils vendored with setuptools (i.e. SETUPTOOLS_USE_DISTUTILS=local).  I need to check whether this is something that Gentoo patchset to dev-lang/python fixed, or if upstream explicitly broke it.
Comment 14 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2022-01-24 13:11:09 UTC
Ok, it turns out that the undocumented distutils patch we're carrying not only changes some stuff for C++ but also sneakily unsets cflags gotten from sysconfig.  I haven't ported the patch to the vendored distutils in setuptools, nor to Python 3.11, and both are affected now.

FWICS, there's no way around this -- we either have to patch distutils, or to strip flags from sysconfig.  The latter would imply that setup.py called outside Portage has non-standard behavior (well, our old patches are guilty as well) which I don't like.

IMO the behavior should be changed from unconditionally stripping Python CFLAGS to overriding these CFLAGS when CFLAGS are explicitly defined in the environment.

I wonder what are the chances of pushing this upstream.
Comment 15 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2022-01-24 13:48:44 UTC
Even better, we're building CPython wrong.  Apparently we're supposed to use CFLAGS_NODIST, not CFLAGS.
Comment 16 Larry the Git Cow gentoo-dev 2022-01-24 22:14:07 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=1f8b1370d91c1f1c2322cdedde542c63869a654b

commit 1f8b1370d91c1f1c2322cdedde542c63869a654b
Author:     Michał Górny <mgorny@gentoo.org>
AuthorDate: 2022-01-24 14:29:02 +0000
Commit:     Michał Górny <mgorny@gentoo.org>
CommitDate: 2022-01-24 22:09:36 +0000

    dev-lang/python: Fix hardcoding C/FLAGS in Python 3.6
    
    Closes: https://bugs.gentoo.org/831901
    Signed-off-by: Michał Górny <mgorny@gentoo.org>

 dev-lang/python/python-3.6.15-r1.ebuild | 342 ++++++++++++++++++++++++++++++++
 1 file changed, 342 insertions(+)

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=e18fd71cd28e0ef8842386cb1729cd1c7ade684c

commit e18fd71cd28e0ef8842386cb1729cd1c7ade684c
Author:     Michał Górny <mgorny@gentoo.org>
AuthorDate: 2022-01-24 14:28:44 +0000
Commit:     Michał Górny <mgorny@gentoo.org>
CommitDate: 2022-01-24 22:09:35 +0000

    dev-lang/python: Fix hardcoding C/FLAGS in Python 3.7
    
    Closes: https://bugs.gentoo.org/831901
    Signed-off-by: Michał Górny <mgorny@gentoo.org>

 dev-lang/python/python-3.7.12_p1-r1.ebuild | 335 +++++++++++++++++++++++++++++
 1 file changed, 335 insertions(+)

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=0b3320be043d2cf67ca36bcda16fbe5485d8a35f

commit 0b3320be043d2cf67ca36bcda16fbe5485d8a35f
Author:     Michał Górny <mgorny@gentoo.org>
AuthorDate: 2022-01-24 14:28:08 +0000
Commit:     Michał Górny <mgorny@gentoo.org>
CommitDate: 2022-01-24 22:09:33 +0000

    dev-lang/python: Fix hardcoding C/FLAGS in Python 3.8
    
    Closes: https://bugs.gentoo.org/831901
    Signed-off-by: Michał Górny <mgorny@gentoo.org>

 dev-lang/python/python-3.8.12_p1-r2.ebuild | 345 +++++++++++++++++++++++++++++
 1 file changed, 345 insertions(+)

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=6e1a528e5eacf3c0c05bcabed88fd15c0daa90f8

commit 6e1a528e5eacf3c0c05bcabed88fd15c0daa90f8
Author:     Michał Górny <mgorny@gentoo.org>
AuthorDate: 2022-01-24 14:27:37 +0000
Commit:     Michał Górny <mgorny@gentoo.org>
CommitDate: 2022-01-24 22:09:33 +0000

    dev-lang/python: Fix hardcoding C/FLAGS in Python 3.9
    
    Closes: https://bugs.gentoo.org/831901
    Signed-off-by: Michał Górny <mgorny@gentoo.org>

 dev-lang/python/python-3.9.10-r1.ebuild | 380 ++++++++++++++++++++++++++++++++
 1 file changed, 380 insertions(+)

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=c3608b131051020b3e895863a1336f2baad9ef77

commit c3608b131051020b3e895863a1336f2baad9ef77
Author:     Michał Górny <mgorny@gentoo.org>
AuthorDate: 2022-01-24 14:26:16 +0000
Commit:     Michał Górny <mgorny@gentoo.org>
CommitDate: 2022-01-24 22:09:32 +0000

    dev-lang/python: Fix hardcoding C/LDFLAGS in Python 3.10
    
    Closes: https://bugs.gentoo.org/831901
    Signed-off-by: Michał Górny <mgorny@gentoo.org>

 dev-lang/python/python-3.10.2-r1.ebuild | 386 ++++++++++++++++++++++++++++++++
 1 file changed, 386 insertions(+)

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=d635364ccb2ede25419c4a6066fa58893d1d5a93

commit d635364ccb2ede25419c4a6066fa58893d1d5a93
Author:     Michał Górny <mgorny@gentoo.org>
AuthorDate: 2022-01-24 14:25:54 +0000
Commit:     Michał Górny <mgorny@gentoo.org>
CommitDate: 2022-01-24 22:09:31 +0000

    dev-lang/python: Fix hardcoding C/LDFLAGS in Python 3.11
    
    Closes: https://bugs.gentoo.org/831901
    Signed-off-by: Michał Górny <mgorny@gentoo.org>

 dev-lang/python/python-3.11.0_alpha4.ebuild | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)