julia.scm 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2019 Nicolò Balzarotti <nicolo@nixo.xyz>
  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 julia)
  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 (%julia-build-system-modules
  29. julia-build
  30. julia-build-system))
  31. ;; Commentary:
  32. ;;
  33. ;; Standard build procedure for Julia packages.
  34. ;;
  35. ;; Code:
  36. (define %julia-build-system-modules
  37. ;; Build-side modules imported by default.
  38. `((guix build julia-build-system)
  39. ,@%gnu-build-system-modules))
  40. (define (default-julia)
  41. "Return the default Julia package."
  42. ;; Lazily resolve the binding to avoid a circular dependency.
  43. (let ((julia-mod (resolve-interface '(gnu packages julia))))
  44. (module-ref julia-mod 'julia)))
  45. (define* (lower name
  46. #:key source inputs native-inputs outputs system target
  47. (julia (default-julia))
  48. #:allow-other-keys
  49. #:rest arguments)
  50. "Return a bag for NAME."
  51. (define private-keywords
  52. '(#:target #:julia #:inputs #:native-inputs))
  53. (and (not target) ;XXX: no cross-compilation
  54. (bag
  55. (name name)
  56. (system system)
  57. (host-inputs `(,@(if source
  58. `(("source" ,source))
  59. '())
  60. ,@inputs
  61. ;; Keep the standard inputs of 'gnu-build-system'.
  62. ,@(standard-packages)))
  63. (build-inputs `(("julia" ,julia)
  64. ,@native-inputs))
  65. (outputs outputs)
  66. (build julia-build)
  67. (arguments (strip-keyword-arguments private-keywords arguments)))))
  68. (define* (julia-build store name inputs
  69. #:key source
  70. (tests? #t)
  71. (phases '(@ (guix build julia-build-system)
  72. %standard-phases))
  73. (outputs '("out"))
  74. (search-paths '())
  75. (system (%current-system))
  76. (guile #f)
  77. (julia-package-name #f)
  78. (imported-modules %julia-build-system-modules)
  79. (modules '((guix build julia-build-system)
  80. (guix build utils))))
  81. "Build SOURCE using Julia, and with INPUTS."
  82. (define builder
  83. `(begin
  84. (use-modules ,@modules)
  85. (julia-build #:name ,name
  86. #:source ,(match (assoc-ref inputs "source")
  87. (((? derivation? source))
  88. (derivation->output-path source))
  89. ((source)
  90. source)
  91. (source
  92. source))
  93. #:system ,system
  94. #:tests? ,tests?
  95. #:phases ,phases
  96. #:outputs %outputs
  97. #:search-paths ',(map search-path-specification->sexp
  98. search-paths)
  99. #:inputs %build-inputs
  100. #:julia-package-name ,julia-package-name)))
  101. (define guile-for-build
  102. (match guile
  103. ((? package?)
  104. (package-derivation store guile system #:graft? #f))
  105. (#f ; the default
  106. (let* ((distro (resolve-interface '(gnu packages commencement)))
  107. (guile (module-ref distro 'guile-final)))
  108. (package-derivation store guile system #:graft? #f)))))
  109. (build-expression->derivation store name builder
  110. #:inputs inputs
  111. #:system system
  112. #:modules imported-modules
  113. #:outputs outputs
  114. #:guile-for-build guile-for-build))
  115. (define julia-build-system
  116. (build-system
  117. (name 'julia)
  118. (description "The build system for Julia packages")
  119. (lower lower)))
  120. ;;; julia.scm ends here