Skip to content

Commit 019aa24

Browse files
committed
Merge #17920: guix: Build support for macOS
f169475 guix: Fix typo (Carl Dong) 771c4b9 guix: README: Add darwin HOSTS entry (Carl Dong) 8dbf18c guix: Check for macOS SDK before building anything (Carl Dong) 34b23f5 guix: Set ZERO_AR_DATE for darwin build determinism (Carl Dong) f3835dc build: Make xorrisofs reproducible with -volume_date (Carl Dong) c9eb4cf guix: Add support for darwin builds (Carl Dong) 37fe73a build: Add var printing target to src/Makefile.am (Carl Dong) Pull request description: This PR brings our Guix builds on par with Gitian in terms of supported architectures. Reviewers: if you run a build, please submit: ``` find output/ -type f -print0 | env LC_ALL=C sort -z | xargs -r0 sha256sum ``` So that we can compare hashes and ensure reproducibility! ACKs for top commit: fanquake: ACK f169475 - I think we can make some small usability improvements, but this is ok to merge now. Tree-SHA512: 4af2b71654a9736467dcc681d10601c6eee37800d7847011a50585455b67b55d61742ca5604585f310a2fd75335b674e5e27dfb5169cb2f26e112aa4c411d8be
2 parents d6c3c43 + f169475 commit 019aa24

File tree

6 files changed

+173
-35
lines changed

6 files changed

+173
-35
lines changed

Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ $(APP_DIST_DIR)/Applications:
141141
$(APP_DIST_EXTRAS): $(APP_DIST_DIR)/$(OSX_APP)/Contents/MacOS/Bitcoin-Qt
142142

143143
$(OSX_TEMP_ISO): $(APP_DIST_EXTRAS)
144-
$(XORRISOFS) -D -l -V "$(OSX_VOLNAME)" -no-pad -r -dir-mode 0755 -o $@ dist
144+
$(XORRISOFS) -D -l -V "$(OSX_VOLNAME)" -no-pad -r -dir-mode 0755 -o $@ dist -- $(if $(SOURCE_DATE_EPOCH),-volume_date all_file_dates =$(SOURCE_DATE_EPOCH))
145145

146146
$(OSX_DMG): $(OSX_TEMP_ISO)
147147
$(DMG) dmg "$<" "$@"

contrib/guix/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ find output/ -type f -print0 | sort -z | xargs -r0 sha256sum
105105

106106
Override the space-separated list of platform triples for which to perform a
107107
bootstrappable build. _(defaults to "x86\_64-linux-gnu arm-linux-gnueabihf
108-
aarch64-linux-gnu riscv64-linux-gnu x86_64-w64-mingw32")_
108+
aarch64-linux-gnu riscv64-linux-gnu x86_64-w64-mingw32
109+
x86_64-apple-darwin18")_
109110

110111
* _**SOURCES_PATH**_
111112

contrib/guix/guix-build.sh

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,13 @@ else
6565
fi
6666

6767
################
68-
# Check 4: Make sure that build directories do no exist
68+
# Check 4: Make sure that build directories do not exist
6969
################
7070

7171
# Default to building for all supported HOSTs (overridable by environment)
7272
export HOSTS="${HOSTS:-x86_64-linux-gnu arm-linux-gnueabihf aarch64-linux-gnu riscv64-linux-gnu
73-
x86_64-w64-mingw32}"
73+
x86_64-w64-mingw32
74+
x86_64-apple-darwin18}"
7475

7576
DISTSRC_BASE="${DISTSRC_BASE:-${PWD}}"
7677

@@ -105,9 +106,28 @@ for host in $hosts_distsrc_exists; do
105106
done
106107
exit 1
107108
else
109+
108110
mkdir -p "$DISTSRC_BASE"
109111
fi
110112

113+
################
114+
# Check 5: When building for darwin, make sure that the macOS SDK exists
115+
################
116+
117+
for host in $HOSTS; do
118+
case "$host" in
119+
*darwin*)
120+
OSX_SDK="$(make -C "${PWD}/depends" --no-print-directory HOST="$host" print-OSX_SDK | sed 's@^[^=]\+=[[:space:]]\+@@g')"
121+
if [ -e "$OSX_SDK" ]; then
122+
echo "Found macOS SDK at '${OSX_SDK}', using..."
123+
else
124+
echo "macOS SDK does not exist at '${OSX_SDK}', please place the extracted, untarred SDK there to perform darwin builds, exiting..."
125+
exit 1
126+
fi
127+
;;
128+
esac
129+
done
130+
111131
#########
112132
# Setup #
113133
#########

