dub.scm 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2013 Andreas Enge <andreas@enge.fr>
  4. ;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
  5. ;;; Copyright © 2016 David Craven <david@craven.ch>
  6. ;;; Copyright © 2016 Danny Milosavljevic <dannym@scratchpost.org>
  7. ;;;
  8. ;;; This file is part of GNU Guix.
  9. ;;;
  10. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  11. ;;; under the terms of the GNU General Public License as published by
  12. ;;; the Free Software Foundation; either version 3 of the License, or (at
  13. ;;; your option) any later version.
  14. ;;;
  15. ;;; GNU Guix is distributed in the hope that it will be useful, but
  16. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;;; GNU General Public License for more details.
  19. ;;;
  20. ;;; You should have received a copy of the GNU General Public License
  21. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  22. (define-module (guix build-system dub)
  23. #:use-module (guix search-paths)
  24. #:use-module (guix store)
  25. #:use-module (guix utils)
  26. #:use-module (guix derivations)
  27. #:use-module (guix packages)
  28. #:use-module (guix build-system)
  29. #:use-module (guix build-system gnu)
  30. #:use-module (ice-9 match)
  31. #:use-module (srfi srfi-26)
  32. #:export (dub-build-system))
  33. (define (default-ldc)
  34. "Return the default ldc package."
  35. ;; Lazily resolve the binding to avoid a circular dependency.
  36. (let ((ldc (resolve-interface '(gnu packages dlang))))
  37. (module-ref ldc 'ldc)))
  38. (define (default-dub)
  39. "Return the default dub package."
  40. ;; Lazily resolve the binding to avoid a circular dependency.
  41. (let ((ldc (resolve-interface '(gnu packages dlang))))
  42. (module-ref ldc 'dub)))
  43. (define (default-pkg-config)
  44. "Return the default pkg-config package."
  45. ;; Lazily resolve the binding to avoid a circular dependency.
  46. (let ((pkg-config (resolve-interface '(gnu packages pkg-config))))
  47. (module-ref pkg-config 'pkg-config)))
  48. (define %dub-build-system-modules
  49. ;; Build-side modules imported by default.
  50. `((guix build dub-build-system)
  51. (guix build syscalls)
  52. ,@%gnu-build-system-modules))
  53. (define* (dub-build store name inputs
  54. #:key
  55. (tests? #t)
  56. (test-target #f)
  57. (dub-build-flags ''())
  58. (phases '(@ (guix build dub-build-system)
  59. %standard-phases))
  60. (outputs '("out"))
  61. (search-paths '())
  62. (system (%current-system))
  63. (guile #f)
  64. (imported-modules %dub-build-system-modules)
  65. (modules '((guix build dub-build-system)
  66. (guix build utils))))
  67. "Build SOURCE using DUB, and with INPUTS."
  68. (define builder
  69. `(begin
  70. (use-modules ,@modules)
  71. (dub-build #:name ,name
  72. #:source ,(match (assoc-ref inputs "source")
  73. (((? derivation? source))
  74. (derivation->output-path source))
  75. ((source)
  76. source)
  77. (source
  78. source))
  79. #:system ,system
  80. #:test-target ,test-target
  81. #:dub-build-flags ,dub-build-flags
  82. #:tests? ,tests?
  83. #:phases ,phases
  84. #:outputs %outputs
  85. #:search-paths ',(map search-path-specification->sexp
  86. search-paths)
  87. #:inputs %build-inputs)))
  88. (define guile-for-build
  89. (match guile
  90. ((? package?)
  91. (package-derivation store guile system #:graft? #f))
  92. (#f ; the default
  93. (let* ((distro (resolve-interface '(gnu packages commencement)))
  94. (guile (module-ref distro 'guile-final)))
  95. (package-derivation store guile system #:graft? #f)))))
  96. (build-expression->derivation store name builder
  97. #:inputs inputs
  98. #:system system
  99. #:modules imported-modules
  100. #:outputs outputs
  101. #:guile-for-build guile-for-build))
  102. (define* (lower name
  103. #:key source inputs native-inputs outputs system target
  104. (ldc (default-ldc))
  105. (dub (default-dub))
  106. (pkg-config (default-pkg-config))
  107. #:allow-other-keys
  108. #:rest arguments)
  109. "Return a bag for NAME."
  110. (define private-keywords
  111. '(#:source #:target #:ldc #:dub #:pkg-config #:inputs #:native-inputs #:outputs))
  112. (and (not target) ;; TODO: support cross-compilation
  113. (bag
  114. (name name)
  115. (system system)
  116. (target target)
  117. (host-inputs `(,@(if source
  118. `(("source" ,source))
  119. '())
  120. ,@inputs
  121. ;; Keep the standard inputs of 'gnu-build-system'
  122. ,@(standard-packages)))
  123. (build-inputs `(("ldc" ,ldc)
  124. ("dub" ,dub)
  125. ,@native-inputs))
  126. (outputs outputs)
  127. (build dub-build)
  128. (arguments (strip-keyword-arguments private-keywords arguments)))))
  129. (define dub-build-system
  130. (build-system
  131. (name 'dub)
  132. (description
  133. "DUB build system, to build D packages")
  134. (lower lower)))