1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016 Petter <petter@mykolab.ch>
3 ;;; Copyright © 2017 Leo Famulari <leo@famulari.name>
5 ;;; This file is part of GNU Guix.
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.
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.
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
34 ;; Standard build procedure for packages using the Go build system. It is
35 ;; implemented as an extension of 'gnu-build-system'.
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))
45 ;; Lazily resolve the binding to avoid a circular dependency.
46 (let ((go (resolve-interface '(gnu packages golang))))
50 #:key source inputs native-inputs outputs system target
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
62 (host-inputs `(,@(if source
67 ;; Keep the standard inputs of 'gnu-build-system'.
68 ,@(standard-packages)))
69 (build-inputs `(("go" ,go)
73 (arguments (strip-keyword-arguments private-keywords arguments)))))
75 (define* (go-build store name inputs
77 (phases '(@ (guix build go-build-system)
85 (allow-go-reference? #f)
86 (system (%current-system))
88 (imported-modules %go-build-system-modules)
89 (modules '((guix build go-build-system)
93 (use-modules ,@modules)
94 (go-build #:name ,name
95 #:source ,(match (assoc-ref inputs "source")
96 (((? derivation? source))
97 (derivation->output-path source))
105 #:search-paths ',(map search-path-specification->sexp
107 #:install-source? ,install-source?
108 #:import-path ,import-path
109 #:unpack-path ,unpack-path
111 #:allow-go-reference? ,allow-go-reference?
112 #:inputs %build-inputs)))
114 (define guile-for-build
117 (package-derivation store guile system #:graft? #f))
119 (let* ((distro (resolve-interface '(gnu packages commencement)))
120 (guile (module-ref distro 'guile-final)))
121 (package-derivation store guile system
124 (build-expression->derivation store name builder
127 #:modules imported-modules
129 #:guile-for-build guile-for-build))
131 (define go-build-system
135 "Build system for Go programs")