meson.scm 7.0 KB

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