aboutsummaryrefslogtreecommitdiff
path: root/guix/build/go-build-system.scm
diff options
context:
space:
mode:
authorEfraim Flashner <efraim@flashner.co.il>2021-04-26 21:13:06 +0300
committerEfraim Flashner <efraim@flashner.co.il>2021-09-13 15:33:30 +0300
commitde4f5df95db6c2e7071bf5e44c0d7ae928da1025 (patch)
treeb760d81f90354814819a41c11684d8084e322b95 /guix/build/go-build-system.scm
parent43f9757f809d0fb3cd7c3e8b24bfb927179055e8 (diff)
downloadguix-de4f5df95db6c2e7071bf5e44c0d7ae928da1025.tar
guix-de4f5df95db6c2e7071bf5e44c0d7ae928da1025.tar.gz
build/go: Support cross compiling.
* guix/build-system/go.scm (go-target): New procedure. (go-build): Add goarch, goos keywords. Adjust bag depending if doing a native or cross compile. (go-cross-build): New procedure. * guix/build/go-build-system.scm (setup-go-environment): Accept goarch, goos keywords. Set go environment variables based on target architecture. * doc/guix.texi (Build Systems): Mention new go-build-system keywords.
Diffstat (limited to 'guix/build/go-build-system.scm')
-rw-r--r--guix/build/go-build-system.scm20
1 files changed, 18 insertions, 2 deletions
diff --git a/guix/build/go-build-system.scm b/guix/build/go-build-system.scm
index 227df820db..645d2fe680 100644
--- a/guix/build/go-build-system.scm
+++ b/guix/build/go-build-system.scm
@@ -4,7 +4,7 @@
;;; Copyright © 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
;;; Copyright © 2020 Jack Hill <jackhill@jackhill.us>
;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net>
-;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il>
+;;; Copyright © 2020, 2021 Efraim Flashner <efraim@flashner.co.il>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -131,7 +131,7 @@
;;
;; Code:
-(define* (setup-go-environment #:key inputs outputs #:allow-other-keys)
+(define* (setup-go-environment #:key inputs outputs goos goarch #:allow-other-keys)
"Prepare a Go build environment for INPUTS and OUTPUTS. Build a file system
union of INPUTS. Export GOPATH, which helps the compiler find the source code
of the package being built and its dependencies, and GOBIN, which determines
@@ -149,6 +149,22 @@ dependencies, so it should be self-contained."
;; GOPATH behavior.
(setenv "GO111MODULE" "off")
(setenv "GOBIN" (string-append (assoc-ref outputs "out") "/bin"))
+
+ ;; Make sure we're building for the correct architecture and OS targets
+ ;; that Guix targets.
+ (setenv "GOARCH" goarch)
+ (setenv "GOOS" goos)
+ (match goarch
+ ("arm"
+ (setenv "GOARM" "7"))
+ ((or "mips" "mipsel")
+ (setenv "GOMIPS" "hardfloat"))
+ ((or "mips64" "mips64le")
+ (setenv "GOMIPS64" "hardfloat"))
+ ((or "ppc64" "ppc64le")
+ (setenv "GOPPC64" "power8"))
+ (_ #t))
+
(let ((tmpdir (tmpnam)))
(match (go-inputs inputs)
(((names . directories) ...)