build: Add a compiler minimum version check #34580

pull polespinasa wants to merge 3 commits into bitcoin:master from polespinasa:clang_min_version_check changing 1 files +24 −0
  1. polespinasa commented at 11:31 am on February 13, 2026: member

    Adds a compiler minimum version check. If failed, it returns a fatal error. This early stop at configure time will avoid contributors losing time trying to fix compilation errors because of not fitting the requirements.

    Example of the output for GCC: Version requirement satisfied:

    0sliv3r@sliv3r-tuxedo:~/Documentos/Projectes/BitcoinCore/bitcoin$ cmake -B BUILD
    1-- The CXX compiler identification is GNU 13.3.0
    2-- Detecting CXX compiler ABI info
    3-- Detecting CXX compiler ABI info - done
    4....
    

    Version requirement not satisfied:

     0$ cmake -B build -S .   -DCMAKE_C_COMPILER=/usr/bin/gcc-11   -DCMAKE_CXX_COMPILER=/usr/bin/g++-11
     1-- The CXX compiler identification is GNU 11.5.0
     2-- Detecting CXX compiler ABI info
     3-- Detecting CXX compiler ABI info - done
     4-- Check for working CXX compiler: /usr/bin/g++-11 - skipped
     5-- Detecting CXX compile features
     6-- Detecting CXX compile features - done
     7CMake Error at CMakeLists.txt:91 (message):
     8  GCC >= 12.1 required.
     9
    10
    11-- Configuring incomplete, errors occurred!
    

    Example of the output for Clang: Version requirement satisfied:

    0sliv3r@sliv3r-tuxedo:~/Documentos/Projectes/BitcoinCore/bitcoin$ cmake -B build
    1-- The CXX compiler identification is Clang 18.1.3
    2-- Detecting CXX compiler ABI info
    3-- Detecting CXX compiler ABI info - done
    4...
    

    Version requirement not satisfied:

     0$ cmake -B build -DCMAKE_C_COMPILER=clang-16       -DCMAKE_CXX_COMPILER=clang++-16
     1-- The CXX compiler identification is Clang 16.0.6
     2-- Detecting CXX compiler ABI info
     3-- Detecting CXX compiler ABI info - done
     4-- Check for working CXX compiler: /usr/bin/clang++-16 - skipped
     5-- Detecting CXX compile features
     6-- Detecting CXX compile features - done
     7CMake Error at CMakeLists.txt:86 (message):
     8  Clang >= 17.0 required.
     9
    10
    11-- Configuring incomplete, errors occurred!
    
  2. DrahtBot added the label Build system on Feb 13, 2026
  3. DrahtBot commented at 11:31 am on February 13, 2026: contributor

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

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK w0xlt
    Approach ACK vasild

    If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #32367 (cmake: Check user-defined APPEND_*FLAGS variables early by hebasto)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  4. polespinasa force-pushed on Feb 13, 2026
  5. DrahtBot added the label CI failed on Feb 13, 2026
  6. polespinasa commented at 11:35 am on February 13, 2026: member

    Friendly ping @vasild @fanquake I assume you are interested because of our IRC conversation.

    Note: the MSVC check was not tested, I don’t have rn an available environment to test it.

  7. polespinasa force-pushed on Feb 13, 2026
  8. build: Add Clang minimum version check 1d3e3c2359
  9. build: Add GCC minimum version check 8dfeaf09b1
  10. build: Add MSVC minimum version check a902bd955c
  11. polespinasa force-pushed on Feb 13, 2026
  12. w0xlt commented at 2:49 am on February 14, 2026: contributor
    Concept ACK
  13. fanquake marked this as a draft on Feb 16, 2026
  14. fanquake commented at 11:03 am on February 16, 2026: member

    https://github.com/bitcoin/bitcoin/actions/runs/21985815150/job/63519602237?pr=34580#step:9:434:

     0+ eval 'CMAKE_ARGS=(-DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DBUILD_BENCH=ON -DBUILD_FUZZ_BINARY=ON -DCMAKE_INSTALL_PREFIX=/Users/runner/work/bitcoin/bitcoin/repo_archive/ci/scratch/out -Werror=dev   --preset=dev-mode   -DWITH_USDT=OFF   -DREDUCE_EXPORTS=ON   -DCMAKE_EXE_LINKER_FLAGS='\''-Wl,-stack_size -Wl,0x80000'\'' )'
     1++ CMAKE_ARGS=(-DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DBUILD_BENCH=ON -DBUILD_FUZZ_BINARY=ON -DCMAKE_INSTALL_PREFIX=/Users/runner/work/bitcoin/bitcoin/repo_archive/ci/scratch/out -Werror=dev --preset=dev-mode -DWITH_USDT=OFF -DREDUCE_EXPORTS=ON -DCMAKE_EXE_LINKER_FLAGS='-Wl,-stack_size -Wl,0x80000')
     2+ cmake -S /Users/runner/work/bitcoin/bitcoin/repo_archive -B /Users/runner/work/bitcoin/bitcoin/repo_archive/ci/scratch/build-aarch64-apple-darwin24.6.0 -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DBUILD_BENCH=ON -DBUILD_FUZZ_BINARY=ON -DCMAKE_INSTALL_PREFIX=/Users/runner/work/bitcoin/bitcoin/repo_archive/ci/scratch/out -Werror=dev --preset=dev-mode -DWITH_USDT=OFF -DREDUCE_EXPORTS=ON '-DCMAKE_EXE_LINKER_FLAGS=-Wl,-stack_size -Wl,0x80000'
     3-- The CXX compiler identification is AppleClang 16.0.0.16000026
     4-- Detecting CXX compiler ABI info
     5-- Detecting CXX compiler ABI info - done
     6-- Check for working CXX compiler: /usr/bin/c++ - skipped
     7-- Detecting CXX compile features
     8-- Detecting CXX compile features - done
     9CMake Error at CMakeLists.txt:86 (message):
    10  Clang >= 17.0 required.
    11-- Configuring incomplete, errors occurred!
    
  15. in CMakeLists.txt:86 in a902bd955c
    81+  # VS 18.x uses 19.50-19.59 as MSVC version values
    82+  # https://cmake.org/cmake/help/latest/variable/MSVC_VERSION.html
    83+
    84+if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
    85+  if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS MIN_CLANG_VERSION)
    86+    message(FATAL_ERROR "Clang >= ${MIN_CLANG_VERSION} required.")
    


    vasild commented at 12:14 pm on February 16, 2026:
    Would be useful to print also the detected compiler version. E.g. if it is detected wrong or the user thinks they have clang 17, it is not the best experience to get a message like “minimum is 17”.

    fanquake commented at 12:25 pm on February 16, 2026:
    The detected compiler version is already printed by CMake
  16. in CMakeLists.txt:83 in a902bd955c
    74@@ -75,6 +75,30 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT CMAKE_HOST_APPLE)
    75   set(CMAKE_PLATFORM_HAS_INSTALLNAME FALSE)
    76 endif()
    77 enable_language(CXX)
    78+set(MIN_CLANG_VERSION 17.0)
    79+set(MIN_GCC_VERSION 12.1)
    80+set(MIN_MSVC_VERSION 19.50)
    81+  # VS 18.x uses 19.50-19.59 as MSVC version values
    82+  # https://cmake.org/cmake/help/latest/variable/MSVC_VERSION.html
    83+
    


    vasild commented at 12:18 pm on February 16, 2026:
    It is common to put the comments before the code they are relating to. I.e. move those two comment lines before the MSVC version set and remove the leading spaces.
  17. in CMakeLists.txt:92 in a902bd955c
    87+  endif()
    88+endif()
    89+
    90+if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
    91+  if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS MIN_GCC_VERSION)
    92+    message(FATAL_ERROR "GCC >= ${MIN_GCC_VERSION} required.")
    


    vasild commented at 12:19 pm on February 16, 2026:
    It would be useful to also print the detected compiler version, even though it is printed somewhere earlier.

    fanquake commented at 12:25 pm on February 16, 2026:
    The detected compiler version is already printed by CMake.
  18. vasild commented at 12:22 pm on February 16, 2026: contributor

    Approach ACK a902bd955c

    I guess the AppleClang needs some exception. What is the deal with it? We support minimum Clang 17 and minimum AppleClang 16? Or is it that the CI uses unsupported compiler (appleclang 16)?

  19. hebasto commented at 12:30 pm on February 16, 2026: member

    Approach ACK a902bd9

    I guess the AppleClang needs some exception. What is the deal with it? We support minimum Clang 17 and minimum AppleClang 16? Or is it that the CI uses unsupported compiler (appleclang 16)?

    AppleClang 16.0.0.16000026 is based on LLVM 17.0.6, which is OK. That’s another reason to test compiler features, not versions.

  20. fanquake commented at 12:34 pm on February 16, 2026: member

    That’s another reason to test compiler fetaures, not versions.

    Yea. This was my initial feedback (in IRC) as well.

  21. sedited commented at 12:37 pm on February 16, 2026: contributor
    I’m tending to Concept~0 here. We should be checking features, not version strings that might have exceptions, or be brittle to match against. This might also make it more difficult to test with weird compiler/standard library pairings.
  22. maflcko commented at 12:41 pm on February 16, 2026: member
    If you want to extract the clang feature check, it is currently in src/util/overloaded.h. See commit faed118fb30fbc303e9d4c70569abfee397f1759
  23. maflcko commented at 12:45 pm on February 16, 2026: member
    For GCC, I think it is some ranges/view stuff in the kernel tests. The gcc-12 fix from fa3854e43295f71f5dad8557dd621f0f799b0ee0 was actually backported to gcc-11, so in theory one could use gcc11.3 just fine, if disabling the kernel tests.
  24. vasild commented at 12:57 pm on February 16, 2026: contributor

    I agree that it is more robust to check for features instead of compiler versions. However, then doc/dependencies.md would be at odds with the code - it mentions clang 17 and the code checks for std::xyz availability. Getting them in line would mean rewording doc/dependencies.md to say something like “you need a compiler which supports feature1, feature2 and feature3” - that would not be very useful.

    Further, if we check for features, e.g. std::xyz availability and the check fails, then what would be the error message? “find a compiler that supports std::xyz”, hmm?

    Maybe use a wording like “Need a compiler with support for feature1, feature2, etc, like clang 17 or gcc 12.1” in both doc/dependencies.md and in the error messages?

  25. maflcko commented at 2:20 pm on February 16, 2026: member

    I think doc/dependencies.md is just the scope for what is tested in CI in this repo and for what users are encouraged to report bugs against. Similar to https://github.com/bitcoin/bitcoin/blob/35e6444fdc4068adc79082648f9889ad593e623b/doc/release-notes-empty-template.md#L35-L43

    Of course, anyone is free to use whatever compiler/OS they want (at their own risk).

    It should be trivial to replace requires with is supported and tested with in doc/dependencies.md.

    Further, if we check for features, e.g. std::xyz availability and the check fails, then what would be the error message? “find a compiler that supports std::xyz”, hmm?

    Why not? Maybe the error message can be improved to say “Your current compiler with the current version failed to compile foobar. You may try the next major version of this compiler, or a different supported and tested compiler, according to doc/dependencies.md”

    Maybe use a wording like “Need a compiler with support for feature1, feature2, etc, like clang 17 or gcc 12.1” in both doc/dependencies.md and in the error messages?

    Seems fine as well, but I don’t think there is a need to keep the build system features check in sync with dependencies.md. I think it is enough to have the features check in the build system only.

  26. vasild commented at 4:05 pm on February 16, 2026: contributor
    So, check for features and print a message like “your compiler does not support xyz, Bitcoin Core has been tested to compile with clang >=17 …”?

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: 2026-02-17 06:13 UTC

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