Skip to content

Commit 1148f3d

Browse files
committed
Merge #17919: depends: Allow building with system clang
de4fedb depends: Add documentation for FORCE_USE_SYSTEM_CLANG make flag (Carl Dong) fe98999 depends: Reformat make options as definition list (Carl Dong) 60c55b1 depends: Add justifications for macOS clang flags (Carl Dong) 6b8e497 depends: specify libc++ header location for darwin (Cory Fields) 156b604 depends: force a new host id string if FORCE_USE_SYSTEM_CLANG is in use (Cory Fields) c9c572a depends: Allow building with system clang (Carl Dong) e6e5c8d depends: Decouple toolchain + binutils (Carl Dong) Pull request description: This replaces: #17099 ----- This patchset allows us to force depends to use system clang. Previously, #17099 removes our dependency on a specific clang we download from llvm.org, but theuni pointed out that since OSX builds are only ever built with a version of clang that is chosen and "blessed" by Apple, it is more likely that the user will encounter problems if they use their system clang. This patchset forces the user to set `FORCE_USE_SYSTEM_CLANG=1` in order to use their system clang (when they know what they're doing) ACKs for top commit: theuni: ACK de4fedb. Tree-SHA512: 8774121e035f90c27030bcce06e1b79f7729b5e17802c718e49652ab06e19780632db974df47423c1d1b04f1ab1b7a763554fb922fec05d1cd6445b26578be1d
2 parents 0f6900e + de4fedb commit 1148f3d

File tree

6 files changed

+121
-27
lines changed

6 files changed

+121
-27
lines changed

depends/Makefile

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ $(host_arch)_$(host_os)_id_string+=$(shell $(host_CXX) --version 2>/dev/null)
125125
$(host_arch)_$(host_os)_id_string+=$(shell $(host_RANLIB) --version 2>/dev/null)
126126
$(host_arch)_$(host_os)_id_string+=$(shell $(host_STRIP) --version 2>/dev/null)
127127

128+
ifneq ($(strip $(FORCE_USE_SYSTEM_CLANG)),)
129+
build_id_string+=system_clang
130+
$(host_arch)_$(host_os)_id_string+=system_clang
131+
endif
132+
128133
qrencode_packages_$(NO_QR) = $(qrencode_packages)
129134

130135
qt_packages_$(NO_QT) = $(qt_packages) $(qt_$(host_os)_packages) $(qt_$(host_arch)_$(host_os)_packages) $(qrencode_packages_)
@@ -150,11 +155,17 @@ all_packages = $(packages) $(native_packages)
150155

151156
meta_depends = Makefile funcs.mk builders/default.mk hosts/default.mk hosts/$(host_os).mk builders/$(build_os).mk
152157

158+
$(host_arch)_$(host_os)_native_binutils?=$($(host_os)_native_binutils)
153159
$(host_arch)_$(host_os)_native_toolchain?=$($(host_os)_native_toolchain)
154160

155161
include funcs.mk
156162

