Skip to content

Commit 0c84a0e

Browse files
committed
Merge bitcoin/bitcoin#27798: depends: modernize clang flags for Darwin
cbee1d7 depends: modernize clang flags (Cory Fields) 2a85857 ci: disable false-positive warnings for now (Cory Fields) Pull request description: This is a cleaner and simpler alternative to #25098. Inspired by [this conversation](bitcoin/bitcoin#27737 (comment)). The diff is large but the change itself is quite small. Fixes builds with llvm >= 11 in guix by working around the problem. As a bonus, this is much cleaner and more maintainable than what we had before. See the updated comment for more info. At a high level: rather than playing tricks and trying to work around clang's default includes, disable them and re-add what we want. ACKs for top commit: fanquake: ACK cbee1d7 - tested Guix and the depends cross-compile. Would like to move this along, to unblock #27676, which itself might be a blocker for #27897. Note that macOS might seem somewhat in flux for the moment, but once we finish the migration to LLVM Clang + LLD, things will be must simpler, and ultimately more maintainable. TheCharlatan: ACK cbee1d7 Tree-SHA512: 5a8300be528f550e15ab23d869e77df7a62201c6d40c0384795a9eecee38118a676e0b79b2b76c5e597597181443caada54a01b75a544dbcde76da1deba8e3a4
2 parents f1b4975 + cbee1d7 commit 0c84a0e

File tree

2 files changed

+17
-36
lines changed

2 files changed

+17
-36
lines changed

ci/test/00_setup_env_mac.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ export XCODE_BUILD_ID=12B45b
1515
export RUN_UNIT_TESTS=false
1616
export RUN_FUNCTIONAL_TESTS=false
1717
export GOAL="deploy"
18-
export BITCOIN_CONFIG="--with-gui --enable-reduce-exports"
18+
19+
# False-positive warning is fixed with clang 17, remove this when that version
20+
# can be used.
21+
export BITCOIN_CONFIG="--with-gui --enable-reduce-exports LDFLAGS=-Wno-error=unused-command-line-argument"

depends/hosts/darwin.mk

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ clang_prog=$(build_prefix)/bin/clang
1919
clangxx_prog=$(clang_prog)++
2020
llvm_config_prog=$(build_prefix)/bin/llvm-config
2121

22-
clang_resource_dir=$(build_prefix)/lib/clang/$(native_clang_version)
2322
else
2423
# FORCE_USE_SYSTEM_CLANG is non-empty, so we use the clang from the user's
2524
# system
@@ -37,7 +36,6 @@ clang_prog=$(shell $(SHELL) $(.SHELLFLAGS) "command -v clang")
3736
clangxx_prog=$(shell $(SHELL) $(.SHELLFLAGS) "command -v clang++")
3837
llvm_config_prog=$(shell $(SHELL) $(.SHELLFLAGS) "command -v llvm-config")
3938

40-
clang_resource_dir=$(shell clang -print-resource-dir)
4139
llvm_lib_dir=$(shell $(llvm_config_prog) --libdir)
4240
endif
4341

@@ -63,53 +61,33 @@ $(foreach TOOL,$(cctools_TOOLS),$(eval darwin_$(TOOL) = $$(build_prefix)/bin/$$(
6361
# Explicitly point to our binaries (e.g. cctools) so that they are
6462
# ensured to be found and preferred over other possibilities.
6563
#
66-
# -stdlib++-isystem$(OSX_SDK)/usr/include/c++/v1
64+
# -isysroot$(OSX_SDK) -nostdlibinc
6765
#
68-
# Forces clang to use the libc++ headers from our SDK and completely
69-
# forget about the libc++ headers from the standard directories
66+
# Disable default include paths built into the compiler as well as
67+
# those normally included for libc and libc++. The only path that
68+
# remains implicitly is the clang resource dir.
7069
#
71-
# -Xclang -*system<path_a> \
72-
# -Xclang -*system<path_b> \
73-
# -Xclang -*system<path_c> ...
70+
# -iwithsysroot / -iframeworkwithsysroot
7471
#
75-
# Adds path_a, path_b, and path_c to the bottom of clang's list of
76-
# include search paths. This is used to explicitly specify the list of
77-
# system include search paths and its ordering, rather than rely on
78-
# clang's autodetection routine. This routine has been shown to:
79-
# 1. Fail to pickup libc++ headers in $SYSROOT/usr/include/c++/v1
80-
# when clang was built manually (see: https://github.com/bitcoin/bitcoin/pull/17919#issuecomment-656785034)
81-
# 2. Fail to pickup C headers in $SYSROOT/usr/include when
82-
# C_INCLUDE_DIRS was specified at configure time (see: https://gist.github.com/dongcarl/5cdc6990b7599e8a5bf6d2a9c70e82f9)
83-
#
84-
# Talking directly to cc1 with -Xclang here grants us access to specify
85-
# more granular categories for these system include search paths, and we
86-
# can use the correct categories that these search paths would have been
87-
# placed in if the autodetection routine had worked correctly. (see:
88-
# https://gist.github.com/dongcarl/5cdc6990b7599e8a5bf6d2a9c70e82f9#the-treatment)
89-
#
90-
# Furthermore, it places these search paths after any "non-Xclang"
91-
# specified search paths. This prevents any additional clang options or
92-
# environment variables from coming after or in between these system
93-
# include search paths, as that would be wrong in general but would also
94-
# break #include_next's.
72+
# Adds the desired paths from the SDK
9573
#
74+
9675
darwin_CC=env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH \
9776
-u OBJC_INCLUDE_PATH -u OBJCPLUS_INCLUDE_PATH -u CPATH \
9877
-u LIBRARY_PATH \
9978
$(clang_prog) --target=$(host) -mmacosx-version-min=$(OSX_MIN_VERSION) \
10079
-B$(build_prefix)/bin -mlinker-version=$(LD64_VERSION) \
101-
-isysroot$(OSX_SDK) \
102-
-Xclang -internal-externc-isystem -Xclang $(clang_resource_dir)/include \
103-
-Xclang -internal-externc-isystem -Xclang $(OSX_SDK)/usr/include
80+
-isysroot$(OSX_SDK) -nostdlibinc \
81+
-iwithsysroot/usr/include -iframeworkwithsysroot/System/Library/Frameworks
82+
10483
darwin_CXX=env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH \
10584
-u OBJC_INCLUDE_PATH -u OBJCPLUS_INCLUDE_PATH -u CPATH \
10685
-u LIBRARY_PATH \
10786
$(clangxx_prog) --target=$(host) -mmacosx-version-min=$(OSX_MIN_VERSION) \
10887
-B$(build_prefix)/bin -mlinker-version=$(LD64_VERSION) \
109-
-isysroot$(OSX_SDK) \
110-
-stdlib++-isystem$(OSX_SDK)/usr/include/c++/v1 \
111-
-Xclang -internal-externc-isystem -Xclang $(clang_resource_dir)/include \
112-
-Xclang -internal-externc-isystem -Xclang $(OSX_SDK)/usr/include
88+
-isysroot$(OSX_SDK) -nostdlibinc \
89+
-iwithsysroot/usr/include/c++/v1 \
90+
-iwithsysroot/usr/include -iframeworkwithsysroot/System/Library/Frameworks
11391

11492
darwin_CFLAGS=-pipe -std=$(C_STANDARD)
11593
darwin_CXXFLAGS=-pipe -std=$(CXX_STANDARD)

0 commit comments

Comments
 (0)