r.scm 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2015, 2017, 2018, 2019, 2020 Ricardo Wurmus <rekado@elephly.net>
  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 r)
  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 (%r-build-system-modules
  29. r-build
  30. r-build-system
  31. cran-uri
  32. bioconductor-uri))
  33. ;; Commentary:
  34. ;;
  35. ;; Standard build procedure for R packages.
  36. ;;
  37. ;; Code:
  38. (define (cran-uri name version)
  39. "Return a list of URI strings for the R package archive on CRAN for the
  40. release corresponding to NAME and VERSION. As only the most recent version is
  41. available via the first URI, the second URI points to the archived version."
  42. (list (string-append "mirror://cran/src/contrib/"
  43. name "_" version ".tar.gz")
  44. (string-append "mirror://cran/src/contrib/Archive/"
  45. name "/" name "_" version ".tar.gz")))
  46. (define* (bioconductor-uri name version #:optional type)
  47. "Return a URI string for the R package archive on Bioconductor for the
  48. release corresponding to NAME and VERSION."
  49. (let ((type-url-part (match type
  50. ('annotation "/data/annotation")
  51. ('experiment "/data/experiment")
  52. (_ "/bioc"))))
  53. (list (string-append "https://bioconductor.org/packages/release"
  54. type-url-part
  55. "/src/contrib/"
  56. name "_" version ".tar.gz")
  57. ;; TODO: use %bioconductor-version from (guix import cran)
  58. (string-append "https://bioconductor.org/packages/3.12"
  59. type-url-part
  60. "/src/contrib/"
  61. name "_" version ".tar.gz"))))
  62. (define %r-build-system-modules
  63. ;; Build-side modules imported by default.
  64. `((guix build r-build-system)
  65. ,@%gnu-build-system-modules))
  66. (define (default-r)
  67. "Return the default R package."
  68. ;; Lazily resolve the binding to avoid a circular dependency.
  69. (let ((r-mod (resolve-interface '(gnu packages statistics))))
  70. (module-ref r-mod 'r-minimal)))
  71. (define* (lower name
  72. #:key source inputs native-inputs outputs system target
  73. (r (default-r))
  74. #:allow-other-keys
  75. #:rest arguments)
  76. "Return a bag for NAME."
  77. (define private-keywords
  78. '(#:source #:target #:r #:inputs #:native-inputs))
  79. (and (not target) ;XXX: no cross-compilation
  80. (bag
  81. (name name)
  82. (system system)
  83. (host-inputs `(,@(if source
  84. `(("source" ,source))
  85. '())
  86. ,@inputs
  87. ;; Keep the standard inputs of 'gnu-build-system'.
  88. ,@(standard-packages)))
  89. (build-inputs `(("r" ,r)
  90. ,@native-inputs))
  91. (outputs outputs)
  92. (build r-build)
  93. (arguments (strip-keyword-arguments private-keywords arguments)))))
  94. (define* (r-build store name inputs
  95. #:key
  96. (tests? #t)
  97. (test-target "tests")
  98. (configure-flags ''())
  99. (phases '(@ (guix build r-build-system)
  100. %standard-phases))
  101. (outputs '("out"))
  102. (search-paths '())
  103. (system (%current-system))
  104. (guile #f)
  105. (substitutable? #t)
  106. (imported-modules %r-build-system-modules)
  107. (modules '((guix build r-build-system)
  108. (guix build utils))))
  109. "Build SOURCE with INPUTS."
  110. (define builder
  111. `(begin
  112. (use-modules ,@modules)
  113. (r-build #:name ,name
  114. #:source ,(match (assoc-ref inputs "source")
  115. (((? derivation? source))
  116. (derivation->output-path source))
  117. ((source)
  118. source)
  119. (source
  120. source))
  121. #:configure-flags ,configure-flags
  122. #:system ,system
  123. #:tests? ,tests?
  124. #:test-target ,test-target
  125. #:phases ,phases
  126. #:outputs %outputs
  127. #:search-paths ',(map search-path-specification->sexp
  128. search-paths)
  129. #:inputs %build-inputs)))
  130. (define guile-for-build
  131. (match guile
  132. ((? package?)
  133. (package-derivation store guile system #:graft? #f))
  134. (#f ; the default
  135. (let* ((distro (resolve-interface '(gnu packages commencement)))
  136. (guile (module-ref distro 'guile-final)))
  137. (package-derivation store guile system #:graft? #f)))))
  138. (build-expression->derivation store name builder
  139. #:inputs inputs
  140. #:system system
  141. #:modules imported-modules
  142. #:outputs outputs
  143. #:guile-for-build guile-for-build
  144. #:substitutable? substitutable?))
  145. (define r-build-system
  146. (build-system
  147. (name 'r)
  148. (description "The standard R build system")
  149. (lower lower)))
  150. ;;; r.scm ends here