r.scm 5.7 KB

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