163+
binutils_path=$($($(host_arch)_$(host_os)_native_binutils)_prefixbin)
164+
ifeq ($(strip $(FORCE_USE_SYSTEM_CLANG)),)
157165
toolchain_path=$($($(host_arch)_$(host_os)_native_toolchain)_prefixbin)
166+
else
167+
toolchain_path=
168+
endif
158169
final_build_id_long+=$(shell $(build_SHA256SUM) config.site.in)
159170
final_build_id+=$(shell echo -n "$(final_build_id_long)" | $(build_SHA256SUM) | cut -c-$(HASH_LENGTH))
160171
$(host_prefix)/.stamp_$(final_build_id): $(native_packages) $(packages)
@@ -170,10 +181,10 @@ $(host_prefix)/share/config.site : config.site.in $(host_prefix)/.stamp_$(final_
170181
$(AT)sed -e 's|@HOST@|$(host)|' \
171182
-e 's|@CC@|$(toolchain_path)$(host_CC)|' \
172183
-e 's|@CXX@|$(toolchain_path)$(host_CXX)|' \
173-
-e 's|@AR@|$(toolchain_path)$(host_AR)|' \
174-
-e 's|@RANLIB@|$(toolchain_path)$(host_RANLIB)|' \
175-
-e 's|@NM@|$(toolchain_path)$(host_NM)|' \
176-
-e 's|@STRIP@|$(toolchain_path)$(host_STRIP)|' \
184+
-e 's|@AR@|$(binutils_path)$(host_AR)|' \
185+
-e 's|@RANLIB@|$(binutils_path)$(host_RANLIB)|' \
186+
-e 's|@NM@|$(binutils_path)$(host_NM)|' \
187+
-e 's|@STRIP@|$(binutils_path)$(host_STRIP)|' \
177188
-e 's|@build_os@|$(build_os)|' \
178189
-e 's|@host_os@|$(host_os)|' \
179190
-e 's|@CFLAGS@|$(strip $(host_CFLAGS) $(host_$(release_type)_CFLAGS))|' \

depends/README.md

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,40 @@ For linux S390X cross compilation:
8080
sudo apt-get install g++-s390x-linux-gnu binutils-s390x-linux-gnu
8181

8282
### Dependency Options
83-
The following can be set when running make: make FOO=bar
84-
85-
SOURCES_PATH: downloaded sources will be placed here
86-
BASE_CACHE: built packages will be placed here
87-
SDK_PATH: Path where sdk's can be found (used by macOS)
88-
FALLBACK_DOWNLOAD_PATH: If a source file can't be fetched, try here before giving up
89-
NO_QT: Don't download/build/cache qt and its dependencies
90-
NO_QR: Don't download/build/cache packages needed for enabling qrencode
91-
NO_ZMQ: Don't download/build/cache packages needed for enabling zeromq
92-
NO_WALLET: Don't download/build/cache libs needed to enable the wallet
93-
NO_UPNP: Don't download/build/cache packages needed for enabling upnp
94-
MULTIPROCESS: build libmultiprocess (experimental, requires cmake)
95-
DEBUG: disable some optimizations and enable more runtime checking
96-
HOST_ID_SALT: Optional salt to use when generating host package ids
97-
BUILD_ID_SALT: Optional salt to use when generating build package ids
83+
The following can be set when running make: `make FOO=bar`
84+
85+
<dl>
86+
<dt>SOURCES_PATH</dt>
87+
<dd>downloaded sources will be placed here</dd>
88+
<dt>BASE_CACHE</dt>
89+
<dd>built packages will be placed here</dd>
90+
<dt>SDK_PATH</dt>
91+
<dd>Path where sdk's can be found (used by macOS)</dd>
92+
<dt>FALLBACK_DOWNLOAD_PATH</dt>
93+
<dd>If a source file can't be fetched, try here before giving up</dd>
94+
<dt>NO_QT</dt>
95+
<dd>Don't download/build/cache qt and its dependencies</dd>
96+
<dt>NO_QR</dt>
97+
<dd>Don't download/build/cache packages needed for enabling qrencode</dd>
98+
<dt>NO_ZMQ</dt>
99+
<dd>Don't download/build/cache packages needed for enabling zeromq</dd>
100+
<dt>NO_WALLET</dt>
101+
<dd>Don't download/build/cache libs needed to enable the wallet</dd>
102+
<dt>NO_UPNP</dt>
103+
<dd>Don't download/build/cache packages needed for enabling upnp</dd>
104+
<dt>MULTIPROCESS</dt>
105+
<dd>build libmultiprocess (experimental, requires cmake)</dd>
106+
<dt>DEBUG</dt>
107+
<dd>disable some optimizations and enable more runtime checking</dd>
108+
<dt>HOST_ID_SALT</dt>
109+
<dd>Optional salt to use when generating host package ids</dd>
110+
<dt>BUILD_ID_SALT</dt>
111+
<dd>Optional salt to use when generating build package ids</dd>
112+
<dt>FORCE_USE_SYSTEM_CLANG</dt>
113+
<dd>(EXPERTS ONLY) When cross-compiling for macOS, use clang found in the
114+
system's <code>$PATH</code> rather than the default prebuilt release of clang
115+
from llvm.org</dd>
116+
</dl>
98117

99118
If some packages are not built, for example `make NO_WALLET=1`, the appropriate
100119
options will be passed to bitcoin's configure. In this case, `--disable-wallet`.

depends/builders/darwin.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ darwin_LIBTOOL:=$(shell xcrun -f libtool)
1919
darwin_OTOOL:=$(shell xcrun -f otool)
2020
darwin_NM:=$(shell xcrun -f nm)
2121
darwin_INSTALL_NAME_TOOL:=$(shell xcrun -f install_name_tool)
22+
darwin_native_binutils=
2223
darwin_native_toolchain=

depends/funcs.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ endef
4141

4242
define int_get_build_id
4343
$(eval $(1)_dependencies += $($(1)_$(host_arch)_$(host_os)_dependencies) $($(1)_$(host_os)_dependencies))
44-
$(eval $(1)_all_dependencies:=$(call int_get_all_dependencies,$(1),$($($(1)_type)_native_toolchain) $($(1)_dependencies)))
44+
$(eval $(1)_all_dependencies:=$(call int_get_all_dependencies,$(1),$($($(1)_type)_native_toolchain) $($($(1)_type)_native_binutils) $($(1)_dependencies)))
4545
$(foreach dep,$($(1)_all_dependencies),$(eval $(1)_build_id_deps+=$(dep)-$($(dep)_version)-$($(dep)_recipe_hash)))
4646
$(eval $(1)_build_id_long:=$(1)-$($(1)_version)-$($(1)_recipe_hash)-$(release_type) $($(1)_build_id_deps) $($($(1)_type)_id_string))
4747
$(eval $(1)_build_id:=$(shell echo -n "$($(1)_build_id_long)" | $(build_SHA256SUM) | cut -c-$(HASH_LENGTH)))
@@ -260,4 +260,4 @@ $(foreach package,$(all_packages),$(eval $(call int_config_attach_build_config,$
260260
$(foreach package,$(all_packages),$(eval $(call int_add_cmds,$(package))))
261261

262262
#special exception: if a toolchain package exists, all non-native packages depend on it
263-
$(foreach package,$(packages),$(eval $($(package)_unpacked): |$($($(host_arch)_$(host_os)_native_toolchain)_cached) ))
263+
$(foreach package,$(packages),$(eval $($(package)_unpacked): |$($($(host_arch)_$(host_os)_native_toolchain)_cached) $($($(host_arch)_$(host_os)_native_binutils)_cached) ))

depends/hosts/darwin.mk

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,30 @@ LD64_VERSION=530
66

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

9-
# When cross-compiling for Darwin using Clang, -mlinker-version must be passed to
10-
# ensure that modern linker features are enabled.
11-
darwin_CC=clang -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION)
12-
darwin_CXX=clang++ -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -stdlib=libc++ -mlinker-version=$(LD64_VERSION)
9+
# Flag explanations:
10+
#
11+
# -mlinker-version
12+
#
13+
# Ensures that modern linker features are enabled. See here for more
14+
# details: https://github.com/bitcoin/bitcoin/pull/19407.
15+
#
16+
# -B$(build_prefix)/bin
17+
#
18+
# Explicitly point to our binaries (e.g. cctools) so that they are
19+
# ensured to be found and preferred over other possibilities.
20+
#
21+
# -nostdinc++ -isystem $(OSX_SDK)/usr/include/c++/v1
22+
#
23+
# Forces clang to use the libc++ headers from our SDK and completely
24+
# forget about the libc++ headers from the standard directories
25+
#
26+
# TODO: Once we start requiring a clang version that has the
27+
# -stdlib++-isystem<directory> flag first introduced here:
28+
# https://reviews.llvm.org/D64089, we should use that instead. Read the
29+
# differential summary there for more details.
30+
#
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
1333

1434
darwin_CFLAGS=-pipe
1535
darwin_CXXFLAGS=$(darwin_CFLAGS)
@@ -20,5 +40,11 @@ darwin_release_CXXFLAGS=$(darwin_release_CFLAGS)
2040
darwin_debug_CFLAGS=-O1
2141
darwin_debug_CXXFLAGS=$(darwin_debug_CFLAGS)
2242

43+
darwin_native_binutils=native_cctools
44+
ifeq ($(strip $(FORCE_USE_SYSTEM_CLANG)),)
2345
darwin_native_toolchain=native_cctools
46+
else
47+
darwin_native_toolchain=
48+
endif
49+
2450
darwin_cmake_system=Darwin

depends/packages/native_cctools.mk

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,39 @@ $(package)_download_path=https://github.com/tpoechtrager/cctools-port/archive
44
$(package)_file_name=$($(package)_version).tar.gz
55
$(package)_sha256_hash=a2d491c0981cef72fee2b833598f20f42a6c44a7614a61c439bda93d56446fec
66
$(package)_build_subdir=cctools
7+
ifeq ($(strip $(FORCE_USE_SYSTEM_CLANG)),)
78
$(package)_clang_version=8.0.0
89
$(package)_clang_download_path=https://releases.llvm.org/$($(package)_clang_version)
910
$(package)_clang_download_file=clang+llvm-$($(package)_clang_version)-x86_64-linux-gnu-ubuntu-14.04.tar.xz
1011
$(package)_clang_file_name=clang-llvm-$($(package)_clang_version)-x86_64-linux-gnu-ubuntu-14.04.tar.xz
1112
$(package)_clang_sha256_hash=9ef854b71949f825362a119bf2597f744836cb571131ae6b721cd102ffea8cd0
13+
endif
1214

1315
$(package)_libtapi_version=3efb201881e7a76a21e0554906cf306432539cef
1416
$(package)_libtapi_download_path=https://github.com/tpoechtrager/apple-libtapi/archive
1517
$(package)_libtapi_download_file=$($(package)_libtapi_version).tar.gz
1618
$(package)_libtapi_file_name=$($(package)_libtapi_version).tar.gz
1719
$(package)_libtapi_sha256_hash=380c1ca37cfa04a8699d0887a8d3ee1ad27f3d08baba78887c73b09485c0fbd3
1820

19-
$(package)_extra_sources=$($(package)_clang_file_name)
20-
$(package)_extra_sources += $($(package)_libtapi_file_name)
21+
$(package)_extra_sources=$($(package)_libtapi_file_name)
22+
ifeq ($(strip $(FORCE_USE_SYSTEM_CLANG)),)
23+
$(package)_extra_sources += $($(package)_clang_file_name)
24+
endif
2125

26+
ifeq ($(strip $(FORCE_USE_SYSTEM_CLANG)),)
2227
define $(package)_fetch_cmds
2328
$(call fetch_file,$(package),$($(package)_download_path),$($(package)_download_file),$($(package)_file_name),$($(package)_sha256_hash)) && \
2429
$(call fetch_file,$(package),$($(package)_clang_download_path),$($(package)_clang_download_file),$($(package)_clang_file_name),$($(package)_clang_sha256_hash)) && \
2530
$(call fetch_file,$(package),$($(package)_libtapi_download_path),$($(package)_libtapi_download_file),$($(package)_libtapi_file_name),$($(package)_libtapi_sha256_hash))
2631
endef
32+
else
33+
define $(package)_fetch_cmds
34+
$(call fetch_file,$(package),$($(package)_download_path),$($(package)_download_file),$($(package)_file_name),$($(package)_sha256_hash)) && \
35+
$(call fetch_file,$(package),$($(package)_libtapi_download_path),$($(package)_libtapi_download_file),$($(package)_libtapi_file_name),$($(package)_libtapi_sha256_hash))
36+
endef
37+
endif
2738

39+
ifeq ($(strip $(FORCE_USE_SYSTEM_CLANG)),)
2840
define $(package)_extract_cmds
2941
mkdir -p $($(package)_extract_dir) && \
3042
echo "$($(package)_sha256_hash) $($(package)_source)" > $($(package)_extract_dir)/.$($(package)_file_name).hash && \
@@ -38,12 +50,28 @@ define $(package)_extract_cmds
3850
rm -f toolchain/lib/libc++abi.so* && \
3951
tar --no-same-owner --strip-components=1 -xf $($(package)_source)
4052
endef
53+
else
54+
define $(package)_extract_cmds
55+
mkdir -p $($(package)_extract_dir) && \
56+
echo "$($(package)_sha256_hash) $($(package)_source)" > $($(package)_extract_dir)/.$($(package)_file_name).hash && \
57+
echo "$($(package)_libtapi_sha256_hash) $($(package)_source_dir)/$($(package)_libtapi_file_name)" >> $($(package)_extract_dir)/.$($(package)_file_name).hash && \
58+
$(build_SHA256SUM) -c $($(package)_extract_dir)/.$($(package)_file_name).hash && \
59+
mkdir -p libtapi && \
60+
tar --no-same-owner --strip-components=1 -C libtapi -xf $($(package)_source_dir)/$($(package)_libtapi_file_name) && \
61+
tar --no-same-owner --strip-components=1 -xf $($(package)_source)
62+
endef
63+
endif
4164

4265
define $(package)_set_vars
4366
$(package)_config_opts=--target=$(host) --disable-lto-support --with-libtapi=$($(package)_extract_dir)
4467
$(package)_ldflags+=-Wl,-rpath=\\$$$$$$$$\$$$$$$$$ORIGIN/../lib
68+
ifeq ($(strip $(FORCE_USE_SYSTEM_CLANG)),)
4569
$(package)_cc=$($(package)_extract_dir)/toolchain/bin/clang
4670
$(package)_cxx=$($(package)_extract_dir)/toolchain/bin/clang++
71+
else
72+
$(package)_cc=clang
73+
$(package)_cxx=clang++
74+
endif
4775
endef
4876

4977
define $(package)_preprocess_cmds
@@ -60,6 +88,7 @@ define $(package)_build_cmds
6088
$(MAKE)
6189
endef
6290

91+
ifeq ($(strip $(FORCE_USE_SYSTEM_CLANG)),)
6392
define $(package)_stage_cmds
6493
$(MAKE) DESTDIR=$($(package)_staging_dir) install && \
6594
mkdir -p $($(package)_staging_prefix_dir)/lib/ && \
@@ -74,3 +103,11 @@ define $(package)_stage_cmds
74103
cp -rf lib/clang/$($(package)_clang_version)/include/* $($(package)_staging_prefix_dir)/lib/clang/$($(package)_clang_version)/include/ && \
75104
cp bin/dsymutil $($(package)_staging_prefix_dir)/bin/$(host)-dsymutil
76105
endef
106+
else
107+
define $(package)_stage_cmds
108+
$(MAKE) DESTDIR=$($(package)_staging_dir) install && \
109+
mkdir -p $($(package)_staging_prefix_dir)/lib/ && \
110+
cd $($(package)_extract_dir) && \
111+
cp lib/libtapi.so.6 $($(package)_staging_prefix_dir)/lib/
112+
endef
113+
endif

0 commit comments

Comments
 (0)