guile.scm 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 (srfi srfi-26)
  28. #:export (%guile-build-system-modules
  29. guile-build-system))
  30. (define %scheme-file-regexp
  31. ;; Regexp to match Scheme files.
  32. "\\.(scm|sls)$")
  33. (define %guile-build-system-modules
  34. ;; Build-side modules imported by default.
  35. `((guix build guile-build-system)
  36. ,@%gnu-build-system-modules))
  37. (define* (lower name
  38. #:key source inputs native-inputs outputs system target
  39. (implicit-inputs? #t)
  40. #:allow-other-keys
  41. #:rest arguments)
  42. "Return a bag for NAME."
  43. ;; Note: There's no #:guile argument (unlike, for instance,
  44. ;; 'ocaml-build-system' which has #:ocaml.) This is so we can keep
  45. ;; procedures like 'package-for-guile-2.0' unchanged and simple.
  46. (define private-keywords
  47. '(#:target #:inputs #:native-inputs
  48. #:implicit-inputs?))
  49. (bag
  50. (name name)
  51. (system system) (target target)
  52. (host-inputs `(
  53. ,@inputs))
  54. (build-inputs `(,@(if source
  55. `(("source" ,source))
  56. '())
  57. ,@native-inputs
  58. ,@(if implicit-inputs?
  59. (map (cute assoc <> (standard-packages))
  60. '("tar" "gzip" "bzip2" "xz" "locales"))
  61. '())))
  62. (outputs outputs)
  63. (build (if target guile-cross-build guile-build))
  64. (arguments (strip-keyword-arguments private-keywords arguments))))
  65. (define %compile-flags
  66. ;; Flags passed to 'guild compile' by default. We choose a common
  67. ;; denominator between Guile 2.0 and 2.2.
  68. ''("-Wunbound-variable" "-Warity-mismatch" "-Wformat"))
  69. (define* (guile-build name inputs
  70. #:key source
  71. (guile #f)
  72. (phases '%standard-phases)
  73. (outputs '("out"))
  74. (search-paths '())
  75. (system (%current-system))
  76. (source-directory ".")
  77. not-compiled-file-regexp
  78. (scheme-file-regexp %scheme-file-regexp)
  79. (compile-flags %compile-flags)
  80. (imported-modules %guile-build-system-modules)
  81. (modules '((guix build guile-build-system)
  82. (guix build utils))))
  83. "Build SOURCE using Guile taken from the native inputs, and with INPUTS."
  84. (define builder
  85. (with-imported-modules imported-modules
  86. #~(begin
  87. (use-modules #$@modules)
  88. (guile-build #:name #$name
  89. #:source #+source
  90. #:source-directory #$source-directory
  91. #:scheme-file-regexp #$scheme-file-regexp
  92. #:not-compiled-file-regexp #$not-compiled-file-regexp
  93. #:compile-flags #$compile-flags
  94. #:phases #$phases
  95. #:system #$system
  96. #:outputs #$(outputs->gexp outputs)
  97. #:inputs #$(input-tuples->gexp inputs)
  98. #:search-paths '#$(map search-path-specification->sexp
  99. search-paths)))))
  100. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  101. system #:graft? #f)))
  102. (gexp->derivation name builder
  103. #:system system
  104. #:target #f
  105. #:graft? #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. (scheme-file-regexp %scheme-file-regexp)
  119. not-compiled-file-regexp
  120. (compile-flags %compile-flags)
  121. (imported-modules %guile-build-system-modules)
  122. (modules '((guix build guile-build-system)
  123. (guix build utils))))
  124. (define builder
  125. (with-imported-modules imported-modules
  126. #~(begin
  127. (use-modules #$@modules)
  128. (define %build-host-inputs
  129. #+(input-tuples->gexp build-inputs))
  130. (define %build-target-inputs
  131. (append #$(input-tuples->gexp host-inputs)
  132. #+(input-tuples->gexp target-inputs)))
  133. (define %outputs
  134. #$(outputs->gexp outputs))
  135. (guile-build #:source #+source
  136. #:system #$system
  137. #:target #$target
  138. #:outputs %outputs
  139. #:source-directory #$source-directory
  140. #:scheme-file-regexp #$scheme-file-regexp
  141. #:not-compiled-file-regexp #$not-compiled-file-regexp
  142. #:compile-flags #$compile-flags
  143. #:inputs %build-target-inputs
  144. #:native-inputs %build-host-inputs
  145. #:search-paths '#$(map search-path-specification->sexp
  146. search-paths)
  147. #:native-search-paths '#$(map
  148. search-path-specification->sexp
  149. native-search-paths)
  150. #:make-dynamic-linker-cache? #f ;cross-compiling
  151. #:phases #$phases))))
  152. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  153. system #:graft? #f)))
  154. (gexp->derivation name builder
  155. #:system system
  156. #:target target
  157. #:graft? #f
  158. #:guile-for-build guile)))
  159. (define guile-build-system
  160. (build-system
  161. (name 'guile)
  162. (description "The build system for simple Guile packages")
  163. (lower lower)))