GeezerVison is showing github.com — Build Python with C11 · Issue #91731 · python/cpython
Build Python with C11 #91731DescriptionPEP 7 was recently updated to require a C11 compiler (without optional features) to build Python. I propose to now implement this new requirement:
- Build Python with -std=c11 rather than -std=c99
- Use static_assert() of <assert.h>
It's already documented in What's New in Python 3.11:
Building Python now requires a C11 compiler without optional C11 features. (Contributed by Victor Stinner in bpo-46656.
https://docs.python.org/dev/whatsnew/3.11.html#build-changes
Reacted by Erlend E. Aasland, Daniele B, C.A.M. Gerlach, Komeil Parseh and Felipe S. S. Schneider Activitycorona10 commented on Apr 20, 2022 vstinner commented on Apr 20, 2022 I merged 2 PRs:
I close the issue. gvanrossum commented on Apr 20, 2022 What about Windows? @zooba are we already building with C11 there? zooba commented on Apr 20, 2022
What about Windows? @zooba are we already building with C11 there?
Apparently, or CI would have broken. I guess we'll find out when people start using new language features. vstinner commented on Apr 20, 2022
What about Windows? @zooba are we already building with C11 there?
When the PEP 7 change was discussed on python-dev, it was said that MSVC supports C11 without optional features.
My PR got merged and the CI is fine. Do you have remaining concerns about MSVC?
The blog post mentions the /std:c11 option: https://docs.microsoft.com/en-us/cpp/build/reference/std-specify-language-standard-version?view=msvc-170 It doesn't seem to be used by Python currently.
I only these /std options:
PCbuild/python_uwp.vcxproj:93: <AdditionalOptions>/EHsc /std:c++17 %(AdditionalOptions)</AdditionalOptions>
PCbuild/pythonw_uwp.vcxproj:93: <AdditionalOptions>/EHsc /std:c++17 %(AdditionalOptions)</AdditionalOptions>
The blog post also mentions the /Zc:preprocessor option to switch the preprocessor to C11 mode ("conformant preprocessor"): https://docs.microsoft.com/en-us/cpp/build/reference/zc-preprocessor?view=msvc-170 This option doesn't seem to be currently used by Python. gvanrossum commented on Apr 20, 2022 My remaining concern is that I tried to use static_assert() in #32387 and it broke on Windows. I've merged the latest main and it still breaks. I'll just assume that that is a different problem so I'll move on. (If you want to look into it, details are in that issue.) zooba commented on Apr 20, 2022 gvanrossum commented on Apr 21, 2022 sweeneyde commented on Apr 21, 2022 It looks like AMD64 FreeBSD Non-Debug 3.x is now failing like this:
-- Objects/longobject.o ---
cc -pthread -c -DNDEBUG -g -fwrapv -O3 -Wall -UNDEBUG -O2 -pipe -std=c11 -Werror=implicit-function-declaration -fvisibility=hidden -I./Include/internal -I. -I./Include -DPy_BUILD_CORE -o Objects/longobject.o Objects/longobject.c
Objects/longobject.c:776:5: error: implicit declaration of function 'static_assert' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
static_assert(PyLong_SHIFT <= sizeof(unsigned long) * 8,
^
added a commit that references this issue on Jun 13, 2022gh-91731: Don't define 'static_assert' in C++11 where is a keyword to… added 2 commits that reference this issue on Jun 16, 2022pythongh-91731: Don't define 'static_assert' in C++11 where is a keyw… gh-91731: Don't define 'static_assert' in C++11 where is a keyword to… gvanrossum commented on Jul 3, 2022 Why is this a release blocker? Should it be fixed in 3.12 or also for 3.11? pablogsal commented on Jul 3, 2022 Is not a release blocker anymore (it was when it caused c++ compilers to fail) but I removed the label one week ago. gvanrossum commented on Jul 3, 2022 pablogsal commented on Jul 3, 2022 vstinner commented on Jul 3, 2022 On Linux, all C++ compiler errors have been fixed and now have tests (test_cppext: C++03 and C++11).
On Windows, test_cppext is skipped and Python doesn't pass /std:c11 compiler flag. I would suggest opening a separated issue to enhance C11 and C++ support on Windows.
# With MSVC, the linker fails with: cannot open file 'python311.lib'
# https://github.com/python/cpython/pull/32175#issuecomment-1111175897
@unittest.skipIf(MS_WINDOWS, 'test fails on Windows')
Well, C11 features are used in Python on Windows as well. So I consider that the initial issue is now fixed. /std:c11 doesn't seem to be required at this point.
Can I close this issue? vstinner commented on Nov 3, 2022 Python 3.11 was released and it now requires a C11 compiler. I close the issue. If you want to enhance Python build, please open a new separated issue ;-)
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|