GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Build Python with C11 · Issue #91731 · python/cpython

Build Python with C11 #91731

New issue
Copy link
New issue
Copy link
Closed
Closed
Build Python with C11#91731
Copy link
Assignees
zooba
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or errortype-featureA feature request or enhancementA feature request or enhancement

Description

@vstinner
vstinner
opened on Apr 20, 2022
Issue body actions

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

  • PR: gh-99069: Consolidate checks for static_assert #94766
Reacted by Erlend E. Aasland, Daniele B, C.A.M. Gerlach, Komeil Parseh and Felipe S. S. Schneider

Activity

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

    @corona10
    corona10
    on Apr 20, 2022
    Member
    More actions

    +1

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

    gh-91731: Build Python with -std=c11 (#91733)

    aaeea78

    gh-91731: Replace Py_BUILD_ASSERT() with static_assert() (#91730)

    7cdaf87
  4. vstinner commented on Apr 20, 2022

    @vstinner
    vstinner
    on Apr 20, 2022
    MemberAuthor
    More actions

    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.

  5. vstinner
    closed this as completedon Apr 20, 2022
  6. gvanrossum commented on Apr 20, 2022

    @gvanrossum
    gvanrossum
    on Apr 20, 2022
    Member
    More actions

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

  7. zooba commented on Apr 20, 2022

    @zooba
    zooba
    on Apr 20, 2022
    Member
    More actions

    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.

  8. vstinner commented on Apr 20, 2022

    @vstinner
    vstinner
    on Apr 20, 2022
    MemberAuthor
    More actions

    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/[email protected]/thread/J5FSP6J4EITPY5C2UJI7HSL2GQCTCUWN/
    • https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-support-arriving-in-msvc/ <= mentions _Static_assert and has an example using static_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: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.

  9. gvanrossum commented on Apr 20, 2022

    @gvanrossum
    gvanrossum
    on Apr 20, 2022
    Member
    More actions

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

  10. zooba commented on Apr 20, 2022

    @zooba
    zooba
    on Apr 20, 2022
    Member
    More actions

    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.

  11. gvanrossum commented on Apr 21, 2022

    @gvanrossum
    gvanrossum
    on Apr 21, 2022
    Member
    More actions

    I reopen the issue.

  12. gvanrossum
    reopened this on Apr 21, 2022
  13. sweeneyde commented on Apr 21, 2022

    @sweeneyde
    sweeneyde
    on Apr 21, 2022
    Member
    More actions

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

  15. pablogsal
    added a commit that references this issue on Jun 13, 2022

    gh-91731: Don't define 'static_assert' in C++11 where is a keyword to…

    65ff27c
  16. miss-islington
    added 2 commits that reference this issue on Jun 16, 2022

    pythongh-91731: Don't define 'static_assert' in C++11 where is a keyw…

    491392a

    gh-91731: Don't define 'static_assert' in C++11 where is a keyword to…

    7456109
  17. pablogsal
    removed
    release-blocker
    on Jun 21, 2022
  18. serhiy-storchaka
    added a commit that references this issue on Jun 26, 2022

    Revert 30935 defer bpo45162 to 312 (#94285)

    1ffde3e
  19. gvanrossum commented on Jul 3, 2022

    @gvanrossum
    gvanrossum
    on Jul 3, 2022
    Member
    More actions

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

  20. pablogsal commented on Jul 3, 2022

    @pablogsal
    pablogsal
    on Jul 3, 2022
    Member
    More actions

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

  21. gvanrossum commented on Jul 3, 2022

    @gvanrossum
    gvanrossum
    on Jul 3, 2022
    Member
    More actions

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

  22. pablogsal commented on Jul 3, 2022

    @pablogsal
    pablogsal
    on Jul 3, 2022
    Member
    More actions

    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 Melotti
  23. gvanrossum
    removed this from Release and Deferred blockers 🚫on Jul 3, 2022
  24. vstinner commented on Jul 3, 2022

    @vstinner
    vstinner
    on Jul 3, 2022
    MemberAuthor
    More actions

    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?

  25. jmroot
    added a commit that references this issue on Jul 12, 2022

    pythongh-91731: Consolidate checks for static_assert

    d85f456
  26. vstinner commented on Nov 3, 2022

    @vstinner
    vstinner
    on Nov 3, 2022
    MemberAuthor
    More actions

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

  27. vstinner
    closed this as completedon Nov 3, 2022
  28. jmroot
    added a commit that references this issue on Nov 3, 2022

    pythongh-91731: Consolidate checks for static_assert

    05b6d12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @zooba
    zooba

Labels

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

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.