gnu: emacs-org: Update to 9.4.
[jackhill/guix/guix.git] / guix / build-system / dune.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016, 2017, 2018 Julien Lepiller <julien@lepiller.eu>
3 ;;; Copyright © 2017 Ben Woodcroft <donttrustben@gmail.com>
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
20 (define-module (guix build-system dune)
21 #:use-module (guix store)
22 #:use-module (guix utils)
23 #:use-module (guix derivations)
24 #:use-module (guix search-paths)
25 #:use-module (guix build-system)
26 #:use-module ((guix build-system gnu) #:prefix gnu:)
27 #:use-module ((guix build-system ocaml) #:prefix ocaml:)
28 #:use-module (guix packages)
29 #:use-module (ice-9 match)
30 #:use-module (srfi srfi-1)
31 #:export (%dune-build-system-modules
32 dune-build
33 dune-build-system))
34
35 ;; Commentary:
36 ;;
37 ;; Standard build procedure for packages using dune. This is implemented as an
38 ;; extension of `ocaml-build-system'.
39 ;;
40 ;; Code:
41
42 (define %dune-build-system-modules
43 ;; Build-side modules imported by default.
44 `((guix build dune-build-system)
45 ,@ocaml:%ocaml-build-system-modules))
46
47 (define (default-dune)
48 "Return the default OCaml package."
49
50 ;; Do not use `@' to avoid introducing circular dependencies.
51 (let ((module (resolve-interface '(gnu packages ocaml))))
52 (module-ref module 'dune)))
53
54 (define* (lower name
55 #:key source inputs native-inputs outputs system target
56 (dune (default-dune))
57 (ocaml (ocaml:default-ocaml))
58 (findlib (ocaml:default-findlib))
59 #:allow-other-keys
60 #:rest arguments)
61 "Return a bag for NAME."
62 (define private-keywords
63 '(#:source #:target #:dune #:findlib #:ocaml #:inputs #:native-inputs))
64
65 (and (not target) ;XXX: no cross-compilation
66 (let ((base (ocaml:lower name
67 #:source source
68 #:inputs inputs
69 #:native-inputs native-inputs
70 #:outputs outputs
71 #:system system
72 #:target target
73 #:ocaml ocaml
74 #:findlib findlib
75 arguments)))
76 (bag
77 (inherit base)
78 (build-inputs `(("dune" ,dune)
79 ,@(bag-build-inputs base)))
80 (build dune-build)
81 (arguments (strip-keyword-arguments private-keywords arguments))))))
82
83 (define* (dune-build store name inputs
84 #:key (guile #f)
85 (outputs '("out"))
86 (search-paths '())
87 (build-flags ''())
88 (out-of-source? #t)
89 (jbuild? #f)
90 (package #f)
91 (tests? #t)
92 (test-flags ''())
93 (test-target "test")
94 (install-target "install")
95 (validate-runpath? #t)
96 (patch-shebangs? #t)
97 (strip-binaries? #t)
98 (strip-flags ''("--strip-debug"))
99 (strip-directories ''("lib" "lib64" "libexec"
100 "bin" "sbin"))
101 (phases '(@ (guix build dune-build-system)
102 %standard-phases))
103 (system (%current-system))
104 (imported-modules %dune-build-system-modules)
105 (modules '((guix build dune-build-system)
106 (guix build utils))))
107 "Build SOURCE using OCAML, and with INPUTS. This assumes that SOURCE
108 provides a 'setup.ml' file as its build system."
109 (define builder
110 `(begin
111 (use-modules ,@modules)
112 (dune-build #:source ,(match (assoc-ref inputs "source")
113 (((? derivation? source))
114 (derivation->output-path source))
115 ((source)
116 source)
117 (source
118 source))
119 #:system ,system
120 #:outputs %outputs
121 #:inputs %build-inputs
122 #:search-paths ',(map search-path-specification->sexp
123 search-paths)
124 #:phases ,phases
125 #:test-flags ,test-flags
126 #:build-flags ,build-flags
127 #:out-of-source? ,out-of-source?
128 #:jbuild? ,jbuild?
129 #:package ,package
130 #:tests? ,tests?
131 #:test-target ,test-target
132 #:install-target ,install-target
133 #:validate-runpath? ,validate-runpath?
134 #:patch-shebangs? ,patch-shebangs?
135 #:strip-binaries? ,strip-binaries?
136 #:strip-flags ,strip-flags
137 #:strip-directories ,strip-directories)))
138
139 (define guile-for-build
140 (match guile
141 ((? package?)
142 (package-derivation store guile system #:graft? #f))
143 (#f ; the default
144 (let* ((distro (resolve-interface '(gnu packages commencement)))
145 (guile (module-ref distro 'guile-final)))
146 (package-derivation store guile system #:graft? #f)))))
147
148 (build-expression->derivation store name builder
149 #:system system
150 #:inputs inputs
151 #:modules imported-modules
152 #:outputs outputs
153 #:guile-for-build guile-for-build))
154
155 (define dune-build-system
156 (build-system
157 (name 'dune)
158 (description "The standard Dune build system")
159 (lower lower)))
160
161 ;;; dune.scm ends here