all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Sarah Morgensen <iskarian@mgsn.dev>
To: Efraim Flashner <efraim@flashner.co.il>
Cc: 48044@debbugs.gnu.org, leo@famulari.name
Subject: [bug#48044] [PATCH v3] build/go: Support cross compiling.
Date: Sun, 22 Aug 2021 11:52:29 -0700	[thread overview]
Message-ID: <86r1el48ia.fsf@mgsn.dev> (raw)
In-Reply-To: Efraim Flashner's message of "Sun, 22 Aug 2021 13:20:14 +0300 (8 hours, 12 minutes, 33 seconds ago)"

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?

> -(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---

> +      (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).

--
Sarah




  parent reply	other threads:[~2021-08-22 18:53 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 ` Sarah Morgensen [this message]
2021-08-23  9:02   ` [bug#48044] " Efraim Flashner
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=86r1el48ia.fsf@mgsn.dev \
    --to=iskarian@mgsn.dev \
    --cc=48044@debbugs.gnu.org \
    --cc=efraim@flashner.co.il \
    --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.