go.scm 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016 Petter <petter@mykolab.ch>
  3. ;;; Copyright © 2017 Leo Famulari <leo@famulari.name>
  4. ;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net>
  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 go)
  21. #:use-module (guix utils)
  22. #:use-module (guix derivations)
  23. #:use-module (guix search-paths)
  24. #:use-module (guix build-system)
  25. #:use-module (guix build-system gnu)
  26. #:use-module (guix packages)
  27. #:use-module (ice-9 match)
  28. #:export (%go-build-system-modules
  29. go-build
  30. go-build-system))
  31. ;; Commentary:
  32. ;;
  33. ;; Standard build procedure for packages using the Go build system. It is
  34. ;; implemented as an extension of 'gnu-build-system'.
  35. ;;
  36. ;; Code:
  37. (define %go-build-system-modules
  38. ;; Build-side modules imported and used by default.
  39. `((guix build go-build-system)
  40. (guix build union)
  41. ,@%gnu-build-system-modules))
  42. (define (default-go)
  43. ;; Lazily resolve the binding to avoid a circular dependency.
  44. (let ((go (resolve-interface '(gnu packages golang))))
  45. (module-ref go 'go)))
  46. (define* (lower name
  47. #:key source inputs native-inputs outputs system target
  48. (go (default-go))
  49. #:allow-other-keys
  50. #:rest arguments)
  51. "Return a bag for NAME."
  52. (define private-keywords
  53. '(#:source #:target #:go #:inputs #:native-inputs))
  54. (and (not target) ;XXX: no cross-compilation
  55. (bag
  56. (name name)
  57. (system system)
  58. (host-inputs `(,@(if source
  59. `(("source" ,source))
  60. '())
  61. ,@inputs
  62. ;; Keep the standard inputs of 'gnu-build-system'.
  63. ,@(standard-packages)))
  64. (build-inputs `(("go" ,go)
  65. ,@native-inputs))
  66. (outputs outputs)
  67. (build go-build)
  68. (arguments (strip-keyword-arguments private-keywords arguments)))))
  69. (define* (go-build store name inputs
  70. #:key
  71. (phases '(@ (guix build go-build-system)
  72. %standard-phases))
  73. (outputs '("out"))
  74. (search-paths '())
  75. (install-source? #t)
  76. (import-path "")
  77. (unpack-path "")
  78. (build-flags ''())
  79. (tests? #t)
  80. (allow-go-reference? #f)
  81. (system (%current-system))
  82. (guile #f)
  83. (imported-modules %go-build-system-modules)
  84. (modules '((guix build go-build-system)
  85. (guix build union)
  86. (guix build utils))))
  87. (define builder
  88. `(begin
  89. (use-modules ,@modules)
  90. (go-build #:name ,name
  91. #:source ,(match (assoc-ref inputs "source")
  92. (((? derivation? source))
  93. (derivation->output-path source))
  94. ((source)
  95. source)
  96. (source
  97. source))
  98. #:system ,system
  99. #:phases ,phases
  100. #:outputs %outputs
  101. #:search-paths ',(map search-path-specification->sexp
  102. search-paths)
  103. #:install-source? ,install-source?
  104. #:import-path ,import-path
  105. #:unpack-path ,unpack-path
  106. #:build-flags ,build-flags
  107. #:tests? ,tests?
  108. #:allow-go-reference? ,allow-go-reference?
  109. #:inputs %build-inputs)))
  110. (define guile-for-build
  111. (match guile
  112. ((? package?)
  113. (package-derivation store guile system #:graft? #f))
  114. (#f ; the default
  115. (let* ((distro (resolve-interface '(gnu packages commencement)))
  116. (guile (module-ref distro 'guile-final)))
  117. (package-derivation store guile system
  118. #:graft? #f)))))
  119. (build-expression->derivation store name builder
  120. #:inputs inputs
  121. #:system system
  122. #:modules imported-modules
  123. #:outputs outputs
  124. #:guile-for-build guile-for-build))
  125. (define go-build-system
  126. (build-system
  127. (name 'go)
  128. (description
  129. "Build system for Go programs")
  130. (lower lower)))