dune.scm 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 Ludovic Courtès <ludo@gnu.org>
  5. ;;;
  6. ;;; This file is part of GNU Guix.
  7. ;;;
  8. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  9. ;;; under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation; either version 3 of the License, or (at
  11. ;;; your option) any later version.
  12. ;;;
  13. ;;; GNU Guix is distributed in the hope that it will be useful, but
  14. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;;; GNU General Public License for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; 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 gexp)
  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. ;; 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. (define private-keywords
  58. '(#:target #:dune #:findlib #:ocaml #:inputs #:native-inputs))
  59. (and (not target) ;XXX: no cross-compilation
  60. (let ((base (ocaml:lower name
  61. #:source source
  62. #:inputs inputs
  63. #:native-inputs native-inputs
  64. #:outputs outputs
  65. #:system system
  66. #:target target
  67. #:ocaml ocaml
  68. #:findlib findlib
  69. arguments)))
  70. (bag
  71. (inherit base)
  72. (build-inputs `(("dune" ,dune)
  73. ,@(bag-build-inputs base)))
  74. (build dune-build)
  75. (arguments (strip-keyword-arguments private-keywords arguments))))))
  76. (define* (dune-build name inputs
  77. #:key
  78. guile source
  79. (outputs '("out"))
  80. (search-paths '())
  81. (build-flags ''())
  82. (out-of-source? #t)
  83. (jbuild? #f)
  84. (package #f)
  85. (tests? #t)
  86. (test-flags ''())
  87. (test-target "test")
  88. (install-target "install")
  89. (validate-runpath? #t)
  90. (patch-shebangs? #t)
  91. (strip-binaries? #t)
  92. (strip-flags ''("--strip-debug"))
  93. (strip-directories ''("lib" "lib64" "libexec"
  94. "bin" "sbin"))
  95. (phases '(@ (guix build dune-build-system)
  96. %standard-phases))
  97. (system (%current-system))
  98. (imported-modules %dune-build-system-modules)
  99. (modules '((guix build dune-build-system)
  100. (guix build utils))))
  101. "Build SOURCE using OCAML, and with INPUTS. This assumes that SOURCE
  102. provides a 'setup.ml' file as its build system."
  103. (define builder
  104. (with-imported-modules imported-modules
  105. #~(begin
  106. (use-modules #$@modules)
  107. (dune-build #:source #$source
  108. #:system #$system
  109. #:outputs (list #$@(map (lambda (name)
  110. #~(cons #$name
  111. (ungexp output name)))
  112. outputs))
  113. #:inputs (map (lambda (tuple)
  114. (apply cons tuple))
  115. '#$inputs)
  116. #:search-paths '#$(map search-path-specification->sexp
  117. search-paths)
  118. #:phases #$phases
  119. #:test-flags #$test-flags
  120. #:build-flags #$build-flags
  121. #:out-of-source? #$out-of-source?
  122. #:jbuild? #$jbuild?
  123. #:package #$package
  124. #:tests? #$tests?
  125. #:test-target #$test-target
  126. #:install-target #$install-target
  127. #:validate-runpath? #$validate-runpath?
  128. #:patch-shebangs? #$patch-shebangs?
  129. #:strip-binaries? #$strip-binaries?
  130. #:strip-flags #$strip-flags
  131. #:strip-directories #$strip-directories))))
  132. (gexp->derivation name builder
  133. #:system system
  134. #:target #f
  135. #:guile-for-build guile))
  136. (define dune-build-system
  137. (build-system
  138. (name 'dune)
  139. (description "The standard Dune build system")
  140. (lower lower)))
  141. ;;; dune.scm ends here