r.scm 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2015, 2017, 2018, 2019, 2020 Ricardo Wurmus <rekado@elephly.net>
  3. ;;; Copyright © 2021 Ludovic Courtès <ludo@gnu.org>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (guix build-system r)
  20. #:use-module (guix store)
  21. #:use-module (guix utils)
  22. #:use-module (guix packages)
  23. #:use-module (guix gexp)
  24. #:use-module (guix monads)
  25. #:use-module (guix search-paths)
  26. #:use-module (guix build-system)
  27. #:use-module (guix build-system gnu)
  28. #:use-module (ice-9 match)
  29. #:use-module (srfi srfi-26)
  30. #:export (%r-build-system-modules
  31. r-build
  32. r-build-system
  33. cran-uri
  34. bioconductor-uri))
  35. ;; Commentary:
  36. ;;
  37. ;; Standard build procedure for R packages.
  38. ;;
  39. ;; Code:
  40. (define (cran-uri name version)
  41. "Return a list of URI strings for the R package archive on CRAN for the
  42. release corresponding to NAME and VERSION. As only the most recent version is
  43. available via the first URI, the second URI points to the archived version."
  44. (list (string-append "mirror://cran/src/contrib/"
  45. name "_" version ".tar.gz")
  46. (string-append "mirror://cran/src/contrib/Archive/"
  47. name "/" name "_" version ".tar.gz")))
  48. (define* (bioconductor-uri name version #:optional type)
  49. "Return a URI string for the R package archive on Bioconductor for the
  50. release corresponding to NAME and VERSION."
  51. (let ((type-url-part (match type
  52. ('annotation "/data/annotation")
  53. ('experiment "/data/experiment")
  54. (_ "/bioc"))))
  55. (list (string-append "https://bioconductor.org/packages/release"
  56. type-url-part
  57. "/src/contrib/"
  58. name "_" version ".tar.gz")
  59. ;; TODO: use %bioconductor-version from (guix import cran)
  60. (string-append "https://bioconductor.org/packages/3.12"
  61. type-url-part
  62. "/src/contrib/"
  63. name "_" version ".tar.gz"))))
  64. (define %r-build-system-modules
  65. ;; Build-side modules imported by default.
  66. `((guix build r-build-system)
  67. ,@%gnu-build-system-modules))
  68. (define (default-r)
  69. "Return the default R package."
  70. ;; Lazily resolve the binding to avoid a circular dependency.
  71. (let ((r-mod (resolve-interface '(gnu packages statistics))))
  72. (module-ref r-mod 'r-minimal)))
  73. (define* (lower name
  74. #:key source inputs native-inputs outputs system target
  75. (r (default-r))
  76. #:allow-other-keys
  77. #:rest arguments)
  78. "Return a bag for NAME."
  79. (define private-keywords
  80. '(#:target #:r #:inputs #:native-inputs))
  81. (and (not target) ;XXX: no cross-compilation
  82. (bag
  83. (name name)
  84. (system system)
  85. (host-inputs `(,@(if source
  86. `(("source" ,source))
  87. '())
  88. ,@inputs
  89. ;; Keep the standard inputs of 'gnu-build-system'.
  90. ,@(standard-packages)))
  91. (build-inputs `(("r" ,r)
  92. ,@native-inputs))
  93. (outputs outputs)
  94. (build r-build)
  95. (arguments (strip-keyword-arguments private-keywords arguments)))))
  96. (define* (r-build name inputs
  97. #:key
  98. source
  99. (tests? #t)
  100. (test-target "tests")
  101. (configure-flags ''())
  102. (phases '%standard-phases)
  103. (outputs '("out"))
  104. (search-paths '())
  105. (system (%current-system))
  106. (guile #f)
  107. (substitutable? #t)
  108. (imported-modules %r-build-system-modules)
  109. (modules '((guix build r-build-system)
  110. (guix build utils))))
  111. "Build SOURCE with INPUTS."
  112. (define builder
  113. (with-imported-modules imported-modules
  114. #~(begin
  115. (use-modules #$@(sexp->gexp modules))
  116. (r-build #:name #$name
  117. #:source #+source
  118. #:configure-flags #$configure-flags
  119. #:system #$system
  120. #:tests? #$tests?
  121. #:test-target #$test-target
  122. #:phases #$phases
  123. #:outputs #$(outputs->gexp outputs)
  124. #:search-paths '#$(sexp->gexp
  125. (map search-path-specification->sexp
  126. search-paths))
  127. #:inputs #$(input-tuples->gexp inputs)))))
  128. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  129. system #:graft? #f)))
  130. (gexp->derivation name builder
  131. #:system system
  132. #:guile-for-build guile
  133. #:substitutable? substitutable?)))
  134. (define r-build-system
  135. (build-system
  136. (name 'r)
  137. (description "The standard R build system")
  138. (lower lower)))
  139. ;;; r.scm ends here