guile.scm 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2018-2019, 2021-2022 Ludovic Courtès <ludo@gnu.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (guix build-system guile)
  19. #:use-module (guix store)
  20. #:use-module (guix utils)
  21. #:use-module (guix packages)
  22. #:use-module (guix monads)
  23. #:use-module (guix gexp)
  24. #:use-module (guix search-paths)
  25. #:use-module (guix build-system)
  26. #:use-module (guix build-system gnu)
  27. #:use-module (ice-9 match)
  28. #:use-module (srfi srfi-26)
  29. #:export (%guile-build-system-modules
  30. guile-build-system))
  31. (define %scheme-file-regexp
  32. ;; Regexp to match Scheme files.
  33. "\\.(scm|sls)$")
  34. (define %guile-build-system-modules
  35. ;; Build-side modules imported by default.
  36. `((guix build guile-build-system)
  37. ,@%gnu-build-system-modules))
  38. (define* (lower name
  39. #:key source inputs native-inputs outputs system target
  40. (implicit-inputs? #t)
  41. #:allow-other-keys
  42. #:rest arguments)
  43. "Return a bag for NAME."
  44. ;; Note: There's no #:guile argument (unlike, for instance,
  45. ;; 'ocaml-build-system' which has #:ocaml.) This is so we can keep
  46. ;; procedures like 'package-for-guile-2.0' unchanged and simple.
  47. (define private-keywords
  48. '(#:target #:inputs #:native-inputs
  49. #:implicit-inputs?))
  50. (bag
  51. (name name)
  52. (system system) (target target)
  53. (host-inputs `(
  54. ,@inputs))
  55. (build-inputs `(,@(if source
  56. `(("source" ,source))
  57. '())
  58. ,@native-inputs
  59. ,@(if implicit-inputs?
  60. (map (cute assoc <> (standard-packages))
  61. '("tar" "gzip" "bzip2" "xz" "locales"))
  62. '())))
  63. (outputs outputs)
  64. (build (if target guile-cross-build guile-build))
  65. (arguments (strip-keyword-arguments private-keywords arguments))))
  66. (define %compile-flags
  67. ;; Flags passed to 'guild compile' by default. We choose a common
  68. ;; denominator between Guile 2.0 and 2.2.
  69. ''("-Wunbound-variable" "-Warity-mismatch" "-Wformat"))
  70. (define* (guile-build name inputs
  71. #:key source
  72. (guile #f)
  73. (phases '%standard-phases)
  74. (outputs '("out"))
  75. (search-paths '())
  76. (system (%current-system))
  77. (source-directory ".")
  78. not-compiled-file-regexp
  79. (scheme-file-regexp %scheme-file-regexp)
  80. (compile-flags %compile-flags)
  81. (imported-modules %guile-build-system-modules)
  82. (modules '((guix build guile-build-system)
  83. (guix build utils))))
  84. "Build SOURCE using Guile taken from the native inputs, and with INPUTS."
  85. (define builder
  86. (with-imported-modules imported-modules
  87. #~(begin
  88. (use-modules #$@modules)
  89. (guile-build #:name #$name
  90. #:source #+source
  91. #:source-directory #$source-directory
  92. #:scheme-file-regexp #$scheme-file-regexp
  93. #:not-compiled-file-regexp #$not-compiled-file-regexp
  94. #:compile-flags #$compile-flags
  95. #:phases #$phases
  96. #:system #$system
  97. #:outputs #$(outputs->gexp outputs)
  98. #:inputs #$(input-tuples->gexp inputs)
  99. #:search-paths '#$(map search-path-specification->sexp
  100. search-paths)))))
  101. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  102. system #:graft? #f)))
  103. (gexp->derivation name builder
  104. #:system system
  105. #:target #f
  106. #:guile-for-build guile)))
  107. (define* (guile-cross-build name
  108. #:key
  109. (system (%current-system)) target
  110. build-inputs target-inputs host-inputs
  111. (guile #f)
  112. source
  113. (outputs '("out"))
  114. (search-paths '())
  115. (native-search-paths '())
  116. (phases '%standard-phases)
  117. (source-directory ".")
  118. not-compiled-file-regexp
  119. (compile-flags %compile-flags)
  120. (imported-modules %guile-build-system-modules)
  121. (modules '((guix build guile-build-system)
  122. (guix build utils))))
  123. (define builder
  124. (with-imported-modules imported-modules
  125. #~(begin
  126. (use-modules #$@modules)
  127. (define %build-host-inputs
  128. #+(input-tuples->gexp build-inputs))
  129. (define %build-target-inputs
  130. (append #$(input-tuples->gexp host-inputs)
  131. #+(input-tuples->gexp target-inputs)))
  132. (define %outputs
  133. #$(outputs->gexp outputs))
  134. (guile-build #:source #+source
  135. #:system #$system
  136. #:target #$target
  137. #:outputs %outputs
  138. #:source-directory #$source-directory
  139. #:not-compiled-file-regexp #$not-compiled-file-regexp
  140. #:compile-flags #$compile-flags
  141. #:inputs %build-target-inputs
  142. #:native-inputs %build-host-inputs
  143. #:search-paths '#$(map search-path-specification->sexp
  144. search-paths)
  145. #:native-search-paths '#$(map
  146. search-path-specification->sexp
  147. native-search-paths)
  148. #:make-dynamic-linker-cache? #f ;cross-compiling
  149. #:phases #$phases))))
  150. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  151. system #:graft? #f)))
  152. (gexp->derivation name builder
  153. #:system system
  154. #:target target
  155. #:guile-for-build guile)))
  156. (define guile-build-system
  157. (build-system
  158. (name 'guile)
  159. (description "The build system for simple Guile packages")
  160. (lower lower)))