dune.scm 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. ;;; Copyright © 2021, 2022 Ludovic Courtès <ludo@gnu.org>
  5. ;;; Copyright © 2021 pukkamustard <pukkamustard@posteo.net>
  6. ;;;
  7. ;;; This file is part of GNU Guix.
  8. ;;;
  9. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  10. ;;; under the terms of the GNU General Public License as published by
  11. ;;; the Free Software Foundation; either version 3 of the License, or (at
  12. ;;; your option) any later version.
  13. ;;;
  14. ;;; GNU Guix is distributed in the hope that it will be useful, but
  15. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;;; GNU General Public License for more details.
  18. ;;;
  19. ;;; You should have received a copy of the GNU General Public License
  20. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  21. (define-module (guix build-system dune)
  22. #:use-module (guix store)
  23. #:use-module (guix utils)
  24. #:use-module (guix gexp)
  25. #:use-module (guix search-paths)
  26. #:use-module (guix build-system)
  27. #:use-module ((guix build-system gnu) #:prefix gnu:)
  28. #:use-module ((guix build-system ocaml) #:prefix ocaml:)
  29. #:use-module (guix packages)
  30. #:use-module (srfi srfi-1)
  31. #:export (%dune-build-system-modules
  32. dune-build
  33. dune-build-system))
  34. ;; Commentary:
  35. ;;
  36. ;; Standard build procedure for packages using dune. This is implemented as an
  37. ;; extension of `ocaml-build-system'.
  38. ;;
  39. ;; Code:
  40. (define %dune-build-system-modules
  41. ;; Build-side modules imported by default.
  42. `((guix build dune-build-system)
  43. ,@ocaml:%ocaml-build-system-modules))
  44. (define (default-dune)
  45. "Return the default OCaml package."
  46. ;; Do not use `@' to avoid introducing circular dependencies.
  47. (let ((module (resolve-interface '(gnu packages ocaml))))
  48. (module-ref module 'dune)))
  49. (define* (lower name
  50. #:key source inputs native-inputs outputs system target
  51. (dune (default-dune))
  52. (ocaml (ocaml:default-ocaml))
  53. (findlib (ocaml:default-findlib))
  54. #:allow-other-keys
  55. #:rest arguments)
  56. "Return a bag for NAME."
  57. ;; Flags that put dune into reproducible build mode.
  58. (define dune-release-flags
  59. (if (version>=? (package-version dune) "2.5.0")
  60. ;; For dune >= 2.5.0 this is just --release.
  61. ''("--release")
  62. ;; --release does not exist before 2.5.0. Replace with flags compatible
  63. ;; with our old ocaml4.07-dune (1.11.3)
  64. ''("--root" "." "--ignore-promoted-rules" "--no-config"
  65. "--profile" "release")))
  66. (define private-keywords
  67. '(#:target #:dune #:findlib #:ocaml #:inputs #:native-inputs))
  68. (and (not target) ;XXX: no cross-compilation
  69. (let ((base (ocaml:lower name
  70. #:source source
  71. #:inputs inputs
  72. #:native-inputs native-inputs
  73. #:outputs outputs
  74. #:system system
  75. #:target target
  76. #:ocaml ocaml
  77. #:findlib findlib
  78. arguments)))
  79. (bag
  80. (inherit base)
  81. (build-inputs `(("dune" ,dune)
  82. ,@(bag-build-inputs base)))
  83. (build dune-build)
  84. (arguments (append
  85. `(#:dune-release-flags ,dune-release-flags)
  86. (strip-keyword-arguments private-keywords arguments)))))))
  87. (define* (dune-build name inputs
  88. #:key
  89. guile source
  90. (outputs '("out"))
  91. (search-paths '())
  92. (build-flags ''())
  93. (out-of-source? #t)
  94. (jbuild? #f)
  95. (package #f)
  96. (dune-release-flags ''())
  97. (tests? #t)
  98. (test-flags ''())
  99. (test-target "test")
  100. (install-target "install")
  101. (validate-runpath? #t)
  102. (patch-shebangs? #t)
  103. (strip-binaries? #t)
  104. (strip-flags gnu:%strip-flags)
  105. (strip-directories gnu:%strip-directories)
  106. (phases '(@ (guix build dune-build-system)
  107. %standard-phases))
  108. (system (%current-system))
  109. (imported-modules %dune-build-system-modules)
  110. (modules '((guix build dune-build-system)
  111. (guix build utils))))
  112. "Build SOURCE using OCAML, and with INPUTS. This assumes that SOURCE
  113. provides a 'setup.ml' file as its build system."
  114. (define builder
  115. (with-imported-modules imported-modules
  116. #~(begin
  117. (use-modules #$@modules)
  118. (dune-build #:source #$source
  119. #:system #$system
  120. #:outputs (list #$@(map (lambda (name)
  121. #~(cons #$name
  122. (ungexp output name)))
  123. outputs))
  124. #:inputs (map (lambda (tuple)
  125. (apply cons tuple))
  126. '#$inputs)
  127. #:search-paths '#$(map search-path-specification->sexp
  128. search-paths)
  129. #:phases #$phases
  130. #:test-flags #$test-flags
  131. #:build-flags #$build-flags
  132. #:out-of-source? #$out-of-source?
  133. #:jbuild? #$jbuild?
  134. #:package #$package
  135. #:dune-release-flags #$dune-release-flags
  136. #:tests? #$tests?
  137. #:test-target #$test-target
  138. #:install-target #$install-target
  139. #:validate-runpath? #$validate-runpath?
  140. #:patch-shebangs? #$patch-shebangs?
  141. #:strip-binaries? #$strip-binaries?
  142. #:strip-flags #$strip-flags
  143. #:strip-directories #$strip-directories))))
  144. (gexp->derivation name builder
  145. #:system system
  146. #:target #f
  147. #:graft? #f
  148. #:guile-for-build guile))
  149. (define dune-build-system
  150. (build-system
  151. (name 'dune)
  152. (description "The standard Dune build system")
  153. (lower lower)))
  154. ;;; dune.scm ends here