[PATCH 0/1] Fix cross-compilation of packages that use go-build-system

  • Open
  • quality assurance status badge
Details
2 participants
  • Collin J. Doering
  • Maxime Devos
Owner
unassigned
Submitted by
Collin J. Doering
Severity
normal
C
C
Collin J. Doering wrote on 19 Nov 2021 20:59
(no subject)
(address . guix-patches@gnu.org)
87bl2f6gti.fsf@rekahsoft.ca
Hi all,

This patch resolves an issue I discovered when attempting to cross-compile packages that use the go-build-system.

Namely, prior to this patch, running 'guix build --target=arm-unknown-linux-gnueabihf <go-package>' where '<go-package>' is some package that uses to go-build-system (for example, 'fzf'), would result in the following error in the build log:

Toggle snippet (40 lines)
go install: cannot install cross-compiled binaries when GOBIN is set
Building 'github.com/junegunn/fzf' failed.
Here are the results of `go env`:
GO111MODULE="off"
GOARCH="arm"
GOBIN="/gnu/store/8xcs9vna6zyl814j78raynccm7mqqk0h-fzf-0.25.0/bin"
GOCACHE="/tmp/go-cache"
GOENV="/homeless-shelter/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/tmp/guix-build-fzf-0.25.0.drv-0"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/gnu/store/y5rwacd5l4q26pxis28wsmswj2603hkw-go-1.14.15"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/gnu/store/y5rwacd5l4q26pxis28wsmswj2603hkw-go-1.14.15/pkg/tool/linux_amd64"
GCCGO="gccgo"
GOARM="7"
AR="ar"
CC="/gnu/store/rn75fm7adgx3pw5j8pg3bczfqq1y17lk-gcc-7.5.0/bin/gcc"
CXX="g++"
CGO_ENABLED="0"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -marm -fmessage-length=0 -fdebug-prefix-map=/tmp/guix-build-fzf-0.25.0.drv-0/go-build219362912=/tmp/go-build -gno-record-gcc-switches"
command "go" "install" "-v" "-x" "-ldflags=-s -w" "github.com/junegunn/fzf" failed with status 1

The important bit is the first line, which indicates that 'GOBIN' cannot be set when cross-compiling. This has been the case in go from what I can tell for numerous years (atleast 2019).

This patch removes the setting of 'GOBIN' and adjusts the go-build-systems build function to us 'go build' instead of 'go install'.

Collin J. Doering (1):
build: Fix cross compilation for go-build-system

guix/build/go-build-system.scm | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

--
2.33.1

--
Collin J. Doering

C
C
Collin J. Doering wrote on 19 Nov 2021 21:37
[PATCH 1/1] build: Fix cross compilation for go-build-system
(address . 51981@debbugs.gnu.org)
877dd36fvc.fsf@rekahsoft.ca
---
guix/build/go-build-system.scm | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

Toggle diff (44 lines)
diff --git a/guix/build/go-build-system.scm b/guix/build/go-build-system.scm
index 4768ee8562..f36e98f47a 100644
--- a/guix/build/go-build-system.scm
+++ b/guix/build/go-build-system.scm
@@ -148,7 +148,6 @@ (define* (setup-go-environment #:key inputs outputs goos goarch #:allow-other-ke
;; currently support modules, so turn modules off to continue using the old
;; 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.
@@ -234,14 +233,19 @@ (define (go-inputs inputs)
(_ #f))
inputs))))
-(define* (build #:key import-path build-flags #:allow-other-keys)
+(define* (build #:key outputs import-path build-flags #:allow-other-keys)
"Build the package named by IMPORT-PATH."
(with-throw-handler
#t
(lambda _
- (apply invoke "go" "install"
+ (apply invoke "go" "build"
"-v" ; print the name of packages as they are compiled
"-x" ; print each command as it is invoked
+ ;; Set the output path for the build
+ (string-append "-o="
+ (assoc-ref outputs "out") "/bin/"
+ (package-name->name+version
+ (strip-store-file-name (assoc-ref outputs "out"))))
;; Respectively, strip the symbol table and debug
;; information, and the DWARF symbol table.
"-ldflags=-s -w"
--
2.33.1


--
Collin J. Doering

http://rekahsoft.ca
http://blog.rekahsoft.ca
http://git.rekahsoft.ca
C
C
M
M
Maxime Devos wrote on 14 May 2022 09:23
Re: [PATCH 0/1] Fix cross-compilation of packages that use go-build-system
(address . 51981@debbugs.gnu.org)
2d39676f4b73229ca654ce67ea3fce57b50edc53.camel@telenet.be
Toggle quote (1 lines)
> [PATCH 1/1] build: Fix cross compilation for go-build-system
Nice.

Toggle quote (6 lines)
> + ;; Set the output path for the build
> + (string-append "-o="
> + (assoc-ref outputs "out") "/bin/"
> + (package-name->name+version
> + (strip-store-file-name (assoc-ref outputs "out"))))

Maybe add a comment on why the simpler "GOBIN" isn't used instead, such
that it won't be incorrectly simplified in the future. I'm not sure if
this is correct though, what if the name of the binary differs from the
package name? Or was if the go package has multiple binaries?


maybe you could resend the patch as a v2?

Greetings,
Maxime.
-----BEGIN PGP SIGNATURE-----

iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYn9Y6BccbWF4aW1lZGV2
b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7txmAPsHZR8ey69tGab+YdcTB+Xnf2eA
CRUJ/qNZ+zNB+d/BUAD/ZBvTM7F5NYI3/9cqHLB/RkrJWlCVo/x3LZd4ft4ZvQA=
=en1m
-----END PGP SIGNATURE-----


?
Your comment

Commenting via the web interface is currently disabled.

To comment on this conversation send an email to 51981@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 51981
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch