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>
5 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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
37 ;; Standard build procedure for packages using dune. This is implemented as an
38 ;; extension of `ocaml-build-system'.
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))
47 (define (default-dune)
48 "Return the default OCaml package."
50 ;; Do not use `@' to avoid introducing circular dependencies.
51 (let ((module (resolve-interface '(gnu packages ocaml))))
52 (module-ref module 'dune)))
55 #:key source inputs native-inputs outputs system target
57 (ocaml (ocaml:default-ocaml))
58 (findlib (ocaml:default-findlib))
61 "Return a bag for NAME."
62 (define private-keywords
63 '(#:source #:target #:dune #:findlib #:ocaml #:inputs #:native-inputs))
65 (and (not target) ;XXX: no cross-compilation
66 (let ((base (ocaml:lower name
69 #:native-inputs native-inputs
78 (build-inputs `(("dune" ,dune)
79 ,@(bag-build-inputs base)))
81 (arguments (strip-keyword-arguments private-keywords arguments))))))
83 (define* (dune-build store name inputs
94 (install-target "install")
95 (validate-runpath? #t)
98 (strip-flags ''("--strip-debug"))
99 (strip-directories ''("lib" "lib64" "libexec"
101 (phases '(@ (guix build dune-build-system)
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."
111 (use-modules ,@modules)
112 (dune-build #:source ,(match (assoc-ref inputs "source")
113 (((? derivation? source))
114 (derivation->output-path source))
121 #:inputs %build-inputs
122 #:search-paths ',(map search-path-specification->sexp
125 #:test-flags ,test-flags
126 #:build-flags ,build-flags
127 #:out-of-source? ,out-of-source?
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)))
139 (define guile-for-build
142 (package-derivation store guile system #:graft? #f))
144 (let* ((distro (resolve-interface '(gnu packages commencement)))
145 (guile (module-ref distro 'guile-final)))
146 (package-derivation store guile system #:graft? #f)))))
148 (build-expression->derivation store name builder
151 #:modules imported-modules
153 #:guile-for-build guile-for-build))
155 (define dune-build-system
158 (description "The standard Dune build system")
161 ;;; dune.scm ends here