contrib/guix/libexec/build.sh

Lines changed: 112 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,28 @@ store_path() {
3838
--expression='s|"[[:space:]]*$||'
3939
}
4040

41-
# Set environment variables to point Guix's cross-toolchain to the right
41+
42+
# Set environment variables to point the NATIVE toolchain to the right
43+
# includes/libs
44+
NATIVE_GCC="$(store_path gcc-toolchain)"
45+
export LIBRARY_PATH="${NATIVE_GCC}/lib:${NATIVE_GCC}/lib64"
46+
export CPATH="${NATIVE_GCC}/include"
47+
case "$HOST" in
48+
*darwin*)
49+
# When targeting darwin, some native tools built by depends require
50+
# native packages not incorporated in depends
51+
#
52+
# libcap required by native_cdrkit/wodim
53+
# zlib, bzip2 required by native_cdrkit/genisoimage
54+
for native_pkg in libcap zlib bzip2; do
55+
native_pkg_store_path=$(store_path "$native_pkg")
56+
export LIBRARY_PATH="${native_pkg_store_path}/lib:${LIBRARY_PATH}"
57+
export CPATH="${native_pkg_store_path}/include:${CPATH}"
58+
done
59+
;;
60+
esac
61+
62+
# Set environment variables to point the CROSS toolchain to the right
4263
# includes/libs for $HOST
4364
case "$HOST" in
4465
*mingw*)
@@ -48,14 +69,18 @@ case "$HOST" in
4869
CROSS_GCC_LIBS=( "${CROSS_GCC}/lib/gcc/${HOST}"/* ) # This expands to an array of directories...
4970
CROSS_GCC_LIB="${CROSS_GCC_LIBS[0]}" # ...we just want the first one (there should only be one)
5071

51-
NATIVE_GCC="$(store_path gcc-glibc-2.27-toolchain)"
52-
export LIBRARY_PATH="${NATIVE_GCC}/lib:${NATIVE_GCC}/lib64"
53-
export CPATH="${NATIVE_GCC}/include"
54-
72+
# The search path ordering is generally:
73+
# 1. gcc-related search paths
74+
# 2. libc-related search paths
75+
# 2. kernel-header-related search paths (not applicable to mingw-w64 hosts)
5576
export CROSS_C_INCLUDE_PATH="${CROSS_GCC_LIB}/include:${CROSS_GCC_LIB}/include-fixed:${CROSS_GLIBC}/include"
5677
export CROSS_CPLUS_INCLUDE_PATH="${CROSS_GCC}/include/c++:${CROSS_GCC}/include/c++/${HOST}:${CROSS_GCC}/include/c++/backward:${CROSS_C_INCLUDE_PATH}"
5778
export CROSS_LIBRARY_PATH="${CROSS_GCC}/lib:${CROSS_GCC}/${HOST}/lib:${CROSS_GCC_LIB}:${CROSS_GLIBC}/lib"
5879
;;
80+
*darwin*)
81+
# The CROSS toolchain for darwin uses the SDK and ignores environment variables.
82+
# See depends/hosts/darwin.mk for more details.
83+
;;
5984
*linux*)
6085
CROSS_GLIBC="$(store_path "glibc-cross-${HOST}")"
6186
CROSS_GLIBC_STATIC="$(store_path "glibc-cross-${HOST}" static)"
@@ -64,9 +89,7 @@ case "$HOST" in
6489
CROSS_GCC_LIBS=( "${CROSS_GCC}/lib/gcc/${HOST}"/* ) # This expands to an array of directories...
6590
CROSS_GCC_LIB="${CROSS_GCC_LIBS[0]}" # ...we just want the first one (there should only be one)
6691

67-
# NOTE: CROSS_C_INCLUDE_PATH is missing ${CROSS_GCC_LIB}/include-fixed, because
68-
# the limits.h in it is missing a '#include_next <limits.h>'
69-
export CROSS_C_INCLUDE_PATH="${CROSS_GCC_LIB}/include:${CROSS_GLIBC}/include:${CROSS_KERNEL}/include"
92+
export CROSS_C_INCLUDE_PATH="${CROSS_GCC_LIB}/include:${CROSS_GCC_LIB}/include-fixed:${CROSS_GLIBC}/include:${CROSS_KERNEL}/include"
7093
export CROSS_CPLUS_INCLUDE_PATH="${CROSS_GCC}/include/c++:${CROSS_GCC}/include/c++/${HOST}:${CROSS_GCC}/include/c++/backward:${CROSS_C_INCLUDE_PATH}"
7194
export CROSS_LIBRARY_PATH="${CROSS_GCC}/lib:${CROSS_GCC}/${HOST}/lib:${CROSS_GCC_LIB}:${CROSS_GLIBC}/lib:${CROSS_GLIBC_STATIC}/lib"
7295
;;
@@ -77,14 +100,25 @@ esac
77100
# Sanity check CROSS_*_PATH directories
78101
IFS=':' read -ra PATHS <<< "${CROSS_C_INCLUDE_PATH}:${CROSS_CPLUS_INCLUDE_PATH}:${CROSS_LIBRARY_PATH}"
79102
for p in "${PATHS[@]}"; do
80-
if [ ! -d "$p" ]; then
103+
if [ -n "$p" ] && [ ! -d "$p" ]; then
81104
echo "'$p' doesn't exist or isn't a directory... Aborting..."
82105
exit 1
83106
fi
84107
done
85108

86109
# Disable Guix ld auto-rpath behavior
87-
export GUIX_LD_WRAPPER_DISABLE_RPATH=yes
110+
case "$HOST" in
111+
*darwin*)
112+
# The auto-rpath behavior is necessary for darwin builds as some native
113+
# tools built by depends refer to and depend on Guix-built native
114+
# libraries
115+
#
116+
# After the native packages in depends are built, the ld wrapper should
117+
# no longer affect our build, as clang would instead reach for
118+
# x86_64-apple-darwin18-ld from cctools
119+
;;
120+
*) export GUIX_LD_WRAPPER_DISABLE_RPATH=yes ;;
121+
esac
88122

89123
# Make /usr/bin if it doesn't exist
90124
[ -e /usr/bin ] || mkdir -p /usr/bin
@@ -114,6 +148,16 @@ export QT_RCC_TEST=1
114148
export QT_RCC_SOURCE_DATE_OVERRIDE=1
115149
export TAR_OPTIONS="--owner=0 --group=0 --numeric-owner --mtime='@${SOURCE_DATE_EPOCH}' --sort=name"
116150
export TZ="UTC"
151+
case "$HOST" in
152+
*darwin*)
153+
# cctools AR, unlike GNU binutils AR, does not have a deterministic mode
154+
# or a configure flag to enable determinism by default, it only
155+
# understands if this env-var is set or not. See:
156+
#
157+
# https://github.com/tpoechtrager/cctools-port/blob/55562e4073dea0fbfd0b20e0bf69ffe6390c7f97/cctools/ar/archive.c#L334
158+
export ZERO_AR_DATE=yes
159+
;;
160+
esac
117161

118162
####################
119163
# Depends Building #
@@ -135,7 +179,8 @@ make -C depends --jobs="$MAX_JOBS" HOST="$HOST" \
135179
x86_64_linux_RANLIB=x86_64-linux-gnu-ranlib \
136180
x86_64_linux_NM=x86_64-linux-gnu-nm \
137181
x86_64_linux_STRIP=x86_64-linux-gnu-strip \
138-
qt_config_opts_i686_linux='-platform linux-g++ -xplatform bitcoin-linux-g++'
182+
qt_config_opts_i686_linux='-platform linux-g++ -xplatform bitcoin-linux-g++' \
183+
FORCE_USE_SYSTEM_CLANG=1
139184

140185

141186
###########################
@@ -169,6 +214,7 @@ HOST_CFLAGS="-O2 -g"
169214
case "$HOST" in
170215
*linux*) HOST_CFLAGS+=" -ffile-prefix-map=${PWD}=." ;;
171216
*mingw*) HOST_CFLAGS+=" -fno-ident" ;;
217+
*darwin*) unset HOST_CFLAGS ;;
172218
esac
173219

174220
# CXXFLAGS
@@ -199,8 +245,8 @@ mkdir -p "$DISTSRC"
199245
--disable-maintainer-mode \
200246
--disable-dependency-tracking \
201247
${CONFIGFLAGS} \
202-
CFLAGS="${HOST_CFLAGS}" \
203-
CXXFLAGS="${HOST_CXXFLAGS}" \
248+
${HOST_CFLAGS:+CFLAGS="${HOST_CFLAGS}"} \
249+
${HOST_CXXFLAGS:+CXXFLAGS="${HOST_CXXFLAGS}"} \
204250
${HOST_LDFLAGS:+LDFLAGS="${HOST_LDFLAGS}"}
205251

206252
sed -i.old 's/-lstdc++ //g' config.status libtool src/univalue/config.status src/univalue/libtool
@@ -210,14 +256,9 @@ mkdir -p "$DISTSRC"
210256

211257
# Perform basic ELF security checks on a series of executables.
212258
make -C src --jobs=1 check-security ${V:+V=1}
213-
214-
case "$HOST" in
215-
*linux*|*mingw*)
216-
# Check that executables only contain allowed gcc, glibc and libstdc++
217-
# version symbols for Linux distro back-compatibility.
218-
make -C src --jobs=1 check-symbols ${V:+V=1}
219-
;;
220-
esac
259+
# Check that executables only contain allowed gcc, glibc and libstdc++
260+
# version symbols for Linux distro back-compatibility.
261+
make -C src --jobs=1 check-symbols ${V:+V=1}
221262

222263
# Make the os-specific installers
223264
case "$HOST" in
@@ -232,8 +273,39 @@ mkdir -p "$DISTSRC"
232273
INSTALLPATH="${PWD}/installed/${DISTNAME}"
233274
mkdir -p "${INSTALLPATH}"
234275
# Install built Bitcoin Core to $INSTALLPATH
235-
make install DESTDIR="${INSTALLPATH}" ${V:+V=1}
276+
case "$HOST" in
277+
*darwin*)
278+
make install-strip DESTDIR="${INSTALLPATH}" ${V:+V=1}
279+
;;
280+
*)
281+
make install DESTDIR="${INSTALLPATH}" ${V:+V=1}
282+
;;
283+
esac
236284

285+
case "$HOST" in
286+
*darwin*)
287+
make osx_volname ${V:+V=1}
288+
make deploydir ${V:+V=1}
289+
mkdir -p "unsigned-app-${HOST}"
290+
cp --target-directory="unsigned-app-${HOST}" \
291+
osx_volname \
292+
contrib/macdeploy/detached-sig-{apply,create}.sh \
293+
"${BASEPREFIX}/${HOST}"/native/bin/dmg
294+
for util in codesign_allocate pagestuff; do
295+
cp --no-target-directory {"${BASEPREFIX}/${HOST}/native/bin/${HOST}-","unsigned-app-${HOST}/"}"$util"
296+
done
297+
mv --target-directory="unsigned-app-${HOST}" dist
298+
(
299+
cd "unsigned-app-${HOST}"
300+
find . -print0 \
301+
| sort --zero-terminated \
302+
| tar --create --no-recursion --mode='u+rw,go+r-w,a+X' --null --files-from=- \
303+
| gzip -9n > "${OUTDIR}/${DISTNAME}-osx-unsigned.tar.gz" \
304+
|| ( rm -f "${OUTDIR}/${DISTNAME}-osx-unsigned.tar.gz" && exit 1 )
305+
)
306+
make deploy ${V:+V=1} OSX_DMG="${OUTDIR}/${DISTNAME}-osx-unsigned.dmg"
307+
;;
308+
esac
237309
(
238310
cd installed
239311

@@ -248,13 +320,18 @@ mkdir -p "$DISTSRC"
248320
find . -name "lib*.a" -delete
249321

250322
# Prune pkg-config files
251-
rm -r "${DISTNAME}/lib/pkgconfig"
323+
rm -rf "${DISTNAME}/lib/pkgconfig"
252324

253-
# Split binaries and libraries from their debug symbols
254-
{
255-
find "${DISTNAME}/bin" -type f -executable -print0
256-
find "${DISTNAME}/lib" -type f -print0
257-
} | xargs -0 -n1 -P"$MAX_JOBS" -I{} "${DISTSRC}/contrib/devtools/split-debug.sh" {} {} {}.dbg
325+
case "$HOST" in
326+
*darwin*) ;;
327+
*)
328+
# Split binaries and libraries from their debug symbols
329+
{
330+
find "${DISTNAME}/bin" -type f -executable -print0
331+
find "${DISTNAME}/lib" -type f -print0
332+
} | xargs -0 -n1 -P"$MAX_JOBS" -I{} "${DISTSRC}/contrib/devtools/split-debug.sh" {} {} {}.dbg
333+
;;
334+
esac
258335

259336
case "$HOST" in
260337
*mingw*)
@@ -294,6 +371,13 @@ mkdir -p "$DISTSRC"
294371
| gzip -9n > "${OUTDIR}/${DISTNAME}-${HOST}-debug.tar.gz" \
295372
|| ( rm -f "${OUTDIR}/${DISTNAME}-${HOST}-debug.tar.gz" && exit 1 )
296373
;;
374+
*darwin*)
375+
find "${DISTNAME}" -print0 \
376+
| sort --zero-terminated \
377+
| tar --create --no-recursion --mode='u+rw,go+r-w,a+X' --null --files-from=- \
378+
| gzip -9n > "${OUTDIR}/${DISTNAME}-${HOST//x86_64-apple-darwin18/osx64}.tar.gz" \
379+
|| ( rm -f "${OUTDIR}/${DISTNAME}-${HOST//x86_64-apple-darwin18/osx64}.tar.gz" && exit 1 )
380+
;;
297381
esac
298382
)
299383
)

contrib/guix/manifest.scm

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,33 @@
33
(gnu packages autotools)
44
(gnu packages base)
55
(gnu packages bash)
6+
(gnu packages cdrom)
67
(gnu packages check)
8+
(gnu packages cmake)
79
(gnu packages commencement)
810
(gnu packages compression)
911
(gnu packages cross-base)
1012
(gnu packages file)
1113
(gnu packages gawk)
1214
(gnu packages gcc)
15+
(gnu packages gnome)
16+
(gnu packages image)
17+
(gnu packages imagemagick)
1318
(gnu packages installers)
1419
(gnu packages linux)
20+
(gnu packages llvm)
1521
(gnu packages mingw)
1622
(gnu packages perl)
1723
(gnu packages pkg-config)
1824
(gnu packages python)
1925
(gnu packages shells)
2026
(gnu packages version-control)
27+
(guix build-system font)
2128
(guix build-system gnu)
2229
(guix build-system trivial)
30+
(guix download)
2331
(guix gexp)
32+
((guix licenses) #:prefix license:)
2433
(guix packages)
2534
(guix profiles)
2635
(guix utils))
@@ -161,11 +170,29 @@ chain for " target " development."))
161170
(package-with-extra-patches base-nsis
162171
(search-our-patches "nsis-SConstruct-sde-support.patch")))
163172

173+
(define-public font-tuffy
174+
(package
175+
(name "font-tuffy")
176+
(version "20120614")
177+
(source
178+
(origin
179+
(method url-fetch)
180+
(uri (string-append "http://tulrich.com/fonts/tuffy-" version ".tar.gz"))
181+
(file-name (string-append name "-" version ".tar.gz"))
182+
(sha256
183+
(base32
184+
"02vf72bgrp30vrbfhxjw82s115z27dwfgnmmzfb0n9wfhxxfpyf6"))))
185+
(build-system font-build-system)
186+
(home-page "http://tulrich.com/fonts/")
187+
(synopsis "The Tuffy Truetype Font Family")
188+
(description
189+
"Thatcher Ulrich's first outline font design. He started with the goal of producing a neutral, readable sans-serif text font. There are lots of \"expressive\" fonts out there, but he wanted to start with something very plain and clean, something he might want to actually use. ")
190+
(license license:public-domain)))
164191

165192
(packages->manifest
166193
(append
167194
(list ;; The Basics
168-
bash-minimal
195+
bash
169196
which
170197
coreutils
171198
util-linux
@@ -195,8 +222,8 @@ chain for " target " development."))
195222
python-3.7
196223
;; Git
197224
git
198-
;; Native gcc 9 toolchain targeting glibc 2.27
199-
(make-gcc-toolchain gcc-9 glibc-2.27))
225+
;; Native gcc 7 toolchain
226+
gcc-toolchain-7)
200227
(let ((target (getenv "HOST")))
201228
(cond ((string-suffix? "-mingw32" target)
202229
;; Windows
@@ -208,4 +235,6 @@ chain for " target " development."))
208235
#:base-gcc-for-libc gcc-7)))
209236
((string-contains target "-linux-")
210237
(list (make-bitcoin-cross-toolchain target)))
238+
((string-contains target "darwin")
239+
(list clang-8 libcap binutils imagemagick libtiff librsvg font-tuffy cmake-3.15.5 xorriso))
211240
(else '())))))

src/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
# Distributed under the MIT software license, see the accompanying
33
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
# Pattern rule to print variables, e.g. make print-top_srcdir
6+
print-%:
7+
@echo $* = $($*)
8+
59
DIST_SUBDIRS = secp256k1 univalue
610

711
AM_LDFLAGS = $(LIBTOOL_LDFLAGS) $(HARDENED_LDFLAGS) $(GPROF_LDFLAGS) $(SANITIZER_LDFLAGS)

0 commit comments

Comments
 (0)