meson-build-system.scm 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2017 Peter Mikkelsen <petermikkelsen10@gmail.com>
  3. ;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
  4. ;;; Copyright © 2018 Marius Bakke <mbakke@fastmail.com>
  5. ;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
  6. ;;;
  7. ;;; This file is part of GNU Guix.
  8. ;;;
  9. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  10. ;;; under the terms of the GNU General Public License as published by
  11. ;;; the Free Software Foundation; either version 3 of the License, or (at
  12. ;;; your option) any later version.
  13. ;;;
  14. ;;; GNU Guix is distributed in the hope that it will be useful, but
  15. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;;; GNU General Public License for more details.
  18. ;;;
  19. ;;; You should have received a copy of the GNU General Public License
  20. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  21. (define-module (guix build meson-build-system)
  22. #:use-module ((guix build gnu-build-system) #:prefix gnu:)
  23. #:use-module ((guix build glib-or-gtk-build-system) #:prefix glib-or-gtk:)
  24. #:use-module (guix build utils)
  25. #:use-module (guix build gremlin)
  26. #:use-module (guix elf)
  27. #:use-module (ice-9 match)
  28. #:use-module (rnrs io ports)
  29. #:use-module (srfi srfi-1)
  30. #:export (%standard-phases
  31. meson-build))
  32. ;; Commentary:
  33. ;;
  34. ;; Builder-side code of the standard meson build procedure.
  35. ;;
  36. ;; Code:
  37. (define* (configure #:key outputs configure-flags build-type
  38. #:allow-other-keys)
  39. "Configure the given package."
  40. (let* ((out (assoc-ref outputs "out"))
  41. (source-dir (getcwd))
  42. (build-dir "../build")
  43. (prefix (assoc-ref outputs "out"))
  44. (args `(,(string-append "--prefix=" prefix)
  45. ,(string-append "--buildtype=" build-type)
  46. ,(string-append "-Dc_link_args=-Wl,-rpath="
  47. (assoc-ref outputs "out") "/lib")
  48. ,(string-append "-Dcpp_link_args=-Wl,-rpath="
  49. (assoc-ref outputs "out") "/lib")
  50. ,@configure-flags
  51. ,source-dir)))
  52. (mkdir build-dir)
  53. (chdir build-dir)
  54. (apply invoke "meson" args)))
  55. (define* (build #:key parallel-build?
  56. #:allow-other-keys)
  57. "Build a given meson package."
  58. (invoke "ninja" "-j" (if parallel-build?
  59. (number->string (parallel-job-count))
  60. "1")))
  61. (define* (check #:key tests? test-options parallel-tests?
  62. #:allow-other-keys)
  63. (if tests?
  64. (begin
  65. (setenv "MESON_TESTTHREADS"
  66. (if parallel-tests?
  67. (number->string (parallel-job-count))
  68. "1"))
  69. ;; Always provide "-t 0" to disable the 30 s default timeout.
  70. (apply invoke "meson" "test" "--print-errorlogs" "-t" "0" test-options))
  71. (format #t "test suite not run~%")))
  72. (define* (install #:rest args)
  73. (invoke "ninja" "install"))
  74. (define* (shrink-runpath #:key (elf-directories '("lib" "lib64" "libexec"
  75. "bin" "sbin"))
  76. outputs #:allow-other-keys)
  77. "Go through all ELF files from ELF-DIRECTORIES and shrink the RUNPATH
  78. since a lot of directories are left over from the build phase of meson,
  79. for example libraries only needed for the tests."
  80. (define handle-output
  81. (match-lambda
  82. ((output . directory)
  83. (let* ((elf-dirnames (map (lambda (subdir)
  84. (string-append directory "/" subdir))
  85. elf-directories))
  86. (existing-elf-dirs (filter (lambda (dir)
  87. (and (file-exists? dir)
  88. (file-is-directory? dir)))
  89. elf-dirnames))
  90. (elf-pred (lambda (name stat)
  91. (elf-file? name)))
  92. (elf-list (concatenate (map (lambda (dir)
  93. (find-files dir elf-pred))
  94. existing-elf-dirs))))
  95. (for-each strip-runpath elf-list)))))
  96. (for-each handle-output (alist-delete "debug" outputs))
  97. #t)
  98. (define %standard-phases
  99. ;; The standard-phases of glib-or-gtk contains a superset of the phases
  100. ;; from the gnu-build-system. If the glib-or-gtk? key is #f (the default)
  101. ;; then the extra phases will be removed again in (guix build-system meson).
  102. (modify-phases glib-or-gtk:%standard-phases
  103. (delete 'bootstrap)
  104. (replace 'configure configure)
  105. (replace 'build build)
  106. (replace 'check check)
  107. (replace 'install install)
  108. (add-after 'strip 'shrink-runpath shrink-runpath)))
  109. (define* (meson-build #:key inputs phases
  110. #:allow-other-keys #:rest args)
  111. "Build the given package, applying all of PHASES in order."
  112. (apply gnu:gnu-build #:inputs inputs #:phases phases args))
  113. ;;; meson-build-system.scm ends here