go.scm 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016 Petter <petter@mykolab.ch>
  3. ;;; Copyright © 2017 Leo Famulari <leo@famulari.name>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (guix build-system go)
  20. #:use-module (guix utils)
  21. #:use-module (guix derivations)
  22. #:use-module (guix search-paths)
  23. #:use-module (guix build-system)
  24. #:use-module (guix build-system gnu)
  25. #:use-module (guix packages)
  26. #:use-module (ice-9 match)
  27. #:export (%go-build-system-modules
  28. go-build
  29. go-build-system))
  30. ;; Commentary:
  31. ;;
  32. ;; Standard build procedure for packages using the Go build system. It is
  33. ;; implemented as an extension of 'gnu-build-system'.
  34. ;;
  35. ;; Code:
  36. (define %go-build-system-modules
  37. ;; Build-side modules imported and used by default.
  38. `((guix build go-build-system)
  39. (guix build union)
  40. ,@%gnu-build-system-modules))
  41. (define (default-go)
  42. ;; Lazily resolve the binding to avoid a circular dependency.
  43. (let ((go (resolve-interface '(gnu packages golang))))
  44. (module-ref go 'go)))
  45. (define* (lower name
  46. #:key source inputs native-inputs outputs system target
  47. (go (default-go))
  48. #:allow-other-keys
  49. #:rest arguments)
  50. "Return a bag for NAME."
  51. (define private-keywords
  52. '(#:source #:target #:go #:inputs #:native-inputs))
  53. (and (not target) ;XXX: no cross-compilation
  54. (bag
  55. (name name)
  56. (system system)
  57. (host-inputs `(,@(if source
  58. `(("source" ,source))
  59. '())
  60. ,@inputs
  61. ;; Keep the standard inputs of 'gnu-build-system'.
  62. ,@(standard-packages)))
  63. (build-inputs `(("go" ,go)
  64. ,@native-inputs))
  65. (outputs outputs)
  66. (build go-build)
  67. (arguments (strip-keyword-arguments private-keywords arguments)))))
  68. (define* (go-build store name inputs
  69. #:key
  70. (phases '(@ (guix build go-build-system)
  71. %standard-phases))
  72. (outputs '("out"))
  73. (search-paths '())
  74. (install-source? #t)
  75. (import-path "")
  76. (unpack-path "")
  77. (tests? #t)
  78. (allow-go-reference? #f)
  79. (system (%current-system))
  80. (guile #f)
  81. (imported-modules %go-build-system-modules)
  82. (modules '((guix build go-build-system)
  83. (guix build union)
  84. (guix build utils))))
  85. (define builder
  86. `(begin
  87. (use-modules ,@modules)
  88. (go-build #:name ,name
  89. #:source ,(match (assoc-ref inputs "source")
  90. (((? derivation? source))
  91. (derivation->output-path source))
  92. ((source)
  93. source)
  94. (source
  95. source))
  96. #:system ,system
  97. #:phases ,phases
  98. #:outputs %outputs
  99. #:search-paths ',(map search-path-specification->sexp
  100. search-paths)
  101. #:install-source? ,install-source?
  102. #:import-path ,import-path
  103. #:unpack-path ,unpack-path
  104. #:tests? ,tests?
  105. #:allow-go-reference? ,allow-go-reference?
  106. #:inputs %build-inputs)))
  107. (define guile-for-build
  108. (match guile
  109. ((? package?)
  110. (package-derivation store guile system #:graft? #f))
  111. (#f ; the default
  112. (let* ((distro (resolve-interface '(gnu packages commencement)))
  113. (guile (module-ref distro 'guile-final)))
  114. (package-derivation store guile system
  115. #:graft? #f)))))
  116. (build-expression->derivation store name builder
  117. #:inputs inputs
  118. #:system system
  119. #:modules imported-modules
  120. #:outputs outputs
  121. #:guile-for-build guile-for-build))
  122. (define go-build-system
  123. (build-system
  124. (name 'go)
  125. (description
  126. "Build system for Go programs")
  127. (lower lower)))