1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017 Peter Mikkelsen <petermikkelsen10@gmail.com>
3 ;;; Copyright © 2018 Marius Bakke <mbakke@fastmail.com>
5 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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
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'.
41 (define %meson-build-system-modules
42 ;; Build-side modules imported by default.
43 `((guix build meson-build-system)
45 ;; The modules from glib-or-gtk contains the modules from gnu-build-system,
46 ;; so there is no need to import that too.
47 ,@%glib-or-gtk-build-system-modules))
49 (define (default-ninja)
50 "Return the default ninja package."
51 ;; Lazily resolve the binding to avoid a circular dependency.
52 (let ((module (resolve-interface '(gnu packages ninja))))
53 (module-ref module 'ninja)))
55 (define (default-meson)
56 "Return the default meson package."
57 ;; Lazily resolve the binding to avoid a circular dependency.
58 (let ((module (resolve-interface '(gnu packages build-tools))))
59 (module-ref module 'meson-for-build)))
61 (define (default-patchelf)
62 "Return the default patchelf package."
63 ;; Lazily resolve the binding to avoid a circular dependency.
64 (let ((module (resolve-interface '(gnu packages elf))))
65 (module-ref module 'patchelf)))
68 #:key source inputs native-inputs outputs system target
69 (meson (default-meson))
70 (ninja (default-ninja))
74 "Return a bag for NAME."
75 (define private-keywords
76 `(#:source #:meson #:ninja #:inputs #:native-inputs #:outputs #:target))
78 (and (not target) ;; TODO: add support for cross-compilation.
82 (build-inputs `(("meson" ,meson)
84 ;; XXX PatchELF fails to build on armhf, so we skip
85 ;; the 'fix-runpath' phase there for now. It is used
86 ;; to avoid superfluous entries in RUNPATH as described
87 ;; in <https://bugs.gnu.org/28444#46>, so armhf may now
88 ;; have different runtime dependencies from other arches.
89 ,@(if (not (string-prefix? "arm" (or (%current-target-system)
91 `(("patchelf" ,(default-patchelf)))
94 (host-inputs `(,@(if source
98 ;; Keep the standard inputs of 'gnu-build-system'.
99 ,@(standard-packages)))
102 (arguments (strip-keyword-arguments private-keywords arguments)))))
104 (define* (meson-build store name inputs
107 (configure-flags ''())
115 (validate-runpath? #t)
118 (strip-flags ''("--strip-debug"))
119 (strip-directories ''("lib" "lib64" "libexec"
121 (elf-directories ''("lib" "lib64" "libexec"
123 (phases '(@ (guix build meson-build-system)
125 (system (%current-system))
126 (imported-modules %meson-build-system-modules)
127 (modules '((guix build meson-build-system)
128 (guix build utils))))
129 "Build SOURCE using MESON, and with INPUTS, assuming that SOURCE
130 has a 'meson.build' file."
132 `(let ((build-phases (if ,glib-or-gtk?
134 (modify-phases ,phases
135 (delete 'glib-or-gtk-compile-schemas)
136 (delete 'glib-or-gtk-wrap)))))
137 (use-modules ,@modules)
138 (meson-build #:source ,(match (assoc-ref inputs "source")
139 (((? derivation? source))
140 (derivation->output-path source))
147 #:inputs %build-inputs
148 #:search-paths ',(map search-path-specification->sexp
151 (if (string-prefix? "arm" ,(or (%current-target-system)
153 (modify-phases build-phases (delete 'fix-runpath))
155 #:configure-flags ,configure-flags
156 #:build-type ,build-type
158 #:test-target ,test-target
159 #:parallel-build? ,parallel-build?
160 #:parallel-tests? ,parallel-tests?
161 #:validate-runpath? ,validate-runpath?
162 #:patch-shebangs? ,patch-shebangs?
163 #:strip-binaries? ,strip-binaries?
164 #:strip-flags ,strip-flags
165 #:strip-directories ,strip-directories
166 #:elf-directories ,elf-directories)))
168 (define guile-for-build
171 (package-derivation store guile system #:graft? #f))
173 (let* ((distro (resolve-interface '(gnu packages commencement)))
174 (guile (module-ref distro 'guile-final)))
175 (package-derivation store guile system #:graft? #f)))))
177 (build-expression->derivation store name builder
180 #:modules imported-modules
182 #:guile-for-build guile-for-build))
184 (define meson-build-system
187 (description "The standard Meson build system")
190 ;;; meson.scm ends here