Skip to content

Commit c9eb4cf

Browse files
committed
guix: Add support for darwin builds
1 parent 37fe73a commit c9eb4cf

File tree

3 files changed

+137
-32
lines changed

3 files changed

+137
-32
lines changed

contrib/guix/guix-build.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ fi
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,6 +106,7 @@ for host in $hosts_distsrc_exists; do
105106
done
106107
exit 1
107108
else
109+
108110
mkdir -p "$DISTSRC_BASE"
109111
fi
110112

contrib/guix/libexec/build.sh

Lines changed: 102 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
@@ -135,7 +169,8 @@ make -C depends --jobs="$MAX_JOBS" HOST="$HOST" \
135169
x86_64_linux_RANLIB=x86_64-linux-gnu-ranlib \
136170
x86_64_linux_NM=x86_64-linux-gnu-nm \
137171
x86_64_linux_STRIP=x86_64-linux-gnu-strip \
138-
qt_config_opts_i686_linux='-platform linux-g++ -xplatform bitcoin-linux-g++'
172+
qt_config_opts_i686_linux='-platform linux-g++ -xplatform bitcoin-linux-g++' \
173+
FORCE_USE_SYSTEM_CLANG=1
139174

140175

141176
###########################
@@ -169,6 +204,7 @@ HOST_CFLAGS="-O2 -g"
169204
case "$HOST" in
170205
*linux*) HOST_CFLAGS+=" -ffile-prefix-map=${PWD}=." ;;
171206
*mingw*) HOST_CFLAGS+=" -fno-ident" ;;
207+
*darwin*) unset HOST_CFLAGS ;;
172208
esac
173209

174210
# CXXFLAGS
@@ -199,8 +235,8 @@ mkdir -p "$DISTSRC"
199235
--disable-maintainer-mode \
200236
--disable-dependency-tracking \
201237
${CONFIGFLAGS} \
202-
CFLAGS="${HOST_CFLAGS}" \
203-
CXXFLAGS="${HOST_CXXFLAGS}" \
238+
${HOST_CFLAGS:+CFLAGS="${HOST_CFLAGS}"} \
239+
${HOST_CXXFLAGS:+CXXFLAGS="${HOST_CXXFLAGS}"} \
204240
${HOST_LDFLAGS:+LDFLAGS="${HOST_LDFLAGS}"}
205241

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

211247
# Perform basic ELF security checks on a series of executables.
212248
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
249+
# Check that executables only contain allowed gcc, glibc and libstdc++
250+
# version symbols for Linux distro back-compatibility.
251+
make -C src --jobs=1 check-symbols ${V:+V=1}
221252

222253
# Make the os-specific installers
223254
case "$HOST" in
@@ -232,8 +263,39 @@ mkdir -p "$DISTSRC"
232263
INSTALLPATH="${PWD}/installed/${DISTNAME}"
233264
mkdir -p "${INSTALLPATH}"
234265
# Install built Bitcoin Core to $INSTALLPATH
235-
make install DESTDIR="${INSTALLPATH}" ${V:+V=1}
266+
case "$HOST" in
267+
*darwin*)
268+
make install-strip DESTDIR="${INSTALLPATH}" ${V:+V=1}
269+
;;
270+
*)
271+
make install DESTDIR="${INSTALLPATH}" ${V:+V=1}
272+
;;
273+
esac
236274

275+
case "$HOST" in
276+
*darwin*)
277+
make osx_volname ${V:+V=1}
278+
make deploydir ${V:+V=1}
279+
mkdir -p "unsigned-app-${HOST}"
280+
cp --target-directory="unsigned-app-${HOST}" \
281+
osx_volname \
282+
contrib/macdeploy/detached-sig-{apply,create}.sh \
283+
"${BASEPREFIX}/${HOST}"/native/bin/dmg
284+
for util in codesign_allocate pagestuff; do
285+
cp --no-target-directory {"${BASEPREFIX}/${HOST}/native/bin/${HOST}-","unsigned-app-${HOST}/"}"$util"
286+
done
287+
mv --target-directory="unsigned-app-${HOST}" dist
288+
(
289+
cd "unsigned-app-${HOST}"
290+
find . -print0 \
291+
| sort --zero-terminated \
292+
| tar --create --no-recursion --mode='u+rw,go+r-w,a+X' --null --files-from=- \
293+
| gzip -9n > "${OUTDIR}/${DISTNAME}-osx-unsigned.tar.gz" \
294+
|| ( rm -f "${OUTDIR}/${DISTNAME}-osx-unsigned.tar.gz" && exit 1 )
295+
)
296+
make deploy ${V:+V=1} OSX_DMG="${OUTDIR}/${DISTNAME}-osx-unsigned.dmg"
297+
;;
298+
esac
237299
(
238300
cd installed
239301

@@ -248,13 +310,18 @@ mkdir -p "$DISTSRC"
248310
find . -name "lib*.a" -delete
249311

250312
# Prune pkg-config files
251-
rm -r "${DISTNAME}/lib/pkgconfig"
313+
rm -rf "${DISTNAME}/lib/pkgconfig"
252314

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
315+
case "$HOST" in
316+
*darwin*) ;;
317+
*)
318+
# Split binaries and libraries from their debug symbols
319+
{
320+
find "${DISTNAME}/bin" -type f -executable -print0
321+
find "${DISTNAME}/lib" -type f -print0
322+
} | xargs -0 -n1 -P"$MAX_JOBS" -I{} "${DISTSRC}/contrib/devtools/split-debug.sh" {} {} {}.dbg
323+
;;
324+
esac
258325

259326
case "$HOST" in
260327
*mingw*)
@@ -294,6 +361,13 @@ mkdir -p "$DISTSRC"
294361
| gzip -9n > "${OUTDIR}/${DISTNAME}-${HOST}-debug.tar.gz" \
295362
|| ( rm -f "${OUTDIR}/${DISTNAME}-${HOST}-debug.tar.gz" && exit 1 )
296363
;;
364+
*darwin*)
365+
find "${DISTNAME}" -print0 \
366+
| sort --zero-terminated \
367+
| tar --create --no-recursion --mode='u+rw,go+r-w,a+X' --null --files-from=- \
368+
| gzip -9n > "${OUTDIR}/${DISTNAME}-${HOST//x86_64-apple-darwin18/osx64}.tar.gz" \
369+
|| ( rm -f "${OUTDIR}/${DISTNAME}-${HOST//x86_64-apple-darwin18/osx64}.tar.gz" && exit 1 )
370+
;;
297371
esac
298372
)
299373
)

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 '())))))

0 commit comments

Comments
 (0)