summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am2
-rw-r--r--doc/guix.texi21
-rw-r--r--guix/build-system/dune.scm159
-rw-r--r--guix/build-system/ocaml.scm16
-rw-r--r--guix/build/dune-build-system.scm69
5 files changed, 265 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am
index 4a190c4095..0e5ca02ed3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -107,6 +107,7 @@ MODULES = \
guix/build-system/clojure.scm \
guix/build-system/cmake.scm \
guix/build-system/dub.scm \
+ guix/build-system/dune.scm \
guix/build-system/emacs.scm \
guix/build-system/font.scm \
guix/build-system/go.scm \
@@ -144,6 +145,7 @@ MODULES = \
guix/build/cargo-build-system.scm \
guix/build/cmake-build-system.scm \
guix/build/dub-build-system.scm \
+ guix/build/dune-build-system.scm \
guix/build/emacs-build-system.scm \
guix/build/meson-build-system.scm \
guix/build/minify-build-system.scm \
diff --git a/doc/guix.texi b/doc/guix.texi
index 6c5324ee0b..8f6a8b3ed2 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -4512,6 +4512,27 @@ debugging information''), which roughly means that code is compiled with
@code{-O2 -g}, as is the case for Autoconf-based packages by default.
@end defvr
+@defvr {Scheme Variable} dune-build-system
+This variable is exported by @code{(guix build-system dune)}. It
+supports builds of packages using @uref{https://dune.build/, Dune}, a build
+tool for the OCaml programming language. It is implemented as an extension
+of the @code{ocaml-build-system} which is described below. As such, the
+@code{#:ocaml} and @code{#:findlib} parameters can be passed to this build
+system.
+
+It automatically adds the @code{dune} package to the set of inputs.
+Which package is used can be specified with the @code{#:dune}
+parameter.
+
+There is no @code{configure} phase because dune packages typically don't
+need to be configured. The @code{#:build-flags} parameter is taken as a
+list of flags passed to the @code{dune} command during the build.
+
+The @code{#:jbuild?} parameter can be passed to use the @code{jbuild}
+command instead of the more recent @code{dune} command while building
+a package. Its default value is @code{#f}.
+@end defvr
+
@defvr {Scheme Variable} go-build-system
This variable is exported by @code{(guix build-system go)}. It
implements a build procedure for Go packages using the standard
diff --git a/guix/build-system/dune.scm b/guix/build-system/dune.scm
new file mode 100644
index 0000000000..8bd41c89f0
--- /dev/null
+++ b/guix/build-system/dune.scm
@@ -0,0 +1,159 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2016, 2017, 2018 Julien Lepiller <julien@lepiller.eu>
+;;; Copyright © 2017 Ben Woodcroft <donttrustben@gmail.com>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (guix build-system dune)
+ #:use-module (guix store)
+ #:use-module (guix utils)
+ #:use-module (guix derivations)
+ #:use-module (guix search-paths)
+ #:use-module (guix build-system)
+ #:use-module ((guix build-system gnu) #:prefix gnu:)
+ #:use-module ((guix build-system ocaml) #:prefix ocaml:)
+ #:use-module (guix packages)
+ #:use-module (ice-9 match)
+ #:use-module (srfi srfi-1)
+ #:export (%dune-build-system-modules
+ dune-build
+ dune-build-system))
+
+;; Commentary:
+;;
+;; Standard build procedure for packages using dune. This is implemented as an
+;; extension of `ocaml-build-system'.
+;;
+;; Code:
+
+(define %dune-build-system-modules
+ ;; Build-side modules imported by default.
+ `((guix build dune-build-system)
+ ,@ocaml:%ocaml-build-system-modules))
+
+(define (default-dune)
+ "Return the default OCaml package."
+
+ ;; Do not use `@' to avoid introducing circular dependencies.
+ (let ((module (resolve-interface '(gnu packages ocaml))))
+ (module-ref module 'dune)))
+
+(define* (lower name
+ #:key source inputs native-inputs outputs system target
+ (dune (default-dune))
+ (ocaml (ocaml:default-ocaml))
+ (findlib (ocaml:default-findlib))
+ #:allow-other-keys
+ #:rest arguments)
+ "Return a bag for NAME."
+ (define private-keywords
+ '(#:source #:target #:dune #:findlib #:ocaml #:inputs #:native-inputs))
+
+ (and (not target) ;XXX: no cross-compilation
+ (let ((base (ocaml:lower name
+ #:source source
+ #:inputs inputs
+ #:native-inputs native-inputs
+ #:outputs outputs
+ #:system system
+ #:target target
+ #:ocaml ocaml
+ #:findlib findlib
+ arguments)))
+ (bag
+ (inherit base)
+ (build-inputs `(("dune" ,dune)
+ ,@(bag-build-inputs base)))
+ (build dune-build)
+ (arguments (strip-keyword-arguments private-keywords arguments))))))
+
+(define* (dune-build store name inputs
+ #:key (guile #f)
+ (outputs '("out"))
+ (search-paths '())
+ (build-flags ''())
+ (out-of-source? #t)
+ (jbuild? #f)
+ (tests? #t)
+ (test-flags ''())
+ (test-target "test")
+ (install-target "install")
+ (validate-runpath? #t)
+ (patch-shebangs? #t)
+ (strip-binaries? #t)
+ (strip-flags ''("--strip-debug"))
+ (strip-directories ''("lib" "lib64" "libexec"
+ "bin" "sbin"))
+ (phases '(@ (guix build dune-build-system)
+ %standard-phases))
+ (system (%current-system))
+ (imported-modules %dune-build-system-modules)
+ (modules '((guix build dune-build-system)
+ (guix build utils))))
+ "Build SOURCE using OCAML, and with INPUTS. This assumes that SOURCE
+provides a 'setup.ml' file as its build system."
+ (define builder
+ `(begin
+ (use-modules ,@modules)
+ (dune-build #:source ,(match (assoc-ref inputs "source")
+ (((? derivation? source))
+ (derivation->output-path source))
+ ((source)
+ source)
+ (source
+ source))
+ #:system ,system
+ #:outputs %outputs
+ #:inputs %build-inputs
+ #:search-paths ',(map search-path-specification->sexp
+ search-paths)
+ #:phases ,phases
+ #:test-flags ,test-flags
+ #:build-flags ,build-flags
+ #:out-of-source? ,out-of-source?
+ #:jbuild? ,jbuild?
+ #:tests? ,tests?
+ #:test-target ,test-target
+ #:install-target ,install-target
+ #:validate-runpath? ,validate-runpath?
+ #:patch-shebangs? ,patch-shebangs?
+ #:strip-binaries? ,strip-binaries?
+ #:strip-flags ,strip-flags
+ #:strip-directories ,strip-directories)))
+
+ (define guile-for-build
+ (match guile
+ ((? package?)
+ (package-derivation store guile system #:graft? #f))
+ (#f ; the default
+ (let* ((distro (resolve-interface '(gnu packages commencement)))
+ (guile (module-ref distro 'guile-final)))
+ (package-derivation store guile system #:graft? #f)))))
+
+ (build-expression->derivation store name builder
+ #:system system
+ #:inputs inputs
+ #:modules imported-modules
+ #:outputs outputs
+ #:guile-for-build guile-for-build))
+
+(define dune-build-system
+ (build-system
+ (name 'dune)
+ (description "The standard Dune build system")
+ (lower lower)))
+
+;;; dune.scm ends here
diff --git a/guix/build-system/ocaml.scm b/guix/build-system/ocaml.scm
index e5b715f55d..07c69fac76 100644
--- a/guix/build-system/ocaml.scm
+++ b/guix/build-system/ocaml.scm
@@ -31,6 +31,9 @@
package-with-ocaml4.02
strip-ocaml4.01-variant
strip-ocaml4.02-variant
+ default-findlib
+ default-ocaml
+ lower
ocaml-build
ocaml-build-system))
@@ -76,6 +79,13 @@
(let ((module (resolve-interface '(gnu packages ocaml))))
(module-ref module 'ocaml-findlib)))
+(define (default-dune-build-system)
+ "Return the dune-build-system."
+
+ ;; Do not use `@' to avoid introducing circular dependencies.
+ (let ((module (resolve-interface '(guix build-system dune))))
+ (module-ref module 'dune-build-system)))
+
(define (default-ocaml4.01)
(let ((ocaml (resolve-interface '(gnu packages ocaml))))
(module-ref ocaml 'ocaml-4.01)))
@@ -119,7 +129,8 @@ pre-defined variants."
=> force)
;; Otherwise build the new package object graph.
- ((eq? (package-build-system p) ocaml-build-system)
+ ((or (eq? (package-build-system p) ocaml-build-system)
+ (eq? (package-build-system p) (default-dune-build-system)))
(package
(inherit p)
(location (package-location p))
@@ -138,7 +149,8 @@ pre-defined variants."
(else p)))
(define (cut? p)
- (or (not (eq? (package-build-system p) ocaml-build-system))
+ (or (not (or (eq? (package-build-system p) ocaml-build-system)
+ (eq? (package-build-system p) (default-dune-build-system))))
(package-variant p)))
(package-mapping transform cut?))
diff --git a/guix/build/dune-build-system.scm b/guix/build/dune-build-system.scm
new file mode 100644
index 0000000000..fcc2d6567d
--- /dev/null
+++ b/guix/build/dune-build-system.scm
@@ -0,0 +1,69 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2018 Julien Lepiller <julien@lepiller.eu>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (guix build dune-build-system)
+ #:use-module ((guix build ocaml-build-system) #:prefix ocaml:)
+ #:use-module (guix build utils)
+ #:use-module (ice-9 match)
+ #:export (%standard-phases
+ dune-build))
+
+;; Commentary:
+;;
+;; Builder-side code of the standard dune build procedure.
+;;
+;; Code:
+
+(define* (build #:key (build-flags '()) (jbuild? #f)
+ (use-make? #f) #:allow-other-keys)
+ "Build the given package."
+ (let ((program (if jbuild? "jbuilder" "dune")))
+ (apply invoke program "build" "@install" build-flags))
+ #t)
+
+(define* (check #:key (test-flags '()) (test-target "test") tests?
+ (jbuild? #f) #:allow-other-keys)
+ "Test the given package."
+ (when tests?
+ (let ((program (if jbuild? "jbuilder" "dune")))
+ (apply invoke program "runtest" test-target test-flags)))
+ #t)
+
+(define* (install #:key outputs (install-target "install") (jbuild? #f)
+ #:allow-other-keys)
+ "Install the given package."
+ (let ((out (assoc-ref outputs "out"))
+ (program (if jbuild? "jbuilder" "dune")))
+ (invoke program install-target "--prefix" out))
+ #t)
+
+(define %standard-phases
+ ;; Everything is as with the GNU Build System except for the `configure'
+ ;; , `build', `check' and `install' phases.
+ (modify-phases ocaml:%standard-phases
+ (delete 'configure)
+ (replace 'build build)
+ (replace 'check check)
+ (replace 'install install)))
+
+(define* (dune-build #:key inputs (phases %standard-phases)
+ #:allow-other-keys #:rest args)
+ "Build the given package, applying all of PHASES in order."
+ (apply ocaml:ocaml-build #:inputs inputs #:phases phases args))
+
+;;; dune-build-system.scm ends here