depends: Add –sysroot option to mac os native compile flags #18743

pull ryanofsky wants to merge 1 commits into bitcoin:master from ryanofsky:pr/sysroot changing 1 files +2 −2
  1. ryanofsky commented at 8:18 pm on April 22, 2020: member

    Catalina SDK clang stopped automatically searching the SDK include paths when invoked without --sysroot:

    This hasn’t been a problem for current native depends packages because are passing their own --sysroot values, and hasn’t been a problem for current host packages because they use darwin_ commands instead of build_darwin_ commands. But the current build_darwin_CC and build_darwin_CXX commands are still unnecessarily fragile, and incompatible with new native depends packages added in #18677.

    Cory Fields (theuni) suggested in #16367 (comment) switching compiler from SDK clang to native clang (from $PATH) to avoid this problem. This is easy and makes a certain amount of sense for building native packages, as opposed to host packages. But Michael (fanquake) pointed out in #18677 (review) that it would be inconsistent to switch to non-SDK compilers while still using other SDK tools like ranlib and install_name_tool. So simplest, minimal fix seems to be just adding the missing --sysroot option.

  2. depends: Add --sysroot option to mac os native compile flags
    Catalina SDK clang stopped automatically searching the SDK include paths when
    invoked without --sysroot:
    
    https://github.com/bitcoin/bitcoin/pull/16367#issuecomment-594600985
    https://github.com/Homebrew/homebrew-core/issues/45061
    
    This hasn't been a problem for current native depends packages because are
    passing their own --sysroot values, and hasn't been a problem for current host
    packages because they use `darwin_` commands instead of `build_darwin_`
    commands.  But the current `build_darwin_CC` and `build_darwin_CXX` commands
    are still unnecessarily fragile, and incompatible with new native depends
    packages added in https://github.com/bitcoin/bitcoin/pull/18677.
    
    Cory Fields <cory-nospam-@coryfields.com> suggested in
    https://github.com/bitcoin/bitcoin/pull/16367#issuecomment-595393546 switching
    compiler from SDK clang to native clang (from $PATH) to avoid this problem.
    This is easy and makes a certain amount of sense for building native packages,
    as opposed to host packages. But fanquake <fanquake@gmail.com> pointed out in
    https://github.com/bitcoin/bitcoin/pull/18677#discussion_r409934309 that it
    would be inconsistent use switch to non-SDK compilers while still using other
    SDK tools like ranlib and install_name_tool. So simplest, minimal fix seems to
    be just adding the missing --sysroot option.
    1e94a2bcbc
  3. fanquake added the label Build system on Apr 22, 2020
  4. MarcoFalke added the label Needs Guix build on Apr 22, 2020
  5. MarcoFalke removed the label Needs Guix build on Apr 22, 2020
  6. MarcoFalke added the label Needs gitian build on Apr 22, 2020
  7. DrahtBot commented at 4:45 am on April 23, 2020: member

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

    Conflicts

    No conflicts as of last run.

  8. fanquake commented at 1:13 pm on April 25, 2020: member
    Thanks for splitting this out. Will review.
  9. DrahtBot commented at 10:20 pm on April 26, 2020: member

    Gitian builds

    File commit 65276c7737176a5269b052ceae78dbb44b216bf4(master) commit 3eef5a85cdb2b74b161ea6f19e9426e398017bf2(master and this pull)
    bitcoin-0.20.99-aarch64-linux-gnu-debug.tar.gz 673ecc74f832f550... ef2da77636f77213...
    bitcoin-0.20.99-aarch64-linux-gnu.tar.gz 8cacd39d9032cfa0... d518a16100bebac1...
    bitcoin-0.20.99-arm-linux-gnueabihf-debug.tar.gz f33c821af966c7cc... 51517d70e1cc74c5...
    bitcoin-0.20.99-arm-linux-gnueabihf.tar.gz 1610dfc4ad6edcc8... 3329784eeba74a35...
    bitcoin-0.20.99-osx-unsigned.dmg d9b58fd52650821b... e90b4ef8b34de195...
    bitcoin-0.20.99-osx64.tar.gz 2dd8003da396d8ff... efe0d7ad03802192...
    bitcoin-0.20.99-riscv64-linux-gnu-debug.tar.gz 6ab423f10d0576b8... 159270fcefb99d2f...
    bitcoin-0.20.99-riscv64-linux-gnu.tar.gz e2c3d277f9188905... 4c21230cb8e7bba6...
    bitcoin-0.20.99-win64-debug.zip 920cfb921c277ab6... 17c821f355dbcb1e...
    bitcoin-0.20.99-win64-setup-unsigned.exe 499d0e7e3d66123b... a740d57641934e69...
    bitcoin-0.20.99-win64.zip b4c5466788c5ab31... e5cecb010a8761d0...
    bitcoin-0.20.99-x86_64-linux-gnu-debug.tar.gz 771c49516716cf2f... 7a889fadc72217f6...
    bitcoin-0.20.99-x86_64-linux-gnu.tar.gz 9baf50756b8e295a... dfb6d8c65626ce14...
    bitcoin-0.20.99.tar.gz 20db243e4a63e9be... e6f760ab887255cb...
    bitcoin-core-linux-0.21-res.yml 3764dafda91b4998... f87b786f87dc80d6...
    bitcoin-core-osx-0.21-res.yml c908e4d8f612478d... 8328176b5a51f997...
    bitcoin-core-win-0.21-res.yml 65a1ad714e6b7e4c... a301db7f0b7ab07d...
    linux-build.log dbc67f519f1bc039... a5ca86f8bcf5ee20...
    osx-build.log 680987f733987400... bceeff7bb568289d...
    win-build.log 861910357a3af2e6... 11e069a64a7df2b8...
    bitcoin-core-linux-0.21-res.yml.diff 8d65ed4c652db944...
    bitcoin-core-osx-0.21-res.yml.diff 02b2959f25184b43...
    bitcoin-core-win-0.21-res.yml.diff 8ff030c505315d26...
    linux-build.log.diff 667d3b0264bc58d7...
    osx-build.log.diff cd0fbf4e35269f82...
    win-build.log.diff dab47fa63d28ec09...
  10. DrahtBot removed the label Needs gitian build on Apr 26, 2020
  11. fanquake commented at 11:48 am on April 27, 2020: member

    ACK 1e94a2bcbc5ff8ae61eed9f31317ea534649116d - I think this change is ok, and I prefer it to the previous patch. Thanks for the summary in the PR description. I played around with Xcode and the CLT; I think previously I didn’t fully grok the slight differences between the two.

    This output was produced from a test.cpp containing just #include <stdlib.h>.

    CLT Clang vs CLT Clang with -isysroot:

    /Library/Developer/CommandLineTools/usr/bin/clang++ -c test.cpp -v /Library/Developer/CommandLineTools/usr/bin/clang++ -c test.cpp -v -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

     0--- a.txt
     1+++ b.txt
     2@@ -1,17 +1,17 @@
     3 Apple clang version 11.0.3 (clang-1103.0.32.59)
     4 Target: x86_64-apple-darwin19.4.0
     5 Thread model: posix
     6 InstalledDir: /Library/Developer/CommandLineTools/usr/bin
     7- "/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.15.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fno-strict-return -masm-verbose -munwind-tables -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 556.6 -v -coverage-notes-file /Users/michael/Desktop/clt/test.gcno -resource-dir /Library/Developer/CommandLineTools/usr/lib/clang/11.0.3 -stdlib=libc++ -internal-isystem /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1 -internal-isystem /usr/include/c++/v1 -internal-isystem /usr/local/include -internal-isystem /Library/Developer/CommandLineTools/usr/lib/clang/11.0.3/include -internal-externc-isystem /usr/include -internal-externc-isystem /Library/Developer/CommandLineTools/usr/include -Wno-objc-signed-char-bool-implicit-int-conversion -Wno-extra-semi-stmt -Wno-quoted-include-in-framework-header -fdeprecated-macro -fdebug-compilation-dir /Users/michael/Desktop/clt -ferror-limit 19 -fmessage-length 131 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fobjc-runtime=macosx-10.15.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o test.o -x c++ test.cpp
     8+ "/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.15.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=10.15.4 -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 556.6 -v -coverage-notes-file /Users/michael/Desktop/clt/test.gcno -resource-dir /Library/Developer/CommandLineTools/usr/lib/clang/11.0.3 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -stdlib=libc++ -internal-isystem /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1 -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1 -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Library/Developer/CommandLineTools/usr/lib/clang/11.0.3/include -internal-externc-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Library/Developer/CommandLineTools/usr/include -Wno-objc-signed-char-bool-implicit-int-conversion -Wno-extra-semi-stmt -Wno-quoted-include-in-framework-header -fdeprecated-macro -fdebug-compilation-dir /Users/michael/Desktop/clt -ferror-limit 19 -fmessage-length 131 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fobjc-runtime=macosx-10.15.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o test.o -x c++ test.cpp
     9 clang -cc1 version 11.0.3 (clang-1103.0.32.59) default target x86_64-apple-darwin19.4.0
    10-ignoring nonexistent directory "/usr/include/c++/v1"
    11-ignoring nonexistent directory "/usr/include"
    12+ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1"
    13+ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
    14+ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
    15 #include "..." search starts here:
    16 #include <...> search starts here:
    17  /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1
    18- /usr/local/include
    19  /Library/Developer/CommandLineTools/usr/lib/clang/11.0.3/include
    20+ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
    21  /Library/Developer/CommandLineTools/usr/include
    22- /System/Library/Frameworks (framework directory)
    23- /Library/Frameworks (framework directory)
    24+ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
    25 End of search list.
    

    When you pass -isysroot, to CLT Clang, /usr/local/include and /Library/Frameworks are dropped from the include search paths, and /usr/include is added. Note that -target-sdk-version=SDK_VERSION is also added to the compile flags.

    CLT Clang -isysroot vs Xcode Clang:

    Invoking CLT Clang with -isysroot is then seemingly equivalent to Xcode Clang, except for Xcode Clang additionally searching /usr/local/include.

    /Library/Developer/CommandLineTools/usr/bin/clang++ -c test.cpp -v -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk clang++ -c test.cpp -v

     0-InstalledDir: /Library/Developer/CommandLineTools/usr/bin
     1- "/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.15.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=10.15.4 -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 556.6 -v -coverage-notes-file /Users/michael/Desktop/clt/test.gcno -resource-dir /Library/Developer/CommandLineTools/usr/lib/clang/11.0.3 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -stdlib=libc++ -internal-isystem /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1 -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1 -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Library/Developer/CommandLineTools/usr/lib/clang/11.0.3/include -internal-externc-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Library/Developer/CommandLineTools/usr/include -Wno-objc-signed-char-bool-implicit-int-conversion -Wno-extra-semi-stmt -Wno-quoted-include-in-framework-header -fdeprecated-macro -fdebug-compilation-dir /Users/michael/Desktop/clt -ferror-limit 19 -fmessage-length 131 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fobjc-runtime=macosx-10.15.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o test.o -x c++ test.cpp
     2+InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
     3+ "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.15.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=10.15.4 -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 556.6 -v -coverage-notes-file /Users/michael/Desktop/clt/test.gcno -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.3 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -I/usr/local/include -stdlib=libc++ -internal-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.3/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Wno-objc-signed-char-bool-implicit-int-conversion -Wno-extra-semi-stmt -Wno-quoted-include-in-framework-header -fdeprecated-macro -fdebug-compilation-dir /Users/michael/Desktop/clt -ferror-limit 19 -fmessage-length 131 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fobjc-runtime=macosx-10.15.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o test.o -x c++ test.cpp
     4 clang -cc1 version 11.0.3 (clang-1103.0.32.59) default target x86_64-apple-darwin19.4.0
     5-ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1"
     6-ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
     7-ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
     8+ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1"
     9+ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include"
    10+ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks"
    11 #include "..." search starts here:
    12 #include <...> search starts here:
    13- /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1
    14- /Library/Developer/CommandLineTools/usr/lib/clang/11.0.3/include
    15- /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
    16- /Library/Developer/CommandLineTools/usr/include
    17- /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
    18+ /usr/local/include
    19+ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
    20+ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.3/include
    21+ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
    22+ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
    23+ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
    24 End of search list.
    
  12. dongcarl commented at 12:07 pm on April 27, 2020: member
    Is /Library/Developer/CommandLineTools a symlink to /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain or vice versa?
  13. fanquake commented at 12:33 pm on April 27, 2020: member

    Is /Library/Developer/CommandLineTools a symlink to /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain or vice versa?

    No, they are standalone, and there are decent differences between the content of either. Xcode has a bunch more Swift modules, Apple simulator components and dylibs bundled with it. For example, you can see a diff of /Library/Developer/CommandLineTools/usr and /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr here: https://gist.github.com/fanquake/22267d783ac76fbe3eba110d14433e7c.

    The macOS SDKs inside either seem to be identical. i.e: diffoscope /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk --exclude-directory-metadata

  14. ryanofsky commented at 2:36 pm on April 27, 2020: member

    ACK 1e94a2b - I think this change is ok, and I prefer it to the previous patch.

    The current change 1e94a2bcbc5ff8ae61eed9f31317ea534649116d is the original fix I made for the issue before Cory’s suggestion in #16367 (comment).

    It seems safe and good. But Cory’s suggestion to just use clang and presumably ld, nm, etc directly instead of going through an SDK for native packages (which are internal build & code generation tools not distributed or used at runtime) seems it should be a nice simplification and cleanup and more durable fix. I could be wrong but I’d assume a more typical way of building non-gui unix tools on mac is:

    0./configure
    1make
    2make install
    

    and not:

    0./configure CC="$(shell xcrun -f clang) --sysroot $(shell xcrun --show-sdk-path)"
    1make
    2make install
    

    My reason for going back to the direct bugfix 1e94a2bcbc5ff8ae61eed9f31317ea534649116d instead of my half-implementation fba09de775f1eff68d2f72650bccc418cbe87cf8 of Cory suggestion is just that I know the direct fix works and I don’t have a great way of testing other alternatives. But probably an extension of fba09de775f1eff68d2f72650bccc418cbe87cf8 would be a better way to go in the long run.

  15. fanquake commented at 1:26 pm on May 2, 2020: member
    @dongcarl did you have something specific you wanted to follow up with here in regards to the symlink query?
  16. dongcarl commented at 5:50 pm on May 4, 2020: member
    @fanquake No not really. My initial impression here is that we should remove all the xcrun invocations if we can, as doing that makes explicit we’re expecting a standard toolchain for building (open source) applications from source. Will need to test that it works though.
  17. fanquake commented at 12:37 pm on May 7, 2020: member
    @dongcarl Ok, lets follow up with that then. Want to open an issue to track? I’m going to merge this now to unblock Russ and #18677.
  18. fanquake merged this on May 7, 2020
  19. fanquake closed this on May 7, 2020

  20. sidhujag referenced this in commit d51641ba68 on May 12, 2020
  21. jasonbcox referenced this in commit ce5bf0a880 on Sep 23, 2020
  22. random-zebra referenced this in commit 64da8d9167 on Jul 2, 2021
  23. kittywhiskers referenced this in commit 059728233a on Jul 15, 2021
  24. kittywhiskers referenced this in commit 018a788ef6 on Jul 15, 2021
  25. UdjinM6 referenced this in commit 66d80b6a30 on Jul 19, 2021
  26. UdjinM6 referenced this in commit 1f6adef97c on Jul 19, 2021
  27. kittywhiskers referenced this in commit 10adf0fe6a on Jul 20, 2021
  28. kittywhiskers referenced this in commit be5837ec51 on Jul 20, 2021
  29. DrahtBot locked this on Feb 15, 2022

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

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