net: use `__has_include` to narrow `__APPLE__` guards #35745

pull csjones wants to merge 1 commits into bitcoin:master from 21-DOT-DEV:apple-netif-guard changing 1 files +2 −2
  1. csjones commented at 5:10 AM on July 19, 2026: contributor

    The __APPLE__ macro is defined on all Apple platforms, but only the macOS SDK ships <net/route.h>. Use __has_include(<net/route.h>) to compile the route-table code only where its header exists, the same idiom randomenv.cpp and util/threadnames.cpp use for system headers, so unsupported platforms use the existing dummy implementation (return std::nullopt).

    No behavior change on any currently built platform; no CI changes are requested.

    This PR does not add support for iOS or any other Apple platform. SDKs without <net/route.h> remain unsupported; they now reach the file's existing dummy implementation instead of failing on an include their SDK does not ship.

    Reproduction (any Mac with Xcode installed)

    unsupported platform

    echo '#include <net/route.h>' | xcrun --sdk iphoneos clang -x c++ -fsyntax-only -
    # <stdin>:1:10: fatal error: 'net/route.h' file not found
    

    macOS

    echo '#include <net/route.h>' | xcrun --sdk macosx clang -x c++ -fsyntax-only -
    # no output == success
    

    What I tested

    # fresh configure, Xcode 26.6, Boost 1.90; builds cleanly
    cmake --build build -j
    # 100% tests passed out of 351
    ctest --test-dir build -j
    
  2. net: use `__has_include` to narrow `__APPLE__` guards
    The `__APPLE__` macro is defined on all Apple platforms, but only the macOS SDK ships `<net/route.h>`. Use `__has_include(<net/route.h>)` to compile the route-table code only where its header exists, the same idiom `randomenv.cpp` and `util/threadnames.cpp` use for system headers, so unsupported platforms use the existing dummy implementation (`return std::nullopt`).
    44e7750b3e
  3. DrahtBot added the label P2P on Jul 19, 2026
  4. DrahtBot commented at 5:10 AM on July 19, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

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

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  5. hebasto commented at 9:28 AM on July 19, 2026: member
    echo '#include <net/route.h>' | xcrun --sdk iphoneos clang -x c++ -fsyntax-only -
    # <stdin>:1:10: fatal error: 'net/route.h' file not found
    

    I don't think this change is necessary, as Bitcoin Core does not support iOS.

  6. csjones commented at 11:52 AM on July 19, 2026: contributor

    I don't think this change is necessary, as Bitcoin Core does not support iOS.

    Thank you for the comment and agreed that Bitcoin Core does not support iOS. However, the existing fallback in netif.cpp is unreachable for non-macOS Apple SDKs because __APPLE__ matches them first and compilation fails on the include inside that branch before they can fall through to the dummy implementation.

    The file's founding change (#30043) decided against failing for a different case: on FreeBSD 13.2 the netlink code could compile but would not run without loading a special kernel module, "so we skip that", routing it to the same dummy implementation (the gate was removed in #35659 as part of establishing the FreeBSD 14+ baseline, leaving the fallback intact).

    Apple's non-macOS SDKs cannot compile the __APPLE__ route-table branch, so the patch applies the same principle used in #30043 and routes them to that fallback thus treating them as unsupported, not adding support.

    EDIT: I've updated the PR description to state this explicitly.

  7. janb84 commented at 9:45 AM on July 20, 2026: contributor

    However, the existing fallback in netif.cpp is unreachable for non-macOS Apple SDKs because __APPLE__ matches them first and compilation fails on the include inside that branch before they can fall through to the [dummy implementation]

    Can you clarify which non-MacOS non-IOS (lets just say any other non-apple*os) os matches the __APPLE__ macro and prevents correct compilation? Like @hebasto said we no not support iOS or any other apple OS other than macOS.

    I just do not see the use-case / applicability of this code/PR. Not to insult you but it feels like an AI suggestion that is correct but not applicable to this codebase.

  8. csjones commented at 4:25 AM on July 21, 2026: contributor

    No problem, I know there's no iOS support, I'll close the PR.

    Can you clarify which non-MacOS non-IOS (lets just say any other non-apple*os) os matches the __APPLE__ macro and prevents correct compilation?

    To answer your last question, __APPLE__ is only defined on Apple platforms so for an unsupported platform, it feels like the handling could be more graceful.

    Thanks for the time.

  9. csjones closed this on Jul 21, 2026

Labels

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-07-22 07:50 UTC

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