Merge branch 'master' into staging
[jackhill/guix/guix.git] / guix / build-system / meson.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017 Peter Mikkelsen <petermikkelsen10@gmail.com>
3 ;;; Copyright © 2018 Marius Bakke <mbakke@fastmail.com>
4 ;;;
5 ;;; This file is part of GNU Guix.
6 ;;;
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
11 ;;;
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
16 ;;;
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20 (define-module (guix build-system meson)
21 #:use-module (guix store)
22 #:use-module (guix utils)
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 (guix build-system glib-or-gtk)
28 #:use-module (guix packages)
29 #:use-module (ice-9 match)
30 #:export (%meson-build-system-modules
31 meson-build-system))
32
33 ;; Commentary:
34 ;;
35 ;; Standard build procedure for packages using Meson. This is implemented as an
36 ;; extension of `gnu-build-system', with the option to turn on the glib/gtk
37 ;; phases from `glib-or-gtk-build-system'.
38 ;;
39 ;; Code:
40
41 (define %meson-build-system-modules
42 ;; Build-side modules imported by default.
43 `((guix build meson-build-system)
44 ;; The modules from glib-or-gtk contains the modules from gnu-build-system,
45 ;; so there is no need to import that too.
46 ,@%glib-or-gtk-build-system-modules))
47
48 (define (default-ninja)
49 "Return the default ninja package."
50 ;; Lazily resolve the binding to avoid a circular dependency.
51 (let ((module (resolve-interface '(gnu packages ninja))))
52 (module-ref module 'ninja)))
53
54 (define (default-meson)
55 "Return the default meson package."
56 ;; Lazily resolve the binding to avoid a circular dependency.
57 (let ((module (resolve-interface '(gnu packages build-tools))))
58 (module-ref module 'meson-for-build)))
59
60 (define* (lower name
61 #:key source inputs native-inputs outputs system target
62 (meson (default-meson))
63 (ninja (default-ninja))
64 (glib-or-gtk? #f)
65 #:allow-other-keys
66 #:rest arguments)
67 "Return a bag for NAME."
68 (define private-keywords
69 `(#:source #:meson #:ninja #:inputs #:native-inputs #:outputs #:target))
70
71 (and (not target) ;; TODO: add support for cross-compilation.
72 (bag
73 (name name)
74 (system system)
75 (build-inputs `(("meson" ,meson)
76 ("ninja" ,ninja)
77 ,@native-inputs))
78 (host-inputs `(,@(if source
79 `(("source" ,source))
80 '())
81 ,@inputs
82 ;; Keep the standard inputs of 'gnu-build-system'.
83 ,@(standard-packages)))
84 (outputs outputs)
85 (build meson-build)
86 (arguments (strip-keyword-arguments private-keywords arguments)))))
87
88 (define* (meson-build store name inputs
89 #:key (guile #f)
90 (outputs '("out"))
91 (configure-flags ''())
92 (search-paths '())
93 (build-type "plain")
94 (tests? #t)
95 (test-target "test")
96 (glib-or-gtk? #f)
97 (parallel-build? #t)
98 (parallel-tests? #f)
99 (validate-runpath? #t)
100 (patch-shebangs? #t)
101 (strip-binaries? #t)
102 (strip-flags ''("--strip-debug"))
103 (strip-directories ''("lib" "lib64" "libexec"
104 "bin" "sbin"))
105 (elf-directories ''("lib" "lib64" "libexec"
106 "bin" "sbin"))
107 (phases '(@ (guix build meson-build-system)
108 %standard-phases))
109 (system (%current-system))
110 (imported-modules %meson-build-system-modules)
111 (modules '((guix build meson-build-system)
112 (guix build utils))))
113 "Build SOURCE using MESON, and with INPUTS, assuming that SOURCE
114 has a 'meson.build' file."
115 (define builder
116 `(let ((build-phases (if ,glib-or-gtk?
117 ,phases
118 (modify-phases ,phases
119 (delete 'glib-or-gtk-compile-schemas)
120 (delete 'glib-or-gtk-wrap)))))
121 (use-modules ,@modules)
122 (meson-build #:source ,(match (assoc-ref inputs "source")
123 (((? derivation? source))
124 (derivation->output-path source))
125 ((source)
126 source)
127 (source
128 source))
129 #:system ,system
130 #:outputs %outputs
131 #:inputs %build-inputs
132 #:search-paths ',(map search-path-specification->sexp
133 search-paths)
134 #:phases build-phases
135 #:configure-flags ,configure-flags
136 #:build-type ,build-type
137 #:tests? ,tests?
138 #:test-target ,test-target
139 #:parallel-build? ,parallel-build?
140 #:parallel-tests? ,parallel-tests?
141 #:validate-runpath? ,validate-runpath?
142 #:patch-shebangs? ,patch-shebangs?
143 #:strip-binaries? ,strip-binaries?
144 #:strip-flags ,strip-flags
145 #:strip-directories ,strip-directories
146 #:elf-directories ,elf-directories)))
147
148 (define guile-for-build
149 (match guile
150 ((? package?)
151 (package-derivation store guile system #:graft? #f))
152 (#f ; the default
153 (let* ((distro (resolve-interface '(gnu packages commencement)))
154 (guile (module-ref distro 'guile-final)))
155 (package-derivation store guile system #:graft? #f)))))
156
157 (build-expression->derivation store name builder
158 #:system system
159 #:inputs inputs
160 #:modules imported-modules
161 #:outputs outputs
162 #:guile-for-build guile-for-build))
163
164 (define meson-build-system
165 (build-system
166 (name 'meson)
167 (description "The standard Meson build system")
168 (lower lower)))
169
170 ;;; meson.scm ends here