Skip to content

Commit

Permalink
depends: Explicitly specify clang search paths for darwin host
Browse files Browse the repository at this point in the history
  • Loading branch information
dongcarl committed Aug 7, 2020
1 parent 82127d2 commit 8b8296d
Showing 1 changed file with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions depends/hosts/darwin.mk
Expand Up @@ -6,19 +6,25 @@ LD64_VERSION=530

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

ifeq ($(strip $(FORCE_USE_SYSTEM_CLANG)),)
clang_resource_dir=$(build_prefix)/lib/clang/$(native_cctools_clang_version)
else
clang_resource_dir=$(shell clang -print-resource-dir)
endif

# Flag explanations:
#
# -mlinker-version
#
# Ensures that modern linker features are enabled. See here for more
# details: https://github.com/bitcoin/bitcoin/pull/19407.
#
# -B$(build_prefix)/bin
# -B"$(build_prefix)/bin"
#
# Explicitly point to our binaries (e.g. cctools) so that they are
# ensured to be found and preferred over other possibilities.
#
# -nostdinc++ -isystem $(OSX_SDK)/usr/include/c++/v1
# -stdlib=libc++ -nostdinc++ -Xclang -cxx-isystem"$(OSX_SDK)/usr/include/c++/v1"
#
# Forces clang to use the libc++ headers from our SDK and completely
# forget about the libc++ headers from the standard directories
Expand All @@ -28,8 +34,42 @@ OSX_SDK=$(SDK_PATH)/Xcode-$(XCODE_VERSION)-$(XCODE_BUILD_ID)-extracted-SDK-with-
# https://reviews.llvm.org/D64089, we should use that instead. Read the
# differential summary there for more details.
#
darwin_CC=clang -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) -B$(build_prefix)/bin
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
# -Xclang -*system"<path_a>" \
# -Xclang -*system"<path_b>" \
# -Xclang -*system"<path_c>" ...
#
# Adds path_a, path_b, and path_c to the bottom of clang's list of
# include search paths. This is used to explicitly specify the list of
# system include search paths and its ordering, rather than rely on
# clang's autodetection routine. This routine has been shown to:
# 1. Fail to pickup libc++ headers in $SYSROOT/usr/include/c++/v1
# when clang was built manually (see: https://github.com/bitcoin/bitcoin/pull/17919#issuecomment-656785034)
# 2. Fail to pickup C headers in $SYSROOT/usr/include when
# C_INCLUDE_DIRS was specified at configure time (see: https://gist.github.com/dongcarl/5cdc6990b7599e8a5bf6d2a9c70e82f9)
#
# Talking directly to cc1 with -Xclang here grants us access to specify
# more granular categories for these system include search paths, and we
# can use the correct categories that these search paths would have been
# placed in if the autodetection routine had worked correctly. (see:
# https://gist.github.com/dongcarl/5cdc6990b7599e8a5bf6d2a9c70e82f9#the-treatment)
#
# Furthermore, it places these search paths after any "non-Xclang"
# specified search paths. This prevents any additional clang options or
# environment variables from coming after or in between these system
# include search paths, as that would be wrong in general but would also
# break #include_next's.
#
darwin_CC=clang -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) \
-mlinker-version="$(LD64_VERSION)" -B"$(build_prefix)/bin" \
--sysroot "$(OSX_SDK)" \
-Xclang -internal-externc-isystem"$(clang_resource_dir)/include" \
-Xclang -internal-externc-isystem"$(OSX_SDK)/usr/include"
darwin_CXX=clang++ -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) \
-mlinker-version="$(LD64_VERSION)" -B"$(build_prefix)/bin" \
--sysroot "$(OSX_SDK)" \
-stdlib=libc++ -nostdinc++ -Xclang -cxx-isystem"$(OSX_SDK)/usr/include/c++/v1" \
-Xclang -internal-externc-isystem"$(clang_resource_dir)/include" \
-Xclang -internal-externc-isystem"$(OSX_SDK)/usr/include"

darwin_CFLAGS=-pipe
darwin_CXXFLAGS=$(darwin_CFLAGS)
Expand Down

0 comments on commit 8b8296d

Please sign in to comment.