Warn about / refuse unsupported clang version #30947

issue Sjors openend this issue on September 23, 2024
  1. Sjors commented at 7:46 am on September 23, 2024: member

    On an older Intel macOS 13.7 machine:

     0cmake -B build
     1-- The CXX compiler identification is AppleClang 14.0.3.14030022
     2
     3...
     4
     5cmake --build build -j7
     6
     7...
     8
     9In file included from /Users/sjors/dev/bitcoin/src/crypto/muhash.h:9:
    10/Users/sjors/dev/bitcoin/src/uint256.h:133:19: error: call to consteval function 'util::ConstevalHexDigit' is not a constant expression
    11        auto lo = util::ConstevalHexDigit(*(str_it++));
    12                  ^
    13
    14(etc)
    

    Our minimum required clang is 16 so this is no surprise.

    It would be good if cmake -B build checks the minimum version and at least throws a warning.

  2. Sjors commented at 7:51 am on September 23, 2024: member

    The documentation says “For macOS 11 (Big Sur) and 12 (Monterey) you need to install a more recent version of llvm”. That should include macOS 13 and 14 now as well, see https://trac.macports.org/wiki/XcodeVersionInfo#macOS14

    But I think as long as cmake warns about llvm being too old, anyone reading build-osx.md will probably figure out that they need to install a newer version via llvm. But it’s a trivial doc change, see #30949.

  3. maflcko commented at 8:28 am on September 23, 2024: member

    There is no need to use brew to install clang/llvm. You can just pick the newer XCode: sudo xcode-select --switch /Applications/Xcode_15.0.app

    You may have to upgrade to macOS 13.5 (or later), according to the release notes:

    https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes

  4. fanquake commented at 8:28 am on September 23, 2024: member

    It would be good if cmake -B build checks the minimum version

    We don’t check compiler versions, we check for C++ compatibility (i.e CMAKE_CXX_STANDARD, CMAKE_CXX_STANDARD_REQUIRED, CMAKE_CXX_EXTENSIONS). If CMakes CMAKE_CXX_STANDARD check is incorrectly passing, when a compiler doesn’t actually support C++20, we should file a bug upstream, so they can expand the checks they perform.

  5. Sjors commented at 10:20 am on September 23, 2024: member

    we should file a bug upstream, so they can expand the checks they perform

    I used cmake version 3.30.3 (via Homebrew).

    Even this doesn’t trigger an error:

    0add_library(core_interface INTERFACE)
    1target_compile_features(core_interface INTERFACE cxx_std_20)
    

    From googling around I get the impression this check isn’t reliable, and you have to check for specific features. E.g. https://stackoverflow.com/questions/75296149/cmake-set-project-to-c-20#comment132865328_75296149

    That sounds potentially more tedious than just waiting for compile to fail.

    There is no need to use brew to install clang/llvm. You can just pick the newer XCode: sudo xcode-select --switch /Applications/Xcode_15.0.app

    That only works if you install Xcode, otherwise you’re stuck on whichever version of the command-line tools came with the OS.

    You can’t install Xcode via the App Store (on macOS 13). You have to download it via the Developer Center. Account required (the free one). You’ll need version 15.2, because 15.4 required macOS 14.

    So that’s more tedious than using Homebrew, but arguably it’s a cleaner approach.

  6. Sjors closed this on Sep 23, 2024

  7. maflcko commented at 10:30 am on September 23, 2024: member

    There is no need to use brew to install clang/llvm. You can just pick the newer XCode: sudo xcode-select --switch /Applications/Xcode_15.0.app

    That only works if you install Xcode, otherwise you’re stuck on whichever version of the command-line tools came with the OS.

    You can’t install Xcode via the App Store (on macOS 13). You have to download it via the Developer Center. Account required (the free one). You’ll need version 15.2, because 15.4 required macOS 14.

    So that’s more tedious than using Homebrew, but arguably it’s a cleaner approach.

    Well, I’ve never used Apple, so I don’t know which is more tedious. But implying only the brew approach works would be wrong. Also, neither 15.2 nor 15.4 is “required”. 15.0 works fine (and should work fine on macOS 13.5 as well).

  8. fanquake commented at 10:33 am on September 23, 2024: member

    From googling around I get the impression this check isn’t reliable, and you have to check for specific features. E.g. https://stackoverflow.com/questions/75296149/cmake-set-project-to-c-20#comment132865328_75296149

    That is what CMake does behind the scenes, i.e the tests in https://github.com/Kitware/CMake/tree/master/Tests/CompileFeatures. So if they are missing coverage for a certain compiler/cxx std combo, it’s a bug they should address, not something we should have to test ourselves.

  9. Sjors commented at 10:36 am on September 23, 2024: member
  10. fanquake commented at 10:40 am on September 23, 2024: member
    I’d start by looking at https://github.com/Kitware/CMake/blob/master/Tests/CompileFeatures/CMakeLists.txt, and the various combinations of compiler (versions) + feature tests.
  11. maflcko commented at 10:40 am on September 23, 2024: member

    Individual compile features are not provided for C++ 17 or later. See https://cmake.org/cmake/help/latest/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html#low-level-individual-compile-features

    And I don’t think they are tested either, because code should be using the feature test macros introduced in recent versions of C++.

  12. fanquake commented at 10:46 am on September 23, 2024: member
    It seems like they add cpp feature checks for various compilers if it’s otherwise broken/doesn’t always report the right version, i.e https://github.com/Kitware/CMake/blob/master/Modules/CMakeCXXCompilerId.cpp.in#L46, maybe they need to do the same for Apple Clang.
  13. polespinasa commented at 3:00 pm on October 31, 2024: none

    I’m not able to run fuzzing tests also because of this:

    0$ cmake --build build_fuzz
    1....
    2/bitcoin/src/uint256.h:133:19: error: call to consteval function 'util::ConstevalHexDigit' is not a constant expression
    3        auto lo = util::ConstevalHexDigit(*(str_it++));
    

    Which clang version are we suposed to use?

    0$ clang --version
    1Ubuntu clang version 14.0.0-1ubuntu1.1
    
  14. fanquake commented at 3:02 pm on October 31, 2024: member

    Which clang version are we suposed to use?

    https://github.com/bitcoin/bitcoin/blob/master/doc/dependencies.md


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-12-21 15:12 UTC

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