dune.scm 6.4 KB

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