meson-build-system.scm 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. ;;;
  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 meson-build-system)
  21. #:use-module ((guix build gnu-build-system) #:prefix gnu:)
  22. #:use-module ((guix build glib-or-gtk-build-system) #:prefix glib-or-gtk:)
  23. #:use-module (guix build utils)
  24. #:use-module (guix build gremlin)
  25. #:use-module (guix elf)
  26. #:use-module (ice-9 match)
  27. #:use-module (rnrs io ports)
  28. #:use-module (srfi srfi-1)
  29. #:export (%standard-phases
  30. meson-build))
  31. ;; Commentary:
  32. ;;
  33. ;; Builder-side code of the standard meson build procedure.
  34. ;;
  35. ;; Code:
  36. (define* (configure #:key outputs configure-flags build-type
  37. #:allow-other-keys)
  38. "Configure the given package."
  39. (let* ((out (assoc-ref outputs "out"))
  40. (source-dir (getcwd))
  41. (build-dir "../build")
  42. (prefix (assoc-ref outputs "out"))
  43. (args `(,(string-append "--prefix=" prefix)
  44. ,(string-append "--buildtype=" build-type)
  45. ,(string-append "-Dc_link_args=-Wl,-rpath="
  46. (assoc-ref outputs "out") "/lib")
  47. ,(string-append "-Dcpp_link_args=-Wl,-rpath="
  48. (assoc-ref outputs "out") "/lib")
  49. ,@configure-flags
  50. ,source-dir)))
  51. (mkdir build-dir)
  52. (chdir build-dir)
  53. (apply invoke "meson" args)))
  54. (define* (build #:key parallel-build?
  55. #:allow-other-keys)
  56. "Build a given meson package."
  57. (invoke "ninja" "-j" (if parallel-build?
  58. (number->string (parallel-job-count))
  59. "1")))
  60. (define* (check #:key test-target parallel-tests? tests?
  61. #:allow-other-keys)
  62. (setenv "MESON_TESTTHREADS"
  63. (if parallel-tests?
  64. (number->string (parallel-job-count))
  65. "1"))
  66. (if tests?
  67. (invoke "ninja" test-target)
  68. (format #t "test suite not run~%"))
  69. #t)
  70. (define* (install #:rest args)
  71. (invoke "ninja" "install"))
  72. (define* (shrink-runpath #:key (elf-directories '("lib" "lib64" "libexec"
  73. "bin" "sbin"))
  74. outputs #:allow-other-keys)
  75. "Go through all ELF files from ELF-DIRECTORIES and shrink the RUNPATH
  76. since a lot of directories are left over from the build phase of meson,
  77. for example libraries only needed for the tests."
  78. (define handle-output
  79. (match-lambda
  80. ((output . directory)
  81. (let* ((elf-dirnames (map (lambda (subdir)
  82. (string-append directory "/" subdir))
  83. elf-directories))
  84. (existing-elf-dirs (filter (lambda (dir)
  85. (and (file-exists? dir)
  86. (file-is-directory? dir)))
  87. elf-dirnames))
  88. (elf-pred (lambda (name stat)
  89. (elf-file? name)))
  90. (elf-list (concatenate (map (lambda (dir)
  91. (find-files dir elf-pred))
  92. existing-elf-dirs))))
  93. (for-each strip-runpath elf-list)))))
  94. (for-each handle-output (alist-delete "debug" outputs))
  95. #t)
  96. (define %standard-phases
  97. ;; The standard-phases of glib-or-gtk contains a superset of the phases
  98. ;; from the gnu-build-system. If the glib-or-gtk? key is #f (the default)
  99. ;; then the extra phases will be removed again in (guix build-system meson).
  100. (modify-phases glib-or-gtk:%standard-phases
  101. (delete 'bootstrap)
  102. (replace 'configure configure)
  103. (replace 'build build)
  104. (replace 'check check)
  105. (replace 'install install)
  106. (add-after 'strip 'shrink-runpath shrink-runpath)))
  107. (define* (meson-build #:key inputs phases
  108. #:allow-other-keys #:rest args)
  109. "Build the given package, applying all of PHASES in order."
  110. (apply gnu:gnu-build #:inputs inputs #:phases phases args))
  111. ;;; meson-build-system.scm ends here