guile.scm 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2018, 2019 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 derivations)
  23. #:use-module (guix search-paths)
  24. #:use-module (guix build-system)
  25. #:use-module (guix build-system gnu)
  26. #:use-module (ice-9 match)
  27. #:use-module (srfi srfi-26)
  28. #:export (%guile-build-system-modules
  29. guile-build-system))
  30. (define %guile-build-system-modules
  31. ;; Build-side modules imported by default.
  32. `((guix build guile-build-system)
  33. ,@%gnu-build-system-modules))
  34. (define* (lower name
  35. #:key source inputs native-inputs outputs system target
  36. (implicit-inputs? #t)
  37. #:allow-other-keys
  38. #:rest arguments)
  39. "Return a bag for NAME."
  40. ;; Note: There's no #:guile argument (unlike, for instance,
  41. ;; 'ocaml-build-system' which has #:ocaml.) This is so we can keep
  42. ;; procedures like 'package-for-guile-2.0' unchanged and simple.
  43. (define private-keywords
  44. '(#:target #:inputs #:native-inputs
  45. #:implicit-inputs?))
  46. (bag
  47. (name name)
  48. (system system) (target target)
  49. (host-inputs `(
  50. ,@inputs))
  51. (build-inputs `(,@(if source
  52. `(("source" ,source))
  53. '())
  54. ,@native-inputs
  55. ,@(if implicit-inputs?
  56. (map (cute assoc <> (standard-packages))
  57. '("tar" "gzip" "bzip2" "xz" "locales"))
  58. '())))
  59. (outputs outputs)
  60. (build (if target guile-cross-build guile-build))
  61. (arguments (strip-keyword-arguments private-keywords arguments))))
  62. (define %compile-flags
  63. ;; Flags passed to 'guild compile' by default. We choose a common
  64. ;; denominator between Guile 2.0 and 2.2.
  65. ''("-Wunbound-variable" "-Warity-mismatch" "-Wformat"))
  66. (define* (guile-build store name inputs
  67. #:key source
  68. (guile #f)
  69. (phases '%standard-phases)
  70. (outputs '("out"))
  71. (search-paths '())
  72. (system (%current-system))
  73. (source-directory ".")
  74. not-compiled-file-regexp
  75. (compile-flags %compile-flags)
  76. (imported-modules %guile-build-system-modules)
  77. (modules '((guix build guile-build-system)
  78. (guix build utils))))
  79. "Build SOURCE using Guile taken from the native inputs, and with INPUTS."
  80. (define builder
  81. `(begin
  82. (use-modules ,@modules)
  83. (guile-build #:name ,name
  84. #:source ,(match (assoc-ref inputs "source")
  85. (((? derivation? source))
  86. (derivation->output-path source))
  87. ((source)
  88. source)
  89. (source
  90. source))
  91. #:source-directory ,source-directory
  92. #:not-compiled-file-regexp ,not-compiled-file-regexp
  93. #:compile-flags ,compile-flags
  94. #:phases ,phases
  95. #:system ,system
  96. #:outputs %outputs
  97. #:search-paths ',(map search-path-specification->sexp
  98. search-paths)
  99. #:inputs %build-inputs)))
  100. (define guile-for-build
  101. (match guile
  102. ((? package?)
  103. (package-derivation store guile system #:graft? #f))
  104. (#f ; the default
  105. (let* ((distro (resolve-interface '(gnu packages commencement)))
  106. (guile (module-ref distro 'guile-final)))
  107. (package-derivation store guile system #:graft? #f)))))
  108. (build-expression->derivation store name builder
  109. #:inputs inputs
  110. #:system system
  111. #:modules imported-modules
  112. #:outputs outputs
  113. #:guile-for-build guile-for-build))
  114. (define* (guile-cross-build store name
  115. #:key
  116. (system (%current-system)) target
  117. native-drvs target-drvs
  118. (guile #f)
  119. source
  120. (outputs '("out"))
  121. (search-paths '())
  122. (native-search-paths '())
  123. (phases '%standard-phases)
  124. (source-directory ".")
  125. not-compiled-file-regexp
  126. (compile-flags %compile-flags)
  127. (imported-modules %guile-build-system-modules)
  128. (modules '((guix build guile-build-system)
  129. (guix build utils))))
  130. (define builder
  131. `(begin
  132. (use-modules ,@modules)
  133. (let ()
  134. (define %build-host-inputs
  135. ',(map (match-lambda
  136. ((name (? derivation? drv) sub ...)
  137. `(,name . ,(apply derivation->output-path drv sub)))
  138. ((name path)
  139. `(,name . ,path)))
  140. native-drvs))
  141. (define %build-target-inputs
  142. ',(map (match-lambda
  143. ((name (? derivation? drv) sub ...)
  144. `(,name . ,(apply derivation->output-path drv sub)))
  145. ((name (? package? pkg) sub ...)
  146. (let ((drv (package-cross-derivation store pkg
  147. target system)))
  148. `(,name . ,(apply derivation->output-path drv sub))))
  149. ((name path)
  150. `(,name . ,path)))
  151. target-drvs))
  152. (guile-build #:source ,(match (assoc-ref native-drvs "source")
  153. (((? derivation? source))
  154. (derivation->output-path source))
  155. ((source)
  156. source)
  157. (source
  158. source))
  159. #:system ,system
  160. #:target ,target
  161. #:outputs %outputs
  162. #:source-directory ,source-directory
  163. #:not-compiled-file-regexp ,not-compiled-file-regexp
  164. #:compile-flags ,compile-flags
  165. #:inputs %build-target-inputs
  166. #:native-inputs %build-host-inputs
  167. #:search-paths ',(map search-path-specification->sexp
  168. search-paths)
  169. #:native-search-paths ',(map
  170. search-path-specification->sexp
  171. native-search-paths)
  172. #:phases ,phases))))
  173. (define guile-for-build
  174. (match guile
  175. ((? package?)
  176. (package-derivation store guile system #:graft? #f))
  177. (#f ; the default
  178. (let* ((distro (resolve-interface '(gnu packages commencement)))
  179. (guile (module-ref distro 'guile-final)))
  180. (package-derivation store guile system #:graft? #f)))))
  181. (build-expression->derivation store name builder
  182. #:system system
  183. #:inputs (append native-drvs target-drvs)
  184. #:outputs outputs
  185. #:modules imported-modules
  186. #:substitutable? substitutable?
  187. #:guile-for-build guile-for-build))
  188. (define guile-build-system
  189. (build-system
  190. (name 'guile)
  191. (description "The build system for simple Guile packages")
  192. (lower lower)))