gnu: esbuild: Update to 0.11.14.
[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? #t)
79 (phases '(@ (guix build julia-build-system)
80 %standard-phases))
81 (outputs '("out"))
82 (search-paths '())
83 (system (%current-system))
84 (guile #f)
85 (julia-package-name #f)
86 (imported-modules %julia-build-system-modules)
87 (modules '((guix build julia-build-system)
88 (guix build utils))))
89 "Build SOURCE using Julia, and with INPUTS."
90 (define builder
91 `(begin
92 (use-modules ,@modules)
93 (julia-build #:name ,name
94 #:source ,(match (assoc-ref inputs "source")
95 (((? derivation? source))
96 (derivation->output-path source))
97 ((source)
98 source)
99 (source
100 source))
101 #:system ,system
102 #:tests? ,tests?
103 #:phases ,phases
104 #:outputs %outputs
105 #:search-paths ',(map search-path-specification->sexp
106 search-paths)
107 #:inputs %build-inputs
108 #:julia-package-name ,julia-package-name)))
109
110 (define guile-for-build
111 (match guile
112 ((? package?)
113 (package-derivation store guile system #:graft? #f))
114 (#f ; the default
115 (let* ((distro (resolve-interface '(gnu packages commencement)))
116 (guile (module-ref distro 'guile-final)))
117 (package-derivation store guile system #:graft? #f)))))
118
119 (build-expression->derivation store name builder
120 #:inputs inputs
121 #:system system
122 #:modules imported-modules
123 #:outputs outputs
124 #:guile-for-build guile-for-build))
125
126 (define julia-build-system
127 (build-system
128 (name 'julia)
129 (description "The build system for Julia packages")
130 (lower lower)))
131
132 ;;; julia.scm ends here