meson.scm 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2017 Peter Mikkelsen <petermikkelsen10@gmail.com>
  3. ;;; Copyright © 2018, 2019 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. (define-module (guix build-system meson)
  20. #:use-module (guix store)
  21. #:use-module (guix utils)
  22. #:use-module (guix derivations)
  23. #:use-module (guix search-paths)
  24. #:use-module (guix build-system)
  25. #:use-module (guix build-system gnu)
  26. #:use-module (guix build-system glib-or-gtk)
  27. #:use-module (guix packages)
  28. #:use-module (ice-9 match)
  29. #:export (%meson-build-system-modules
  30. meson-build-system))
  31. ;; Commentary:
  32. ;;
  33. ;; Standard build procedure for packages using Meson. This is implemented as an
  34. ;; extension of `gnu-build-system', with the option to turn on the glib/gtk
  35. ;; phases from `glib-or-gtk-build-system'.
  36. ;;
  37. ;; Code:
  38. (define %meson-build-system-modules
  39. ;; Build-side modules imported by default.
  40. `((guix build meson-build-system)
  41. ;; The modules from glib-or-gtk contains the modules from gnu-build-system,
  42. ;; so there is no need to import that too.
  43. ,@%glib-or-gtk-build-system-modules))
  44. (define (default-ninja)
  45. "Return the default ninja package."
  46. ;; Lazily resolve the binding to avoid a circular dependency.
  47. (let ((module (resolve-interface '(gnu packages ninja))))
  48. (module-ref module 'ninja)))
  49. (define (default-meson)
  50. "Return the default meson package."
  51. ;; Lazily resolve the binding to avoid a circular dependency.
  52. (let ((module (resolve-interface '(gnu packages build-tools))))
  53. (module-ref module 'meson-for-build)))
  54. (define* (lower name
  55. #:key source inputs native-inputs outputs system target
  56. (meson (default-meson))
  57. (ninja (default-ninja))
  58. (glib-or-gtk? #f)
  59. #:allow-other-keys
  60. #:rest arguments)
  61. "Return a bag for NAME."
  62. (define private-keywords
  63. `(#:source #:meson #:ninja #:inputs #:native-inputs #:outputs #:target))
  64. (and (not target) ;; TODO: add support for cross-compilation.
  65. (bag
  66. (name name)
  67. (system system)
  68. (build-inputs `(("meson" ,meson)
  69. ("ninja" ,ninja)
  70. ,@native-inputs))
  71. (host-inputs `(,@(if source
  72. `(("source" ,source))
  73. '())
  74. ,@inputs
  75. ;; Keep the standard inputs of 'gnu-build-system'.
  76. ,@(standard-packages)))
  77. (outputs outputs)
  78. (build meson-build)
  79. (arguments (strip-keyword-arguments private-keywords arguments)))))
  80. (define* (meson-build store name inputs
  81. #:key (guile #f)
  82. (outputs '("out"))
  83. (configure-flags ''())
  84. (search-paths '())
  85. (build-type "debugoptimized")
  86. (tests? #t)
  87. (test-target "test")
  88. (glib-or-gtk? #f)
  89. (parallel-build? #t)
  90. (parallel-tests? #f)
  91. (validate-runpath? #t)
  92. (patch-shebangs? #t)
  93. (strip-binaries? #t)
  94. (strip-flags ''("--strip-debug"))
  95. (strip-directories ''("lib" "lib64" "libexec"
  96. "bin" "sbin"))
  97. (elf-directories ''("lib" "lib64" "libexec"
  98. "bin" "sbin"))
  99. (phases '(@ (guix build meson-build-system)
  100. %standard-phases))
  101. (system (%current-system))
  102. (imported-modules %meson-build-system-modules)
  103. (modules '((guix build meson-build-system)
  104. (guix build utils)))
  105. allowed-references
  106. disallowed-references)
  107. "Build SOURCE using MESON, and with INPUTS, assuming that SOURCE
  108. has a 'meson.build' file."
  109. ;; TODO: Copied from build-system/gnu, factorize this!
  110. (define canonicalize-reference
  111. (match-lambda
  112. ((? package? p)
  113. (derivation->output-path (package-derivation store p system
  114. #:graft? #f)))
  115. (((? package? p) output)
  116. (derivation->output-path (package-derivation store p system
  117. #:graft? #f)
  118. output))
  119. ((? string? output)
  120. output)))
  121. (define builder
  122. `(let ((build-phases (if ,glib-or-gtk?
  123. ,phases
  124. (modify-phases ,phases
  125. (delete 'glib-or-gtk-compile-schemas)
  126. (delete 'glib-or-gtk-wrap)))))
  127. (use-modules ,@modules)
  128. (meson-build #:source ,(match (assoc-ref inputs "source")
  129. (((? derivation? source))
  130. (derivation->output-path source))
  131. ((source)
  132. source)
  133. (source
  134. source))
  135. #:system ,system
  136. #:outputs %outputs
  137. #:inputs %build-inputs
  138. #:search-paths ',(map search-path-specification->sexp
  139. search-paths)
  140. #:phases build-phases
  141. #:configure-flags ,configure-flags
  142. #:build-type ,build-type
  143. #:tests? ,tests?
  144. #:test-target ,test-target
  145. #:parallel-build? ,parallel-build?
  146. #:parallel-tests? ,parallel-tests?
  147. #:validate-runpath? ,validate-runpath?
  148. #:patch-shebangs? ,patch-shebangs?
  149. #:strip-binaries? ,strip-binaries?
  150. #:strip-flags ,strip-flags
  151. #:strip-directories ,strip-directories
  152. #:elf-directories ,elf-directories)))
  153. (define guile-for-build
  154. (match guile
  155. ((? package?)
  156. (package-derivation store guile system #:graft? #f))
  157. (#f ; the default
  158. (let* ((distro (resolve-interface '(gnu packages commencement)))
  159. (guile (module-ref distro 'guile-final)))
  160. (package-derivation store guile system #:graft? #f)))))
  161. (build-expression->derivation store name builder
  162. #:system system
  163. #:inputs inputs
  164. #:modules imported-modules
  165. #:outputs outputs
  166. #:guile-for-build guile-for-build
  167. #:allowed-references
  168. (and allowed-references
  169. (map canonicalize-reference
  170. allowed-references))
  171. #:disallowed-references
  172. (and disallowed-references
  173. (map canonicalize-reference
  174. disallowed-references))))
  175. (define meson-build-system
  176. (build-system
  177. (name 'meson)
  178. (description "The standard Meson build system")
  179. (lower lower)))
  180. ;;; meson.scm ends here