Repository navigation
Build Python with C11 #91731
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or errortype-featureA feature request or enhancementA feature request or enhancement
on Apr 20, 2022 +1
I merged 2 PRs:
- gh-91731: Build Python with -std=c11 #91733
- gh-91731: Replace Py_BUILD_ASSERT() with static_assert() #91730
I close the issue.
What about Windows? @zooba are we already building with C11 there?
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.
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.
- https://mail.python.org/archives/list/python-dev@python.org/thread/J5FSP6J4EITPY5C2UJI7HSL2GQCTCUWN/
- https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-support-arriving-in-msvc/ <= mentions
_Static_assertand has an example usingstatic_assert()of<assert.h>
My PR got merged and the CI is fine. Do you have remaining concerns about MSVC?
The blog post mentions the
/std:c11option: 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:preprocessoroption 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.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.)
The blog post mentions the
/std:c11option: 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.Yeah, this probably needs to be added (in pyproject.props). I don't think it will matter if it's included twice in the C++ projects, but that would be the biggest issue.
I reopen the issue.
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, ^36 remaining items
- added a commit that references this issue
on Jun 13, 2022 - added a commit that references this issue
on Jun 26, 2022 Why is this a release blocker? Should it be fixed in 3.12 or also for 3.11?
Is not a release blocker anymore (it was when it caused c++ compilers to fail) but I removed the label one week ago.
Hm it’s still in Ezio’s project: Release and Deferred blockers 🚫 (view)
Hm it’s still in Ezio’s project: Release and Deferred blockers 🚫 (view)
Ah, that's because according to Ezio that will require manual update, which is unfortunate :(
Reacted by Ezio MelottiOn 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?
- added a commit that references this issue
on Jul 12, 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 ;-)
- added a commit that references this issue
on Nov 3, 2022
PEP 7 was recently updated to require a C11 compiler (without optional features) to build Python. I propose to now implement this new requirement:
It's already documented in What's New in Python 3.11:
https://docs.python.org/dev/whatsnew/3.11.html#build-changes