manifest_build.scm raw
1 (use-modules (gnu packages)
2 ((gnu packages bash) #:select (bash-minimal))
3 (gnu packages bison)
4 ((gnu packages cmake) #:select (cmake-minimal))
5 (gnu packages commencement)
6 ((gnu packages compression) #:select (gzip xz zip))
7 (gnu packages cross-base)
8 (gnu packages gawk)
9 (gnu packages gcc)
10 ((gnu packages installers) #:select (nsis-x86_64))
11 ((gnu packages linux) #:select (linux-libre-headers-6.1))
12 (gnu packages llvm)
13 (gnu packages mingw)
14 (gnu packages ninja)
15 (gnu packages pkg-config)
16 ((gnu packages python) #:select (python-minimal))
17 ((gnu packages python-xyz) #:select (python-lief))
18 ((gnu packages version-control) #:select (git-minimal))
19 (guix build-system trivial)
20 (guix download)
21 (guix gexp)
22 (guix git-download)
23 ((guix licenses) #:prefix license:)
24 (guix packages)
25 ((guix utils) #:select (substitute-keyword-arguments)))
26
27 (define-syntax-rule (search-our-patches file-name ...)
28 "Return the list of absolute file names corresponding to each
29 FILE-NAME found in ./patches relative to the current file."
30 (parameterize
31 ((%patch-path (list (string-append (dirname (current-filename)) "/patches"))))
32 (list (search-patch file-name) ...)))
33
34 (define building-on (string-append "--build=" (list-ref (string-split (%current-system) #\-) 0) "-guix-linux-gnu"))
35
36 (define (base-binutils target)
37 (package
38 (inherit (cross-binutils target)) ;; 2.44
39 (version "2.46.0")
40 (source (origin
41 (method url-fetch)
42 (uri (string-append "mirror://gnu/binutils/binutils-"
43 version ".tar.bz2"))
44 (sha256
45 (base32
46 "04nd9vl7c1pxjbc9wh3ckddzhz5g82xyjqq9y9kf171a59im4c8g"))))
47 (arguments
48 (substitute-keyword-arguments (package-arguments (cross-binutils target))
49 ((#:configure-flags flags)
50 #~(append #$flags
51 (list "--enable-gprofng=no")))))
52 (native-inputs
53 (modify-inputs
54 (package-native-inputs (cross-binutils target))
55 (delete "bison")))
56 )
57 )
58
59 (define (make-cross-toolchain target
60 base-gcc-for-libc
61 base-kernel-headers
62 base-libc
63 base-gcc)
64 "Create a cross-compilation toolchain package for TARGET"
65 (let* ((xbinutils (base-binutils target))
66 ;; 1. Build a cross-compiling gcc without targeting any libc, derived
67 ;; from BASE-GCC-FOR-LIBC
68 (xgcc-sans-libc (cross-gcc target
69 #:xgcc base-gcc-for-libc
70 #:xbinutils xbinutils))
71 ;; 2. Build cross-compiled kernel headers with XGCC-SANS-LIBC, derived
72 ;; from BASE-KERNEL-HEADERS
73 (xkernel (cross-kernel-headers target
74 #:linux-headers base-kernel-headers
75 #:xgcc xgcc-sans-libc
76 #:xbinutils xbinutils))
77 ;; 3. Build a cross-compiled libc with XGCC-SANS-LIBC and XKERNEL,
78 ;; derived from BASE-LIBC
79 (xlibc (cross-libc target
80 #:libc base-libc
81 #:xgcc xgcc-sans-libc
82 #:xbinutils xbinutils
83 #:xheaders xkernel))
84 ;; 4. Build a cross-compiling gcc targeting XLIBC, derived from
85 ;; BASE-GCC
86 (xgcc (cross-gcc target
87 #:xgcc base-gcc
88 #:xbinutils xbinutils
89 #:libc xlibc)))
90 ;; Define a meta-package that propagates the resulting XBINUTILS, XLIBC, and
91 ;; XGCC
92 (package
93 (name (string-append target "-toolchain"))
94 (version (package-version xgcc))
95 (source #f)
96 (build-system trivial-build-system)
97 (arguments '(#:builder (begin (mkdir %output) #t)))
98 (propagated-inputs
99 (list xbinutils
100 xlibc
101 xgcc
102 `(,xlibc "static")
103 `(,xgcc "lib")))
104 (synopsis (string-append "Complete GCC tool chain for " target))
105 (description (string-append "This package provides a complete GCC tool
106 chain for " target " development."))
107 (home-page (package-home-page xgcc))
108 (license (package-license xgcc)))))
109
110 (define base-gcc
111 (package-with-extra-patches gcc-14
112 (search-our-patches "gcc-remap-guix-store.patch" "gcc-ssa-generation.patch")))
113
114 (define base-linux-kernel-headers linux-libre-headers-6.1)
115
116 (define* (make-bitcoin-cross-toolchain target
117 #:key
118 (base-gcc-for-libc linux-base-gcc)
119 (base-kernel-headers base-linux-kernel-headers)
120 (base-libc glibc-2.31)
121 (base-gcc linux-base-gcc))
122 "Convenience wrapper around MAKE-CROSS-TOOLCHAIN with default values
123 desirable for building Bitcoin Core release binaries."
124 (make-cross-toolchain target
125 base-gcc-for-libc
126 base-kernel-headers
127 base-libc
128 base-gcc))
129
130 (define (binutils-mingw-patches binutils)
131 (package-with-extra-patches binutils
132 (search-our-patches "binutils-unaligned-default.patch")))
133
134 (define (winpthreads-patches mingw-w64-x86_64-winpthreads)
135 (package-with-extra-patches mingw-w64-x86_64-winpthreads
136 (search-our-patches "winpthreads-remap-guix-store.patch")))
137
138 (define (make-mingw-pthreads-cross-toolchain target)
139 "Create a cross-compilation toolchain package for TARGET"
140 (let* ((xbinutils (binutils-mingw-patches (base-binutils target)))
141 (machine (substring target 0 (string-index target #\-)))
142 (pthreads-xlibc (winpthreads-patches (make-mingw-w64 machine
143 #:xgcc (cross-gcc target #:xgcc base-gcc)
144 #:with-winpthreads? #t)))
145 (pthreads-xgcc (cross-gcc target
146 #:xgcc mingw-w64-base-gcc
147 #:xbinutils xbinutils
148 #:libc pthreads-xlibc)))
149 ;; Define a meta-package that propagates the resulting XBINUTILS, XLIBC, and
150 ;; XGCC
151 (package
152 (name (string-append target "-posix-toolchain"))
153 (version (package-version pthreads-xgcc))
154 (source #f)
155 (build-system trivial-build-system)
156 (arguments '(#:builder (begin (mkdir %output) #t)))
157 (propagated-inputs
158 (list xbinutils
159 pthreads-xlibc
160 pthreads-xgcc
161 `(,pthreads-xgcc "lib")))
162 (synopsis (string-append "Complete GCC tool chain for " target))
163 (description (string-append "This package provides a complete GCC tool
164 chain for " target " development."))
165 (home-page (package-home-page pthreads-xgcc))
166 (license (package-license pthreads-xgcc)))))
167
168 (define-public mingw-w64-base-gcc
169 (package
170 (inherit base-gcc)
171 (arguments
172 (substitute-keyword-arguments (package-arguments base-gcc)
173 ((#:configure-flags flags)
174 `(append ,flags
175 ;; https://gcc.gnu.org/install/configure.html
176 (list "--enable-threads=posix",
177 "--enable-default-ssp=yes",
178 "--enable-host-bind-now=yes",
179 "--disable-gcov",
180 "--disable-libgomp",
181 building-on)))))))
182
183 (define-public linux-base-gcc
184 (package
185 (inherit base-gcc)
186 (arguments
187 (substitute-keyword-arguments (package-arguments base-gcc)
188 ((#:configure-flags flags)
189 `(append ,flags
190 ;; https://gcc.gnu.org/install/configure.html
191 (list "--enable-initfini-array=yes",
192 "--enable-default-ssp=yes",
193 "--enable-default-pie=yes",
194 "--enable-host-bind-now=yes",
195 "--enable-standard-branch-protection=yes",
196 "--enable-cet=yes",
197 "--enable-gprofng=no",
198 "--disable-gcov",
199 "--disable-libgomp",
200 "--disable-libquadmath",
201 "--disable-libsanitizer",
202 building-on)))
203 ((#:phases phases)
204 `(modify-phases ,phases
205 ;; Given a XGCC package, return a modified package that replace each instance of
206 ;; -rpath in the default system spec that's inserted by Guix with -rpath-link
207 (add-after 'pre-configure 'replace-rpath-with-rpath-link
208 (lambda _
209 (substitute* (cons "gcc/config/rs6000/sysv4.h"
210 (find-files "gcc/config"
211 "^gnu-user.*\\.h$"))
212 (("-rpath=") "-rpath-link="))
213 #t))))))))
214
215 (define-public glibc-2.31
216 (let ((commit "28eb5caf895ced5d895cb02757e109004a2d33e5"))
217 (package
218 (inherit glibc) ;; 2.39
219 (version "2.31")
220 (source (origin
221 (method git-fetch)
222 (uri (git-reference
223 (url "https://sourceware.org/git/glibc.git")
224 (commit commit)))
225 (file-name (git-file-name "glibc" commit))
226 (sha256
227 (base32
228 "07arjrc1smqy8wrhg38apr1s9ji7xv1rpzdapk4k2ps2n07irp58"))
229 (patches (search-our-patches "glibc-guix-prefix.patch"
230 "glibc-riscv-jumptarget.patch"))))
231 (arguments
232 (substitute-keyword-arguments (package-arguments glibc)
233 ((#:configure-flags flags)
234 `(append ,flags
235 ;; https://www.gnu.org/software/libc/manual/html_node/Configuring-and-compiling.html
236 (list "--enable-stack-protector=all",
237 "--enable-cet",
238 "--enable-bind-now",
239 "--disable-werror",
240 "--disable-timezone-tools",
241 "--disable-profile",
242 building-on)))
243 ((#:phases phases)
244 `(modify-phases ,phases
245 (add-before 'configure 'set-etc-rpc-installation-directory
246 (lambda* (#:key outputs #:allow-other-keys)
247 ;; Install the rpc data base file under `$out/etc/rpc'.
248 ;; Otherwise build will fail with "Permission denied."
249 ;; Can be removed when we are building 2.32 or later.
250 (let ((out (assoc-ref outputs "out")))
251 (substitute* "sunrpc/Makefile"
252 (("^\\$\\(inst_sysconfdir\\)/rpc(.*)$" _ suffix)
253 (string-append out "/etc/rpc" suffix "\n"))
254 (("^install-others =.*$")
255 (string-append "install-others = " out "/etc/rpc\n")))))))))))))
256
257 (packages->manifest
258 (append
259 (list ;; The Basics
260 bash-minimal
261 which
262 coreutils-minimal
263 ;; File(system) inspection
264 grep
265 diffutils
266 findutils
267 ;; File transformation
268 patch
269 gawk
270 sed
271 ;; Compression and archiving
272 tar
273 gzip
274 xz
275 ;; Build tools
276 gcc-toolchain-14
277 cmake-minimal
278 gnu-make
279 ninja
280 ;; Scripting
281 python-minimal ;; (3.11)
282 ;; Git
283 git-minimal
284 ;; Tests
285 python-lief)
286 (let ((target (getenv "HOST")))
287 (cond ((string-suffix? "-mingw32" target)
288 (list (make-mingw-pthreads-cross-toolchain "x86_64-w64-mingw32")
289 nsis-x86_64
290 zip))
291 ((string-contains target "-linux-")
292 (list bison
293 pkg-config
294 (list gcc-toolchain-14 "static")
295 (make-bitcoin-cross-toolchain target)))
296 ((string-contains target "darwin")
297 (list clang-toolchain-19
298 lld-19
299 (make-lld-wrapper lld-19 #:lld-as-ld? #t)
300 zip))
301 (else '())))))
302