build: replace header checks with __has_include #32405

pull fanquake wants to merge 1 commits into bitcoin:master from fanquake:use_has_include changing 4 files +4 −24
  1. fanquake commented at 3:31 pm on May 2, 2025: member

    Replace the checks in CMake, with the equivalent functionality provided by the standard library (since C++17). See https://en.cppreference.com/w/cpp/preprocessor/include.

    Guix Build:

     066d71c866bd111ffe65bc03b9e1653a95eb678f0b04451759c56af868bfc03d5  guix-build-e1f543823b30/output/aarch64-linux-gnu/SHA256SUMS.part
     11a4130d801620a63d86c3069b1fbca39ebc963e610101451d3f48b1c191ca4b3  guix-build-e1f543823b30/output/aarch64-linux-gnu/bitcoin-e1f543823b30-aarch64-linux-gnu-debug.tar.gz
     2745adbc7767344a8cd0ebe1e7592239614d89f949558c9b6a2ae58f7b2602a32  guix-build-e1f543823b30/output/aarch64-linux-gnu/bitcoin-e1f543823b30-aarch64-linux-gnu.tar.gz
     3cb69d205a20715ee58a324cc2b8475c2bae0443a062f5de2820baa45f822292c  guix-build-e1f543823b30/output/arm-linux-gnueabihf/SHA256SUMS.part
     4081774dd903256dafa187ee47a569cd44b01eb16adc9dbfeb54b721abc39e944  guix-build-e1f543823b30/output/arm-linux-gnueabihf/bitcoin-e1f543823b30-arm-linux-gnueabihf-debug.tar.gz
     51dd857fe6b9e75fae746e73fbfc6b77302b4dbb13685baebb10e9686da7bad01  guix-build-e1f543823b30/output/arm-linux-gnueabihf/bitcoin-e1f543823b30-arm-linux-gnueabihf.tar.gz
     6e035ba959da69263de2f29282328d4e5b455f94a800a15891801f26ba3b8b325  guix-build-e1f543823b30/output/arm64-apple-darwin/SHA256SUMS.part
     7ebf973e0e44be688ea5e1ebae804dfce6e71b7ca8aaca5d8249a14d130f37c3f  guix-build-e1f543823b30/output/arm64-apple-darwin/bitcoin-e1f543823b30-arm64-apple-darwin-codesigning.tar.gz
     83ea687b53032b30d7c4a0760f8a35d19e2f60a8cb3f1f5e2c5cba05897f04e43  guix-build-e1f543823b30/output/arm64-apple-darwin/bitcoin-e1f543823b30-arm64-apple-darwin-unsigned.tar.gz
     9ebb6a935f2fbc75167f5e61a039d13f231621f7eb0cbd1292616425f7677739c  guix-build-e1f543823b30/output/arm64-apple-darwin/bitcoin-e1f543823b30-arm64-apple-darwin-unsigned.zip
    109e77422977506f0c3f0373ee19d24c3ad86cbaf3a97cfcf5db202d4fff9c3ae4  guix-build-e1f543823b30/output/dist-archive/bitcoin-e1f543823b30.tar.gz
    1162d7c8f63a3702b066f88498f829b2c371baa06c596b71b6d8969f638cc2d356  guix-build-e1f543823b30/output/powerpc64-linux-gnu/SHA256SUMS.part
    1260c00fc85dea24548c212330e5fa097020f17bb74f511e7e764b8b33224afce0  guix-build-e1f543823b30/output/powerpc64-linux-gnu/bitcoin-e1f543823b30-powerpc64-linux-gnu-debug.tar.gz
    1397b1aa4dc967c9a3767476a262a503900ea77e15b4b292928c6cdddf306cafc9  guix-build-e1f543823b30/output/powerpc64-linux-gnu/bitcoin-e1f543823b30-powerpc64-linux-gnu.tar.gz
    14ed67fbb0768ce7b1d4d053de2ba0ea3b2798d01a276adf6430c4a2a413461ee2  guix-build-e1f543823b30/output/riscv64-linux-gnu/SHA256SUMS.part
    1583f7b4e6c244d97caa2eb41b67cdef2bfa71f2f3ef1cfa378fae32db18fc8e25  guix-build-e1f543823b30/output/riscv64-linux-gnu/bitcoin-e1f543823b30-riscv64-linux-gnu-debug.tar.gz
    16c8ca7793fdfac2346a21d5fc8f6e00f1feb6556d048896fef8148ac614921050  guix-build-e1f543823b30/output/riscv64-linux-gnu/bitcoin-e1f543823b30-riscv64-linux-gnu.tar.gz
    17a3e99dd3369aa97cad2437fc1b29f84a8950327fd0f0a1c0a8a3e7ce49369f1a  guix-build-e1f543823b30/output/x86_64-apple-darwin/SHA256SUMS.part
    181c22d2967c72a5b901d54b9914d243aaf8f52216e48399f09bf17f34455369ec  guix-build-e1f543823b30/output/x86_64-apple-darwin/bitcoin-e1f543823b30-x86_64-apple-darwin-codesigning.tar.gz
    1928c731d91d84f41a0b94cfb420474f150edd2bd33db1e9c38d52c9452e44b3f1  guix-build-e1f543823b30/output/x86_64-apple-darwin/bitcoin-e1f543823b30-x86_64-apple-darwin-unsigned.tar.gz
    20f6b74d1756af4de4a7e250c11f0a48a93fafc67139951afc4a55888ce24dc01a  guix-build-e1f543823b30/output/x86_64-apple-darwin/bitcoin-e1f543823b30-x86_64-apple-darwin-unsigned.zip
    2116d7a33003e89f53b3d8ce31a121250a4f836c83482f39b0c40721a2dd32faca  guix-build-e1f543823b30/output/x86_64-linux-gnu/SHA256SUMS.part
    22d17606b3fec3c045d84dadff4b107186cc6e51daa80a16588de4e213585a98cd  guix-build-e1f543823b30/output/x86_64-linux-gnu/bitcoin-e1f543823b30-x86_64-linux-gnu-debug.tar.gz
    2352ee77c9ff6bbe6965100165847d107c4e3ddcf8c2a960746f663ade074295a5  guix-build-e1f543823b30/output/x86_64-linux-gnu/bitcoin-e1f543823b30-x86_64-linux-gnu.tar.gz
    24daeba27cb9ce21e3a6a01b9487ef81738eec0c84ad80ca0ba1287412c0d4eeda  guix-build-e1f543823b30/output/x86_64-w64-mingw32/SHA256SUMS.part
    2538ccc35fe32895688f4fc0f22ed8a03233d06636a487b49de74a215fc6b67002  guix-build-e1f543823b30/output/x86_64-w64-mingw32/bitcoin-e1f543823b30-win64-codesigning.tar.gz
    2622863abb1a4d1fed1e4753e602f33a743296caf297bdc7ed9330010f5d3f79f3  guix-build-e1f543823b30/output/x86_64-w64-mingw32/bitcoin-e1f543823b30-win64-debug.zip
    271cbc8ae43899d96664e75fa2c3fce2efbb2cfac34b279fe1e240a616646cb3e9  guix-build-e1f543823b30/output/x86_64-w64-mingw32/bitcoin-e1f543823b30-win64-setup-unsigned.exe
    28b6d22f62c083aca24dc788df1676bfc2ce0abc85a796a4823e5802d71482082c  guix-build-e1f543823b30/output/x86_64-w64-mingw32/bitcoin-e1f543823b30-win64-unsigned.zip
    
  2. DrahtBot commented at 3:31 pm on May 2, 2025: contributor

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

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32405.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK shahsb, purpleKarrot
    Concept ACK hebasto
    Approach ACK TheCharlatan

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #31424 (build: enable libc++ hardening in debug builds by vasild)

    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.

  3. DrahtBot added the label Build system on May 2, 2025
  4. build: replace header checks with __has_include
    See https://en.cppreference.com/w/cpp/preprocessor/include.
    e1f543823b
  5. fanquake force-pushed on May 2, 2025
  6. DrahtBot added the label CI failed on May 2, 2025
  7. DrahtBot commented at 3:41 pm on May 2, 2025: contributor

    🚧 At least one of the CI tasks failed. Task lint: https://github.com/bitcoin/bitcoin/runs/41550770562 LLM reason (✨ experimental): Lint check failed due to unnecessary include of bitcoin-build-config.h.

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

  8. hebasto commented at 4:06 pm on May 2, 2025: member
    Concept ACK. This improves code locality.
  9. DrahtBot removed the label CI failed on May 2, 2025
  10. shahsb commented at 4:09 am on May 4, 2025: none

    Concept ACK.

    This improves code readability and simplicity. This is indeed a nice feature from portability and backward compatibility perspective. Thanks for making the changes!!

  11. DrahtBot requested review from hebasto on May 4, 2025
  12. purpleKarrot commented at 9:56 am on May 5, 2025: contributor

    ACK e1f543823b300b28c9edaf5d1a3e1e9badde471b

    Less code, less cmake cache variables, less error prone. However, I have concerns about the if-header-exists-then-include-it pattern, irrespective of the way the existence is checked (both check_include_file_cxx and __has_include). You don’t include a header because it exists, but because of the symbols it declares. The logic should be: If the platform is BAR, then include <foo.h> to use function foo and fail when it it does not exist. If not on platform BAR, then don’t include <foo.h>.

  13. fanquake commented at 11:05 am on May 5, 2025: member

    The logic should be: If the platform is BAR, then include <foo.h>

    Not sure I agree here; as this would give us less-generic code, and the need to maintain platform mappings.

  14. TheCharlatan commented at 11:18 am on May 5, 2025: contributor

    Approach ACK e1f543823b300b28c9edaf5d1a3e1e9badde471b , pending guix build.

    You don’t include a header because it exists, but because of the symbols it declares. The logic should be: If the platform is BAR, then include <foo.h> to use function foo and fail when it it does not exist. If not on platform BAR, then don’t include <foo.h>.

    There is already some additional gating in the first instance (randomenv.cpp), which actually checks for the relevant gadgets (HAVE_SYSCTL). A similar gating in util/threadnames is not required, so I don’t see the need for additional platform mapping here.


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: 2025-05-05 12:12 UTC

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