From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id iGOvLc1kI2GglwAAgWs5BA (envelope-from ) for ; Mon, 23 Aug 2021 11:05:17 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id CDtwKc1kI2EQLgAA1q6Kng (envelope-from ) for ; Mon, 23 Aug 2021 09:05:17 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 818524C7F for ; Mon, 23 Aug 2021 11:05:17 +0200 (CEST) Received: from localhost ([::1]:45098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mI5tL-00026P-7h for larch@yhetil.org; Mon, 23 Aug 2021 05:05:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60544) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mI5t9-000238-9N for guix-patches@gnu.org; Mon, 23 Aug 2021 05:05:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:57160) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mI5t8-0003vh-Kr for guix-patches@gnu.org; Mon, 23 Aug 2021 05:05:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mI5t8-0005Wi-Dp for guix-patches@gnu.org; Mon, 23 Aug 2021 05:05:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#48044] [PATCH v3] build/go: Support cross compiling. Resent-From: Efraim Flashner Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 23 Aug 2021 09:05:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48044 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Sarah Morgensen Cc: 48044@debbugs.gnu.org, leo@famulari.name Received: via spool by 48044-submit@debbugs.gnu.org id=B48044.162970946121193 (code B ref 48044); Mon, 23 Aug 2021 09:05:02 +0000 Received: (at 48044) by debbugs.gnu.org; 23 Aug 2021 09:04:21 +0000 Received: from localhost ([127.0.0.1]:40473 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mI5sO-0005Vh-DE for submit@debbugs.gnu.org; Mon, 23 Aug 2021 05:04:21 -0400 Received: from flashner.co.il ([178.62.234.194]:46796) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mI5sJ-0005VQ-CI for 48044@debbugs.gnu.org; Mon, 23 Aug 2021 05:04:16 -0400 Received: from localhost (unknown [141.226.169.107]) by flashner.co.il (Postfix) with ESMTPSA id 8F17A401A4; Mon, 23 Aug 2021 09:04:04 +0000 (UTC) Date: Mon, 23 Aug 2021 12:02:10 +0300 From: Efraim Flashner Message-ID: Mail-Followup-To: Efraim Flashner , Sarah Morgensen , 48044@debbugs.gnu.org, leo@famulari.name References: <86r1el48ia.fsf@mgsn.dev> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="mxipbSKtO9uJZS4r" Content-Disposition: inline In-Reply-To: <86r1el48ia.fsf@mgsn.dev> X-PGP-Key-ID: 0x41AAE7DCCA3D8351 X-PGP-Key: https://flashner.co.il/~efraim/efraim_flashner.asc X-PGP-Fingerprint: A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -4.00 Authentication-Results: aspmx1.migadu.com; none X-Migadu-Queue-Id: 818524C7F X-Spam-Score: -4.00 X-Migadu-Scanner: scn0.migadu.com X-TUID: +TuiuWEmSbsc --mxipbSKtO9uJZS4r Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Aug 22, 2021 at 11:52:29AM -0700, Sarah Morgensen wrote: > Hi Efraim, >=20 > Thanks for doing this work! I'm excited to see it in action. >=20 > Efraim Flashner writes: >=20 > > * 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. >=20 > 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-oth= er-keys) > > "Prepare a Go build environment for INPUTS and OUTPUTS. Build a fil= e system > > union of INPUTS. Export GOPATH, which helps the compiler find the sou= rce code > > of the package being built and its dependencies, and GOBIN, which dete= rmines > > @@ -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)))) >=20 > And then, if this parsing is host-side, you can probably just do > something like >=20 > --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).=20 > > + (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)))) >=20 > 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. >=20 > -- > Sarah Thanks for taking a look at it. --=20 Efraim Flashner =D7=A8=D7=A0=D7=A9=D7=9C=D7=A4 = =D7=9D=D7=99=D7=A8=D7=A4=D7=90 GPG key =3D A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351 Confidentiality cannot be guaranteed on emails sent or received unencrypted --mxipbSKtO9uJZS4r Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEoov0DD5VE3JmLRT3Qarn3Mo9g1EFAmEjZA8ACgkQQarn3Mo9 g1HkMw//WaIwzgi7u5BQTx6LGRi8lzm/0VlVM9jpB05WtfdEvFCkcWTOYITCU8MM TmyMKNmsUdgU4i4ycp3QvKqouiJdxxTNQiTG1YnaVi1kI9hWpeo9bGYibE6Z8r9G ICb6ai8ubIfRHBPz89LzlJPMlfPgvTbWPsM0zu6IdEhTpKWwGe/e7D91BOVkpq85 Z3T6B1Xpc4sAo2V6z+Ghs/k7zzdP+aH56+NfCx5UsVe08akMqoAJg5EmuLn5J6o+ H0pL8/tPvfROEPn6Bn76U8m04VkILg3X7h422RmtEUimFTnwW/NWi2EzXj2AZ9lU 5a6C4SEkc03DAPqh1Ovpzrzf6nvG20K9sOQALyanpr6OIUZq0AHFa+UtRMyP/SoN DfXsT4WgX0IEnBmlltpWiLo1Yh8AC3+JGsywdY7TQmWCEAMebPNsk8N9jAXH8iZ/ y6PnWj3sRP3GvFNyajcd5BspmHioh8jQrrwWVvfJdKz5mikuZCKWI9f2QW13JuV/ 9BXnOibMxijxs2iYha33aIrNRDl00tyVDveI9HE+xVVRVAwAS8Wo4LkV4cq0DUrz 5zltmk2Yw+HXo19TYaE53p5oAAHAUBGcAsBZFite2gAZUQEg7/L6nEjw1OBuaz4N NA/3wDpQFME7MixCy73bda8p11d4skpclYjBXI9KFFw3NbdLnog= =RJOO -----END PGP SIGNATURE----- --mxipbSKtO9uJZS4r--