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