Skip to content

Commit 3007339

Browse files
committed
depends: Pin clang search paths for darwin host
1 parent 107f33d commit 3007339

File tree

1 file changed

+52
-3
lines changed

1 file changed

+52
-3
lines changed

depends/hosts/darwin.mk

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ LD64_VERSION=530
66

77
OSX_SDK=$(SDK_PATH)/Xcode-$(XCODE_VERSION)-$(XCODE_BUILD_ID)-extracted-SDK-with-libcxx-headers
88

9+
ifeq ($(strip $(FORCE_USE_SYSTEM_CLANG)),)
10+
clang_resource_dir=$(build_prefix)/lib/clang/$(native_cctools_clang_version)
11+
else
12+
clang_resource_dir=$(shell clang -print-resource-dir)
13+
endif
14+
915
# Flag explanations:
1016
#
1117
# -mlinker-version
@@ -18,7 +24,7 @@ OSX_SDK=$(SDK_PATH)/Xcode-$(XCODE_VERSION)-$(XCODE_BUILD_ID)-extracted-SDK-with-
1824
# Explicitly point to our binaries (e.g. cctools) so that they are
1925
# ensured to be found and preferred over other possibilities.
2026
#
21-
# -nostdinc++ -isystem $(OSX_SDK)/usr/include/c++/v1
27+
# -stdlib=libc++ -nostdinc++ -Xclang -cxx-isystem$(OSX_SDK)/usr/include/c++/v1
2228
#
2329
# Forces clang to use the libc++ headers from our SDK and completely
2430
# forget about the libc++ headers from the standard directories
@@ -28,8 +34,51 @@ OSX_SDK=$(SDK_PATH)/Xcode-$(XCODE_VERSION)-$(XCODE_BUILD_ID)-extracted-SDK-with-
2834
# https://reviews.llvm.org/D64089, we should use that instead. Read the
2935
# differential summary there for more details.
3036
#
31-
darwin_CC=clang -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) -B$(build_prefix)/bin
32-
darwin_CXX=clang++ -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -stdlib=libc++ -mlinker-version=$(LD64_VERSION) -B$(build_prefix)/bin -nostdinc++ -isystem $(OSX_SDK)/usr/include/c++/v1
37+
# -Xclang -*system<path_a> \
38+
# -Xclang -*system<path_b> \
39+
# -Xclang -*system<path_c> ...
40+
#
41+
# Adds path_a, path_b, and path_c to the bottom of clang's list of
42+
# include search paths. This is used to explicitly specify the list of
43+
# system include search paths and its ordering, rather than rely on
44+
# clang's autodetection routine. This routine has been shown to:
45+
# 1. Fail to pickup libc++ headers in $SYSROOT/usr/include/c++/v1
46+
# when clang was built manually (see: https://github.com/bitcoin/bitcoin/pull/17919#issuecomment-656785034)
47+
# 2. Fail to pickup C headers in $SYSROOT/usr/include when
48+
# C_INCLUDE_DIRS was specified at configure time (see: https://gist.github.com/dongcarl/5cdc6990b7599e8a5bf6d2a9c70e82f9)
49+
#
50+
# Talking directly to cc1 with -Xclang here grants us access to specify
51+
# more granular categories for these system include search paths, and we
52+
# can use the correct categories that these search paths would have been
53+
# placed in if the autodetection routine had worked correctly. (see:
54+
# https://gist.github.com/dongcarl/5cdc6990b7599e8a5bf6d2a9c70e82f9#the-treatment)
55+
#
56+
# Furthermore, it places these search paths after any "non-Xclang"
57+
# specified search paths. This prevents any additional clang options or
58+
# environment variables from coming after or in between these system
59+
# include search paths, as that would be wrong in general but would also
60+
# break #include_next's.
61+
#
62+
darwin_CC=env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH \
63+
-u OBJC_INCLUDE_PATH -u OBJCPLUS_INCLUDE_PATH -u CPATH \
64+
-u LIBRARY_PATH \
65+
clang --target=$(host) -mmacosx-version-min=$(OSX_MIN_VERSION) \
66+
-B$(build_prefix)/bin -mlinker-version=$(LD64_VERSION) \
67+
-fuse-ld=$(build_prefix)/bin/x86_64-apple-darwin16-ld \
68+
--sysroot=$(OSX_SDK) \
69+
-Xclang -internal-externc-isystem$(clang_resource_dir)/include \
70+
-Xclang -internal-externc-isystem$(OSX_SDK)/usr/include
71+
darwin_CXX=env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH \
72+
-u OBJC_INCLUDE_PATH -u OBJCPLUS_INCLUDE_PATH -u CPATH \
73+
-u LIBRARY_PATH \
74+
clang++ --target=$(host) -mmacosx-version-min=$(OSX_MIN_VERSION) \
75+
-B$(build_prefix)/bin -mlinker-version=$(LD64_VERSION) \
76+
-fuse-ld=$(build_prefix)/bin/x86_64-apple-darwin16-ld \
77+
--sysroot=$(OSX_SDK) \
78+
-stdlib=libc++ -nostdinc++ \
79+
-Xclang -cxx-isystem$(OSX_SDK)/usr/include/c++/v1 \
80+
-Xclang -internal-externc-isystem$(clang_resource_dir)/include \
81+
-Xclang -internal-externc-isystem$(OSX_SDK)/usr/include
3382

3483
darwin_CFLAGS=-pipe
3584
darwin_CXXFLAGS=$(darwin_CFLAGS)

0 commit comments

Comments
 (0)