Skip to content

Commit

Permalink
depends: remove FORCE_USE_SYSTEM_CLANG
Browse files Browse the repository at this point in the history
  • Loading branch information
div72 committed Sep 23, 2024
1 parent a7fa64f commit 54c008e
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 165 deletions.
124 changes: 38 additions & 86 deletions depends/hosts/darwin.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,10 @@ OSX_MIN_VERSION=10.14
OSX_SDK_VERSION=10.15.6
XCODE_VERSION=12.1
XCODE_BUILD_ID=12A7403
LD64_VERSION=609
LLD_VERSION=609

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

darwin_native_binutils=native_cctools

ifeq ($(strip $(FORCE_USE_SYSTEM_CLANG)),)
# FORCE_USE_SYSTEM_CLANG is empty, so we use our depends-managed, pinned clang
# from llvm.org

# The native_cctools package is what provides clang when FORCE_USE_SYSTEM_CLANG
# is empty
darwin_native_toolchain=native_cctools

clang_prog=$(build_prefix)/bin/clang
clangxx_prog=$(clang_prog)++

clang_resource_dir=$(build_prefix)/lib/clang/$(native_cctools_clang_version)
else
# FORCE_USE_SYSTEM_CLANG is non-empty, so we use the clang from the user's
# system

darwin_native_toolchain=

# We can't just use $(shell command -v clang) because GNU Make handles builtins
# in a special way and doesn't know that `command` is a POSIX-standard builtin
# prior to 1af314465e5dfe3e8baa839a32a72e83c04f26ef, first released in v4.2.90.
Expand All @@ -36,18 +16,12 @@ darwin_native_toolchain=
clang_prog=$(shell $(SHELL) $(.SHELLFLAGS) "command -v clang")
clangxx_prog=$(shell $(SHELL) $(.SHELLFLAGS) "command -v clang++")

clang_resource_dir=$(shell clang -print-resource-dir)
endif

cctools_TOOLS=AR RANLIB STRIP NM LIBTOOL OTOOL INSTALL_NAME_TOOL

# Make-only lowercase function
lc = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1))))))))))))))))))))))))))

# For well-known tools provided by cctools, make sure that their well-known
# variable is set to the full path of the tool, just like how AC_PATH_{TOO,PROG}
# would.
$(foreach TOOL,$(cctools_TOOLS),$(eval darwin_$(TOOL) = $$(build_prefix)/bin/$$(host)-$(call lc,$(TOOL))))
darwin_AR=$(shell $(SHELL) $(.SHELLFLAGS) "command -v llvm-ar")
darwin_DSYMUTIL=$(shell $(SHELL) $(.SHELLFLAGS) "command -v dsymutil")
darwin_NM=$(shell $(SHELL) $(.SHELLFLAGS) "command -v llvm-nm")
darwin_OBJDUMP=$(shell $(SHELL) $(.SHELLFLAGS) "command -v llvm-objdump")
darwin_RANLIB=$(shell $(SHELL) $(.SHELLFLAGS) "command -v llvm-ranlib")
darwin_STRIP=$(shell $(SHELL) $(.SHELLFLAGS) "command -v llvm-strip")

