ci: Use C++23 in one task #30735

pull maflcko wants to merge 2 commits into bitcoin:master from maflcko:2408-23 changing 2 files +3 −2
  1. maflcko commented at 1:23 pm on August 28, 2024: member

    There are no plans to switch to C++23 anytime soon in the next couple of years. The only place right now that is known to benefit is src/compat/byteswap.h.

    However, it is still useful to test with the option, because deprecated, removed or changed language features, as well as compiler changes that are guarded by the language version will be tested and developers can learn about them upfront.

    Also includes a minor doc fixup commit.

  2. build: Add Centos Stream 9 EOL URL
    To match the format of the previous section about the Ubuntu 22.04 EOL.
    fa053ab7c0
  3. DrahtBot commented at 1:23 pm on August 28, 2024: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK TheCharlatan, davidgumberg
    Concept ACK theuni, jonatack

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

  4. DrahtBot renamed this:
    cmake: Add option to use C++23 for testing
    cmake: Add option to use C++23 for testing
    on Aug 28, 2024
  5. DrahtBot added the label Build system on Aug 28, 2024
  6. maflcko renamed this:
    cmake: Add option to use C++23 for testing
    build: Add option to use C++23 for testing
    on Aug 28, 2024
  7. maflcko added the label DrahtBot Guix build requested on Aug 28, 2024
  8. TheCharlatan commented at 1:37 pm on August 28, 2024: contributor
    Would it be better to add the required standard to the core_interface as a property and remove the global? Then the user can just pick their own standard with -DCMAKE_CXX_STANDARD on the command line. Since it a global set, the user choice is currently overridden.
  9. fanquake commented at 1:37 pm on August 28, 2024: member
    Kind of surprised we have to introduce a new option to make this work. I would have thought CMake would do something smarter where you could just override with -DCMAKE_CXX_STANDARD=23 at configuration time.
  10. maflcko commented at 1:41 pm on August 28, 2024: member
    Sure, happy to push any other alternative, if someone sends me a diff that compiles. Also, I am happy to review an alternative pull request.
  11. TheCharlatan commented at 2:14 pm on August 28, 2024: contributor

    Does this work for you?

    0diff --git a/CMakeLists.txt b/CMakeLists.txt
    1index 32db4189d4..f292830798 100644
    2--- a/CMakeLists.txt
    3+++ b/CMakeLists.txt
    4@@ -74 +73,0 @@ enable_language(CXX)
    5-set(CMAKE_CXX_STANDARD 20)
    6@@ -563,0 +563 @@ target_compile_definitions(core_interface_debug INTERFACE ${DEPENDS_COMPILE_DEFI
    7+target_compile_features(core_interface INTERFACE cxx_std_20)
    

    Maybe @hebasto has a suggestion for also printing it in the summary.

  12. maflcko commented at 2:29 pm on August 28, 2024: member

    Maybe @hebasto has a suggestion for also printing it in the summary.

    IIUC -std=value should always be printed in the summary (before and after)

  13. maflcko commented at 3:10 pm on August 28, 2024: member
    Actually I am not sure on the suggestion on a second thought. Users shouldn’t be able to modify this at all, because building with anything other than C++20 is not supported and will lead to a broken result. The goal here is to only allow C++23 for testing.
  14. fanquake commented at 3:12 pm on August 28, 2024: member
  15. maflcko force-pushed on Aug 28, 2024
  16. maflcko commented at 3:14 pm on August 28, 2024: member

    Looks like this also runs into: bitcoin-core/leveldb-subtree#43.

    Force pushed trivial CI fixup to temporarily work around the issue for now.

  17. fanquake commented at 3:15 pm on August 28, 2024: member

    Users shouldn’t be able to modify this at all,

    In general this is impossible, because they can always just override the compilation flags.

  18. maflcko commented at 3:20 pm on August 28, 2024: member

    Users shouldn’t be able to modify this at all,

    In general this is impossible, because they can always just override the compilation flags.

    Are you sure. Locally when using -DCMAKE_CXX_FLAGS='-std=c++17', it doesn’t have any effect, because they are reset by cmake:

    0C++ compiler flags .................... -std=c++17 -O2 -g -std=c++20 -fPIC ...
    

    I guess I can use the existing non-standard append hack instead, which users shouldn’t know about to shoot themselves into the foot.

  19. ci: Use C++23 once for testing fac587ea07
  20. maflcko force-pushed on Aug 28, 2024
  21. maflcko commented at 3:25 pm on August 28, 2024: member

    I guess I can use the existing non-standard append hack instead

    Force pushed that instead, so that this is a doc/ci-only change.

    Other changes can be done in a follow-up, if needed.

  22. maflcko renamed this:
    build: Add option to use C++23 for testing
    ci: Use C++23 in one task
    on Aug 28, 2024
  23. fanquake commented at 3:27 pm on August 28, 2024: member

    it doesn’t have any effect, because they are reset by cmake:

    Heh, right, I forgot CMake makes a mess of this. Note that this behaviour is itself a footgun, because a user might rightly expect something like -DCMAKE_CXX_FLAGS='-O1' to work, but CMake will just ignore it.

  24. theuni commented at 5:31 pm on August 28, 2024: member

    Fwiw APPEND_CXXFLAGS was added specifically for cases like this where CMake sets a flag internally that we want to override.

    Edit: Nm, I see you’re using that now :)

  25. theuni commented at 5:53 pm on August 28, 2024: member

    Concept ACK.

    If we wanted, we could actually start conditionally enabling c++23 features for these builds. For byteswap, something like:

    0#if __cplusplus >= 202302L && defined(__cpp_lib_byteswap) && __cpp_lib_byteswap >= 202110L
    1#      define bitcoin_builtin_bswap16(x) std::byteswap(x)
    2#      define bitcoin_builtin_bswap32(x) std::byteswap(x)
    3#      define bitcoin_builtin_bswap64(x) std::byteswap(x)
    4#  elif defined __has_builtin
    5...
    

    Another I’ve found useful while working on another project is static operator(), which could be gated/used like:

    0#if __cplusplus >= 202302L && defined(__cpp_static_call_operator) && __cpp_static_call_operator >= 202207L
    1#define CPP23_STATIC static
    2#define CONST_IF_NOT_CPP23_STATIC
    3#else
    4#define CPP23_STATIC
    5#define CONST_IF_NOT_CPP23_STATIC const
    6#endif
    
    0class CScriptVisitor
    1{
    2public:
    3    CPP23_STATIC CScript operator()(const CNoDestination& dest) CONST_IF_NOT_CPP23_STATIC
    4    {
    5        return dest.GetScript();
    6    }
    7...
    
  26. jonatack commented at 6:19 pm on August 28, 2024: member
    Concept ACK
  27. TheCharlatan approved
  28. TheCharlatan commented at 6:58 pm on August 28, 2024: contributor
    ACK fac587ea070fe1354708aacce33ebb9cebd35e5b
  29. DrahtBot requested review from jonatack on Aug 28, 2024
  30. DrahtBot requested review from theuni on Aug 28, 2024
  31. in ci/test/00_setup_env_native_asan.sh:31 in fac587ea07
    27@@ -28,7 +28,8 @@ export BITCOIN_CONFIG="\
    28  -DCMAKE_C_COMPILER=clang-18 \
    29  -DCMAKE_CXX_COMPILER=clang++-18 \
    30  -DCMAKE_C_FLAGS='-ftrivial-auto-var-init=pattern' \
    31- -DCMAKE_CXX_FLAGS='-ftrivial-auto-var-init=pattern' \
    32+ -DCMAKE_CXX_FLAGS='-ftrivial-auto-var-init=pattern -Wno-error=deprecated-declarations' \
    


    davidgumberg commented at 8:46 pm on August 28, 2024:

    A note for other readers: Wno-error=deprecated-declarations is here because the leveldb subtree currently uses std::aligned_storage. (deprecated in C++23)

    Patches introducing features deprecated in C++20 or earlier will still be caught by other CI tasks.

  32. davidgumberg commented at 8:48 pm on August 28, 2024: contributor

    ACK https://github.com/bitcoin/bitcoin/pull/30735/commits/fac587ea070fe1354708aacce33ebb9cebd35e5b

    tested with:

    0cmake -B build -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CC_COMPILER=clang -DAPPEND_CXXFLAGS='-std=c++23'
    
  33. maflcko removed the label DrahtBot Guix build requested on Aug 29, 2024
  34. fanquake merged this on Aug 29, 2024
  35. fanquake closed this on Aug 29, 2024

  36. maflcko deleted the branch on Aug 29, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-21 09:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me