dub.scm 5.0 KB

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