all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Efraim Flashner <efraim@flashner.co.il>
To: Sarah Morgensen <iskarian@mgsn.dev>
Cc: 48044@debbugs.gnu.org, leo@famulari.name
Subject: [bug#48044] [PATCH v3] build/go: Support cross compiling.
Date: Mon, 23 Aug 2021 12:02:10 +0300	[thread overview]
Message-ID: <YSNkEsnfg3uBh+kx@3900XT> (raw)
In-Reply-To: <86r1el48ia.fsf@mgsn.dev>

[-- Attachment #1: Type: text/plain, Size: 3859 bytes --]

On Sun, Aug 22, 2021 at 11:52:29AM -0700, Sarah Morgensen wrote:
> Hi Efraim,
> 
> Thanks for doing this work!  I'm excited to see it in action.
> 
> Efraim Flashner <efraim@flashner.co.il> writes:
> 
> > * guix/build-system/go.scm (lower): Only add target to private-keywords
> > when not cross compiling. Adjust bag depending if doing a native or
> > cross compile.
> > (%go-build-system-modules): Use source-module-closure, add (guix utils).
> > (go-cross-build): New procedure.
> > * guix/build/go-build-system.scm (setup-go-environment): Accept target
> > keyword. Add logic to choose correct target architecture when cross
> > compiling.
> > ---
> >
> > Third version of this patch. I think I'm ready to push it. I don't love
> > using source-module-closure to include (guix utils), but I need it for
> > gnu-triplet->nix-system in setup-go-environment instead of the custom
> > parsing I was doing before.
> 
> Can you do the parsing host-side and pass e.g. TARGET-GOOS/TARGET-GOARCH
> keyword arguments to the build-side?

I'll have to see if there's somewhere I can slot that in. We already
have target, but that's what we're parsing now.

I guess if I add them as a keywords then we can build for targets that
go supports but which Guix doesn't.

> > -(define* (setup-go-environment #:key inputs outputs #:allow-other-keys)
> > +(define* (setup-go-environment #:key inputs outputs target #: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 +150,38 @@ dependencies, so it should be self-contained."
> >    ;; GOPATH behavior.
> >    (setenv "GO111MODULE" "off")
> >    (setenv "GOBIN" (string-append (assoc-ref outputs "out") "/bin"))
> > +
> > +  ;; Cross-build
> > +  (when target
> > +    ;; Parse the nix-system equivalent of the target and set the
> > +    ;; target for compilation accordingly.
> > +    (let* ((system (gnu-triplet->nix-system target))
> > +           (dash   (string-index system #\-))
> > +           (arch   (substring system 0 dash))
> > +           (os     (substring system (+ 1 dash))))
> 
> And then, if this parsing is host-side, you can probably just do
> something like
> 
> --8<---------------cut here---------------start------------->8---
> (match (string-split (gnu-triplet->nix-system target) #\-)
>   ((arch os)
>    [...]
> --8<---------------cut here---------------end--------------->8---

I like the way this looks much better. Even if we did just parse the
gnu-triplet we'd have our special case for arm-linux-gnueabihf (unless
we ignored it, as I did below). 

> > +      (match arch
> > +        ((or "arm" "armhf")
> > +         (setenv "GOARM" "7"))
> > +        ((or "mips" "mipsel")
> > +         (setenv "GOMIPS" "hardfloat"))
> > +        ((or "mips64" "mips64el")
> > +         (setenv "GOMIPS64" "hardfloat"))
> > +        ((or "powerpc64" "powerpc64le")
> > +         (setenv "GOPPC64" "power8"))
> > +        (_ #t))))
> 
> Are these choices obvious for those compiling for those architectures?
> If not, this could probably do with some documentation on why these were
> chosen.  (I note that these are all Go's defaults with the exception of
> GOARM).

For the mips I did just copy from the Go documentation, but for arm and
ppc64 I wanted to make sure we targeted the same systems that Guix
already supports.

> 
> --
> Sarah

Thanks for taking a look at it.

-- 
Efraim Flashner   <efraim@flashner.co.il>   רנשלפ םירפא
GPG key = A28B F40C 3E55 1372 662D  14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2021-08-23  9:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-26 18:32 [bug#48044] [PATCH] build/go: Support cross compiling Efraim Flashner
2021-04-26 19:39 ` Maxime Devos
2021-08-22 10:20 ` [bug#48044] [PATCH v3] " Efraim Flashner
2021-09-14  8:38   ` bug#48044: " Efraim Flashner
2021-08-22 18:52 ` [bug#48044] " Sarah Morgensen
2021-08-23  9:02   ` Efraim Flashner [this message]
2021-08-23  9:26   ` Efraim Flashner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YSNkEsnfg3uBh+kx@3900XT \
    --to=efraim@flashner.co.il \
    --cc=48044@debbugs.gnu.org \
    --cc=iskarian@mgsn.dev \
    --cc=leo@famulari.name \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.