# Flag explanations:
#
Expand All @@ -56,67 +30,45 @@ $(foreach TOOL,$(cctools_TOOLS),$(eval darwin_$(TOOL) = $$(build_prefix)/bin/$$(
# Ensures that modern linker features are enabled. See here for more
# details: https://github.com/bitcoin/bitcoin/pull/19407.
#
# -B$(build_prefix)/bin
# -isysroot$(OSX_SDK) -nostdlibinc
#
# Explicitly point to our binaries (e.g. cctools) so that they are
# ensured to be found and preferred over other possibilities.
# Disable default include paths built into the compiler as well as
# those normally included for libc and libc++. The only path that
# remains implicitly is the clang resource dir.
#
# -stdlib=libc++ -nostdinc++ -Xclang -cxx-isystem$(OSX_SDK)/usr/include/c++/v1
# -iwithsysroot / -iframeworkwithsysroot
#
# Forces clang to use the libc++ headers from our SDK and completely
# forget about the libc++ headers from the standard directories
# Adds the desired paths from the SDK
#
# TODO: Once we start requiring a clang version that has the
# -stdlib++-isystem<directory> flag first introduced here:
# https://reviews.llvm.org/D64089, we should use that instead. Read the
# differential summary there for more details.
# -platform_version
#
# -Xclang -*system<path_a> \
# -Xclang -*system<path_b> \
# -Xclang -*system<path_c> ...
# Indicate to the linker the platform, the oldest supported version,
# and the SDK used.
#
# 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)
# -no_adhoc_codesign
#
# 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=env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH \
-u OBJC_INCLUDE_PATH -u OBJCPLUS_INCLUDE_PATH -u CPATH \
-u LIBRARY_PATH \
$(clang_prog) --target=$(host) -mmacosx-version-min=$(OSX_MIN_VERSION) \
-B$(build_prefix)/bin -mlinker-version=$(LD64_VERSION) \
-isysroot$(OSX_SDK) \
-Xclang -internal-externc-isystem$(clang_resource_dir)/include \
-Xclang -internal-externc-isystem$(OSX_SDK)/usr/include
darwin_CXX=env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH \
-u OBJC_INCLUDE_PATH -u OBJCPLUS_INCLUDE_PATH -u CPATH \
-u LIBRARY_PATH \
$(clangxx_prog) --target=$(host) -mmacosx-version-min=$(OSX_MIN_VERSION) \
-B$(build_prefix)/bin -mlinker-version=$(LD64_VERSION) \
-isysroot$(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
# Disable adhoc codesigning (for now) when using LLVM tooling, to avoid
# non-determinism issues with the Identifier field.

darwin_CC=$(clang_prog) --target=$(host) \
-isysroot$(OSX_SDK) -nostdlibinc \
-iwithsysroot/usr/include -iframeworkwithsysroot/System/Library/Frameworks

darwin_CXX=$(clangxx_prog) --target=$(host) \
-isysroot$(OSX_SDK) -nostdlibinc \
-iwithsysroot/usr/include/c++/v1 \
-iwithsysroot/usr/include -iframeworkwithsysroot/System/Library/Frameworks

darwin_CFLAGS=-pipe -std=$(C_STANDARD) -mmacos-version-min=$(OSX_MIN_VERSION)
darwin_CXXFLAGS=-pipe -std=$(CXX_STANDARD) -mmacos-version-min=$(OSX_MIN_VERSION)
darwin_LDFLAGS=-Wl,-platform_version,macos,$(OSX_MIN_VERSION),$(OSX_SDK_VERSION)

ifneq ($(build_os),darwin)
darwin_CFLAGS += -mlinker-version=$(LLD_VERSION)
darwin_CXXFLAGS += -mlinker-version=$(LLD_VERSION)
darwin_LDFLAGS += -Wl,-no_adhoc_codesign -fuse-ld=lld
endif

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

darwin_release_CFLAGS=-O2
darwin_release_CXXFLAGS=$(darwin_release_CFLAGS)
Expand Down
2 changes: 0 additions & 2 deletions depends/packages/bzip2.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ define $(package)_set_vars
$(package)_build_opts+=CFLAGS="$($(package)_cflags) $($(package)_cppflags) -fPIC"
$(package)_build_opts+=RANLIB="$($(package)_ranlib)"
$(package)_build_opts+=AR="$($(package)_ar)"
# $(package)_build_opts_darwin+=AR="$($(package)_libtool)"
# $(package)_build_opts_darwin+=ARFLAGS="-o"
$(package)_cxxflags_aarch64_linux = $(GCCFLAGS)
$(package)_cflags_aarch64_linux = $(GCCFLAGS)
$(package)_cxxflags_arm_linux = $(GCCFLAGS)
Expand Down
1 change: 0 additions & 1 deletion depends/packages/miniupnpc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ $(package)_patches=dont_leak_info.patch

define $(package)_set_vars
$(package)_build_opts=CC="$($(package)_cc)"
$(package)_build_opts_darwin=LIBTOOL="$($(package)_libtool)"
$(package)_build_opts_mingw32=-f Makefile.mingw
$(package)_build_env+=CFLAGS="$($(package)_cflags) $($(package)_cppflags)" AR="$($(package)_ar)"
$(package)_cxxflags_aarch64_linux = $(GCCFLAGS)
Expand Down
33 changes: 0 additions & 33 deletions depends/packages/native_cctools.mk

This file was deleted.

17 changes: 0 additions & 17 deletions depends/packages/native_clang.mk

This file was deleted.

20 changes: 0 additions & 20 deletions depends/packages/native_libtapi.mk

This file was deleted.

5 changes: 1 addition & 4 deletions depends/packages/packages.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,5 @@ upnp_packages=miniupnpc
darwin_native_packages = native_ds_store native_mac_alias

ifneq ($(build_os),darwin)
darwin_native_packages += native_cctools native_libtapi native_libdmg-hfsplus
ifeq ($(strip $(FORCE_USE_SYSTEM_CLANG)),)
darwin_native_packages+= native_clang
endif
darwin_native_packages += native_libdmg-hfsplus
endif
2 changes: 0 additions & 2 deletions depends/packages/zlib.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ $(package)_config_opts= CC="$($(package)_cc)"
$(package)_config_opts+=CFLAGS="$($(package)_cflags) $($(package)_cppflags) -fPIC"
$(package)_config_opts+=RANLIB="$($(package)_ranlib)"
$(package)_config_opts+=AR="$($(package)_ar)"
$(package)_config_opts_darwin+=AR="$($(package)_libtool)"
$(package)_config_opts_darwin+=ARFLAGS="-o"
$(package)_config_opts_android+=CHOST=$(host)
endef

Expand Down

0 comments on commit 54c008e

Please sign in to comment.