gnu: emacs-irony-mode: Fetch source using git.
[guix.git] / guix / build-system / go.scm
blobcf91163275fd81776362409d1a833a41e30ef5bd
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/>.
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))
32 ;; Commentary:
34 ;; Standard build procedure for packages using the Go build system.  It is
35 ;; implemented as an extension of 'gnu-build-system'.
37 ;; Code:
39 (define %go-build-system-modules
40   ;; Build-side modules imported and used by default.
41   `((guix build go-build-system)
42     ,@%gnu-build-system-modules))
44 (define (default-go)
45   ;; Lazily resolve the binding to avoid a circular dependency.
46   (let ((go (resolve-interface '(gnu packages golang))))
47     (module-ref go 'go)))
49 (define* (lower name
50                 #:key source inputs native-inputs outputs system target
51                 (go (default-go))
52                 #:allow-other-keys
53                 #:rest arguments)
54   "Return a bag for NAME."
55   (define private-keywords
56     '(#:source #:target #:go #:inputs #:native-inputs))
58   (and (not target)                               ;XXX: no cross-compilation
59        (bag
60          (name name)
61          (system system)
62          (host-inputs `(,@(if source
63                               `(("source" ,source))
64                               '())
65                         ,@inputs
67                         ;; Keep the standard inputs of 'gnu-build-system'.
68                         ,@(standard-packages)))
69          (build-inputs `(("go" ,go)
70                          ,@native-inputs))
71          (outputs outputs)
72          (build go-build)
73          (arguments (strip-keyword-arguments private-keywords arguments)))))
75 (define* (go-build store name inputs
76                    #:key
77                    (phases '(@ (guix build go-build-system)
78                                %standard-phases))
79                    (outputs '("out"))
80                    (search-paths '())
81                    (install-source? #t)
82                    (import-path "")
83                    (unpack-path "")
84                    (tests? #t)
85                    (allow-go-reference? #f)
86                    (system (%current-system))
87                    (guile #f)
88                    (imported-modules %go-build-system-modules)
89                    (modules '((guix build go-build-system)
90                               (guix build utils))))
91   (define builder
92    `(begin
93       (use-modules ,@modules)
94       (go-build #:name ,name
95                 #:source ,(match (assoc-ref inputs "source")
96                                  (((? derivation? source))
97                                   (derivation->output-path source))
98                                  ((source)
99                                   source)
100                                  (source
101                                   source))
102                 #:system ,system
103                 #:phases ,phases
104                 #:outputs %outputs
105                 #:search-paths ',(map search-path-specification->sexp
106                                       search-paths)
107                 #:install-source? ,install-source?
108                 #:import-path ,import-path
109                 #:unpack-path ,unpack-path
110                 #:tests? ,tests?
111                 #:allow-go-reference? ,allow-go-reference?
112                 #:inputs %build-inputs)))
114   (define guile-for-build
115     (match guile
116       ((? package?)
117        (package-derivation store guile system #:graft? #f))
118       (#f                                         ; the default
119        (let* ((distro (resolve-interface '(gnu packages commencement)))
120               (guile  (module-ref distro 'guile-final)))
121          (package-derivation store guile system
122                              #:graft? #f)))))
124   (build-expression->derivation store name builder
125                                 #:inputs inputs
126                                 #:system system
127                                 #:modules imported-modules
128                                 #:outputs outputs
129                                 #:guile-for-build guile-for-build))
131 (define go-build-system
132   (build-system
133     (name 'go)
134     (description
135      "Build system for Go programs")
136     (lower lower)))