Visitar URL original
Build Python with C11 · Issue #91731 · python/cpython · GitHub
Skip to content

Build Python with C11 #91731

Description

@vstinner

PEP 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

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    type-featureA feature request or enhancement
    on Apr 20, 2022
  2. corona10 commented on Apr 20, 2022

    @corona10
    Member

    +1

  3. added 2 commits that reference this issue on Apr 20, 2022
  4. vstinner commented on Apr 20, 2022

    @vstinner
    MemberAuthor
  5. gvanrossum commented on Apr 20, 2022

    @gvanrossum
    Member

    What about Windows? @zooba are we already building with C11 there?

  6. zooba commented on Apr 20, 2022

    @zooba
    Member

    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.

  7. vstinner commented on Apr 20, 2022

    @vstinner
    MemberAuthor

    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.

  8. gvanrossum commented on Apr 20, 2022

    @gvanrossum
    Member

    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.)

  9. zooba commented on Apr 20, 2022

    @zooba
    Member

    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.

    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.

  10. gvanrossum commented on Apr 21, 2022

    @gvanrossum
    Member

    I reopen the issue.

  11. sweeneyde commented on Apr 21, 2022

    @sweeneyde
    Member

    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,
        ^
    
  12. 36 remaining items

  13. added a commit that references this issue on Jun 13, 2022
  14. added 2 commits that reference this issue on Jun 16, 2022
  15. gvanrossum commented on Jul 3, 2022

    @gvanrossum
    Member

    Why is this a release blocker? Should it be fixed in 3.12 or also for 3.11?

  16. pablogsal commented on Jul 3, 2022

    @pablogsal
    Member

    Is not a release blocker anymore (it was when it caused c++ compilers to fail) but I removed the label one week ago.

  17. gvanrossum commented on Jul 3, 2022

    @gvanrossum
    Member

    Hm it’s still in Ezio’s project: Release and Deferred blockers 🚫 (view)

  18. pablogsal commented on Jul 3, 2022

    @pablogsal
    Member

    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 :(

  19. vstinner commented on Jul 3, 2022

    @vstinner
    MemberAuthor

    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?

  20. added a commit that references this issue on Jul 12, 2022
  21. vstinner commented on Nov 3, 2022

    @vstinner
    MemberAuthor

    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 ;-)

  22. added a commit that references this issue on Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type-bugAn unexpected behavior, bug, or errortype-featureA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions