1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2018, 2019 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (guix build-system guile)
20 #:use-module (guix store)
21 #:use-module (guix utils)
22 #:use-module (guix packages)
23 #:use-module (guix derivations)
24 #:use-module (guix search-paths)
25 #:use-module (guix build-system)
26 #:use-module (guix build-system gnu)
27 #:use-module (ice-9 match)
28 #:use-module (srfi srfi-26)
29 #:export (%guile-build-system-modules
32 (define %scheme-file-regexp
33 ;; Regexp to match Scheme files.
36 (define %guile-build-system-modules
37 ;; Build-side modules imported by default.
38 `((guix build guile-build-system)
39 ,@%gnu-build-system-modules))
42 #:key source inputs native-inputs outputs system target
46 "Return a bag for NAME."
48 ;; Note: There's no #:guile argument (unlike, for instance,
49 ;; 'ocaml-build-system' which has #:ocaml.) This is so we can keep
50 ;; procedures like 'package-for-guile-2.0' unchanged and simple.
52 (define private-keywords
53 '(#:target #:inputs #:native-inputs
58 (system system) (target target)
61 (build-inputs `(,@(if source
65 ,@(if implicit-inputs?
66 (map (cute assoc <> (standard-packages))
67 '("tar" "gzip" "bzip2" "xz" "locales"))
70 (build (if target guile-cross-build guile-build))
71 (arguments (strip-keyword-arguments private-keywords arguments))))
73 (define %compile-flags
74 ;; Flags passed to 'guild compile' by default. We choose a common
75 ;; denominator between Guile 2.0 and 2.2.
76 ''("-Wunbound-variable" "-Warity-mismatch" "-Wformat"))
78 (define* (guile-build store name inputs
81 (phases '%standard-phases)
84 (system (%current-system))
85 (source-directory ".")
86 not-compiled-file-regexp
87 (scheme-file-regexp %scheme-file-regexp)
88 (compile-flags %compile-flags)
89 (imported-modules %guile-build-system-modules)
90 (modules '((guix build guile-build-system)
92 "Build SOURCE using Guile taken from the native inputs, and with INPUTS."
95 (use-modules ,@modules)
96 (guile-build #:name ,name
97 #:source ,(match (assoc-ref inputs "source")
98 (((? derivation? source))
99 (derivation->output-path source))
104 #:source-directory ,source-directory
105 #:scheme-file-regexp ,scheme-file-regexp
106 #:not-compiled-file-regexp ,not-compiled-file-regexp
107 #:compile-flags ,compile-flags
111 #:search-paths ',(map search-path-specification->sexp
113 #:inputs %build-inputs)))
115 (define guile-for-build
118 (package-derivation store guile system #:graft? #f))
120 (let* ((distro (resolve-interface '(gnu packages commencement)))
121 (guile (module-ref distro 'guile-final)))
122 (package-derivation store guile system #:graft? #f)))))
124 (build-expression->derivation store name builder
127 #:modules imported-modules
129 #:guile-for-build guile-for-build))
131 (define* (guile-cross-build store name
133 (system (%current-system)) target
134 native-drvs target-drvs
139 (native-search-paths '())
141 (phases '%standard-phases)
142 (source-directory ".")
143 not-compiled-file-regexp
144 (compile-flags %compile-flags)
145 (imported-modules %guile-build-system-modules)
146 (modules '((guix build guile-build-system)
147 (guix build utils))))
150 (use-modules ,@modules)
153 (define %build-host-inputs
155 ((name (? derivation? drv) sub ...)
156 `(,name . ,(apply derivation->output-path drv sub)))
161 (define %build-target-inputs
163 ((name (? derivation? drv) sub ...)
164 `(,name . ,(apply derivation->output-path drv sub)))
165 ((name (? package? pkg) sub ...)
166 (let ((drv (package-cross-derivation store pkg
168 `(,name . ,(apply derivation->output-path drv sub))))
173 (guile-build #:source ,(match (assoc-ref native-drvs "source")
174 (((? derivation? source))
175 (derivation->output-path source))
183 #:source-directory ,source-directory
184 #:not-compiled-file-regexp ,not-compiled-file-regexp
185 #:compile-flags ,compile-flags
186 #:inputs %build-target-inputs
187 #:native-inputs %build-host-inputs
188 #:search-paths ',(map search-path-specification->sexp
190 #:native-search-paths ',(map
191 search-path-specification->sexp
195 (define guile-for-build
198 (package-derivation store guile system #:graft? #f))
200 (let* ((distro (resolve-interface '(gnu packages commencement)))
201 (guile (module-ref distro 'guile-final)))
202 (package-derivation store guile system #:graft? #f)))))
204 (build-expression->derivation store name builder
206 #:inputs (append native-drvs target-drvs)
208 #:modules imported-modules
209 #:substitutable? substitutable?
210 #:guile-for-build guile-for-build))
212 (define guile-build-system
215 (description "The build system for simple Guile packages")