dub.scm 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2013, 2014, 2015, 2016, 2021 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 gexp)
  27. #:use-module (guix monads)
  28. #:use-module (guix packages)
  29. #:use-module (guix build-system)
  30. #:use-module (guix build-system gnu)
  31. #:export (dub-build-system))
  32. (define (default-ldc)
  33. "Return the default ldc package."
  34. ;; Lazily resolve the binding to avoid a circular dependency.
  35. (let ((ldc (resolve-interface '(gnu packages dlang))))
  36. (module-ref ldc 'ldc)))
  37. (define (default-dub)
  38. "Return the default dub package."
  39. ;; Lazily resolve the binding to avoid a circular dependency.
  40. (let ((ldc (resolve-interface '(gnu packages dlang))))
  41. (module-ref ldc 'dub)))
  42. (define (default-pkg-config)
  43. "Return the default pkg-config package."
  44. ;; Lazily resolve the binding to avoid a circular dependency.
  45. (let ((pkg-config (resolve-interface '(gnu packages pkg-config))))
  46. (module-ref pkg-config 'pkg-config)))
  47. (define (default-ld-gold-wrapper)
  48. "Return the default ld-gold-wrapper package."
  49. ;; LDC doesn't work with Guix's default (BFD) linker.
  50. ;; Lazily resolve the binding to avoid a circular dependency.
  51. (let ((commencement (resolve-interface '(gnu packages commencement))))
  52. (module-ref commencement 'ld-gold-wrapper)))
  53. (define %dub-build-system-modules
  54. ;; Build-side modules imported by default.
  55. `((guix build dub-build-system)
  56. (guix build syscalls)
  57. ,@%gnu-build-system-modules))
  58. (define* (dub-build name inputs
  59. #:key
  60. source
  61. (tests? #t)
  62. (test-target #f)
  63. (dub-build-flags ''())
  64. (phases '%standard-phases)
  65. (outputs '("out"))
  66. (search-paths '())
  67. (system (%current-system))
  68. (guile #f)
  69. (imported-modules %dub-build-system-modules)
  70. (modules '((guix build dub-build-system)
  71. (guix build utils))))
  72. "Build SOURCE using DUB, and with INPUTS."
  73. (define builder
  74. (with-imported-modules imported-modules
  75. #~(begin
  76. (use-modules #$@(sexp->gexp modules))
  77. (dub-build #:name #$name
  78. #:source #+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->gexp outputs)
  85. #:search-paths '#$(sexp->gexp
  86. (map search-path-specification->sexp
  87. search-paths))
  88. #:inputs #$(input-tuples->gexp inputs)))))
  89. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  90. system #:graft? #f)))
  91. (gexp->derivation name builder
  92. #:system system
  93. #:guile-for-build guile)))
  94. (define* (lower name
  95. #:key source inputs native-inputs outputs system target
  96. (ldc (default-ldc))
  97. (dub (default-dub))
  98. (pkg-config (default-pkg-config))
  99. (ld-gold-wrapper (default-ld-gold-wrapper))
  100. #:allow-other-keys
  101. #:rest arguments)
  102. "Return a bag for NAME."
  103. (define private-keywords
  104. '(#:target #:ldc #:dub #:pkg-config #:inputs #:native-inputs #:outputs))
  105. (and (not target) ;; TODO: support cross-compilation
  106. (bag
  107. (name name)
  108. (system system)
  109. (target target)
  110. (host-inputs `(,@(if source
  111. `(("source" ,source))
  112. '())
  113. ,@inputs
  114. ;; Keep the standard inputs of 'gnu-build-system'
  115. ,@(standard-packages)))
  116. (build-inputs `(("ldc" ,ldc)
  117. ("dub" ,dub)
  118. ("ld-gold-wrapper" ,ld-gold-wrapper)
  119. ,@native-inputs))
  120. (outputs outputs)
  121. (build dub-build)
  122. (arguments (strip-keyword-arguments private-keywords arguments)))))
  123. (define dub-build-system
  124. (build-system
  125. (name 'dub)
  126. (description
  127. "DUB build system, to build D packages")
  128. (lower lower)))