-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-36235: Fix CFLAGS in distutils customize_compiler() #12236
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
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 |
---|---|---|
|
@@ -181,8 +181,8 @@ def customize_compiler(compiler): | |
_osx_support.customize_compiler(_config_vars) | ||
_config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True' | ||
|
||
(cc, cxx, opt, cflags, ccshared, ldshared, shlib_suffix, ar, ar_flags) = \ | ||
get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS', | ||
(cc, cxx, cflags, ccshared, ldshared, shlib_suffix, ar, ar_flags) = \ | ||
get_config_vars('CC', 'CXX', 'CFLAGS', | ||
'CCSHARED', 'LDSHARED', 'SHLIB_SUFFIX', 'AR', 'ARFLAGS') | ||
|
||
if 'CC' in os.environ: | ||
|
@@ -205,7 +205,7 @@ def customize_compiler(compiler): | |
if 'LDFLAGS' in os.environ: | ||
ldshared = ldshared + ' ' + os.environ['LDFLAGS'] | ||
if 'CFLAGS' in os.environ: | ||
cflags = opt + ' ' + os.environ['CFLAGS'] | ||
cflags = cflags + ' ' + os.environ['CFLAGS'] | ||
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. If my concern about 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. Right. Fixed. |
||
ldshared = ldshared + ' ' + os.environ['CFLAGS'] | ||
if 'CPPFLAGS' in os.environ: | ||
cpp = cpp + ' ' + os.environ['CPPFLAGS'] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Fix ``CFLAGS`` in ``customize_compiler()`` of ``distutils.sysconfig``: when | ||
the ``CFLAGS`` environment variable is defined, don't override ``CFLAGS`` | ||
variable with the ``OPT`` variable anymore. Initial patch written by David | ||
Malcolm. |
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.
I believe
opt
should be retained since there are compiler flags captured during./configure
which would get dropped when theCFLAGS
environment variable is set invoking a build viadistutils
.For example, on my macOS machine, the following compiler flags would be lost if
CFLAGS
was set:>>> sysconfig.get_config_var('OPT') '-DNDEBUG -g -fwrapv -O3 -Wall'
To the best of my understanding, it appears the goal is to have the compiler flags used when building the interpreter to be passed along to C/C++ extensions with the ability to add additional user-specified flags via the
CFLAGS
environment variable.Given that the intent appears to be appending to the flags already captured during the configuration phase of building the interpreter, I would suggest:
If the propose change is accepted, then my follow-up feedback would be updating the commit message and news announcement accordingly.
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.
sysconfig reads PY_FLAGS from Makefile and expose it as "CFLAGS". In the Makefile, PY_CFLAGS is composed from other variables:
So "OPT" sysconfig variable is a subset of "CFLAGS" sysconfig variable.
Note: I'm talking about the specific case of sysconfig variables.
Python compiled manually:
/usr/bin/python3:
Uh oh!
There was an error while loading. Please reload this page.
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.
@vstinner, thanks for the walkthrough and I have arrived at the same conclusion.