depends: set CMAKE_*_COMPILER_TARGET in toolchain #31849

pull fanquake wants to merge 1 commits into bitcoin:master from fanquake:clang_cross_toolchain changing 2 files +5 −0
  1. fanquake commented at 5:00 pm on February 12, 2025: member

    According to the CMake docs, this is the correct way to setup a toolchain file for cross-compilation using Clang. See https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-using-clang

    Internally it looks like CMake will only take this variable into account if it detects the compiler to be Clang, so this shouldn’t effect other builds, but in the case of our Apple cross builds, we’d end up with a duplicated --target=$ARCH-apple-darwin on the compiler line, given we are already setting --target for Darwin builds.

    Would fix #31748.

  2. DrahtBot commented at 5:00 pm on February 12, 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/31849.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK theuni, hebasto

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

  3. DrahtBot added the label Build system on Feb 12, 2025
  4. theuni commented at 7:35 pm on February 13, 2025: member

    Concept ACK. Regarding the duplicate --target… this kind of thing has come up a few times now where we need to add something to cc/flags for depends but we don’t want it exported in our toolchain. I have a branch where I’ve done something similar.

    Additionally, for Xcode generators (and CMake 4.0), I think we’ll want to handle the macOS sdk/include paths differently between depends and the toolchain file, since CMake has specific variables that it really wants set for handling those things, rather than making them part of the compiler.

    I think it makes sense to go ahead and add an abstraction for stuff we want for our depends builds that we don’t want exported to the toolchain. I’ll work a PR for that for discussion.

    That’s not a blocker for this though, I don’t think duplicate --target is the end of the world.

  5. in depends/toolchain.cmake.in:18 in ec8c198d94 outdated
    12@@ -13,6 +13,9 @@ if(@depends_crosscompiling@)
    13   set(CMAKE_SYSTEM_NAME @host_system_name@)
    14   set(CMAKE_SYSTEM_VERSION @host_system_version@)
    15   set(CMAKE_SYSTEM_PROCESSOR @host_arch@)
    16+
    17+  set(CMAKE_C_COMPILER_TARGET @host@)
    18+  set(CMAKE_CXX_COMPILER_TARGET @host@)
    


    hebasto commented at 9:16 am on February 14, 2025:
    Add set(CMAKE_OBJCXX_COMPILER_TARGET [@host](/bitcoin-bitcoin/contributor/host/)@)?

    fanquake commented at 10:17 am on February 14, 2025:
    Added.
  6. hebasto commented at 9:16 am on February 14, 2025: member

    Concept ACK on using as many CMake’s abstractions as possible.

    We already use them in depends:https://github.com/bitcoin/bitcoin/blob/2549fc6fd1cc958a0e2d59838907c8808fd129b3/depends/funcs.mk#L194-L198

    … we’d end up with a duplicated --target=$ARCH-apple-darwin on the compiler line

    This will become a persistent source of confusion and complains, which could, of course, just be ignored. That was the only reason why I initially refrained from using CMAKE_<LANG>_COMPILER_TARGET while working on the staging branch.

    Would it be worth filtering out --target=$ARCH-apple-darwin from CMAKE_<LANG>_COMPILER in the toolchain file?

  7. depends: set CMAKE_*_COMPILER_TARGET in toolchain
    According to the CMake docs, this is the correct way to setup a
    toolchain file for cross-compilation using Clang. See
    https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-using-clang
    
    Internally it looks like CMake will only take this variable into account
    if it detects the compiler to be Clang, so this shouldn't effect other
    builds, but in the case of our Apple cross builds, we'd end up with a
    duplicated `--target=arm64-apple-darwin` on the compiler line, given we
    are already setting `--target` for Darwin builds.
    
    Would fix #31748.
    242e21fdd5
  8. fanquake force-pushed on Feb 14, 2025
  9. fanquake commented at 10:20 am on February 14, 2025: member

    This will become a persistent source of confusion and complains,

    It’s only visible during a verbose build, and only happens when cross-compiling for macOS, on Linux. Which is certainly a less common build for anyone to actually be doing (outside of a Guix build, where it also wouldn’t be visible).

    Would it be worth filtering out –target=$ARCH-apple-darwin from CMAKE__COMPILER in the toolchain file?

    It probably depends on how much code is needed, but I’m not sure filtering should be done unless its generic.

  10. hebasto commented at 11:26 am on February 14, 2025: member

    Would it be worth filtering out –target=$ARCH-apple-darwin from CMAKE__COMPILER in the toolchain file?

    It probably depends on how much code is needed, but I’m not sure filtering should be done unless its generic.

    For example:

     0--- a/depends/toolchain.cmake.in
     1+++ b/depends/toolchain.cmake.in
     2@@ -29,8 +29,15 @@ if(NOT DEFINED CMAKE_C_FLAGS_DEBUG_INIT)
     3   set(CMAKE_C_FLAGS_DEBUG_INIT "@CFLAGS_DEBUG@")
     4 endif()
     5 
     6+macro(fliter_flags compiler_invocation_line)
     7+  if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
     8+    list(FILTER ${compiler_invocation_line} EXCLUDE REGEX "--target=@host@")
     9+  endif()
    10+endmacro()
    11+
    12 if(NOT DEFINED CMAKE_C_COMPILER)
    13   set(CMAKE_C_COMPILER [@CC](/bitcoin-bitcoin/contributor/cc/)@)
    14+  fliter_flags(CMAKE_C_COMPILER)
    15 endif()
    16 
    17 if(NOT DEFINED CMAKE_CXX_FLAGS_INIT)
    18@@ -48,6 +55,7 @@ endif()
    19 
    20 if(NOT DEFINED CMAKE_CXX_COMPILER)
    21   set(CMAKE_CXX_COMPILER [@CXX](/bitcoin-bitcoin/contributor/cxx/)@)
    22+  fliter_flags(CMAKE_CXX_COMPILER)
    23   set(CMAKE_OBJCXX_COMPILER ${CMAKE_CXX_COMPILER})
    24 endif()
    25 
    

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-02-22 06:12 UTC

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