From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id t3HeORudImFUuAAAgWs5BA (envelope-from ) for ; Sun, 22 Aug 2021 20:53:15 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id B0bbNBudImHMCAAAbx9fmQ (envelope-from ) for ; Sun, 22 Aug 2021 18:53:15 +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 1809E21AAB for ; Sun, 22 Aug 2021 20:53:15 +0200 (CEST) Received: from localhost ([::1]:51968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mHsan-0003Zv-Rf for larch@yhetil.org; Sun, 22 Aug 2021 14:53:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34176) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mHsac-0003ZU-FU for guix-patches@gnu.org; Sun, 22 Aug 2021 14:53:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:56483) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mHsac-0001Pu-3n for guix-patches@gnu.org; Sun, 22 Aug 2021 14:53:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mHsac-0007VQ-09 for guix-patches@gnu.org; Sun, 22 Aug 2021 14:53:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#48044] [PATCH v3] build/go: Support cross compiling. References: <20210426183235.3856-1-efraim@flashner.co.il> Resent-From: Sarah Morgensen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 22 Aug 2021 18:53:01 +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: Efraim Flashner Cc: 48044@debbugs.gnu.org, leo@famulari.name Received: via spool by 48044-submit@debbugs.gnu.org id=B48044.162965835828822 (code B ref 48044); Sun, 22 Aug 2021 18:53:01 +0000 Received: (at 48044) by debbugs.gnu.org; 22 Aug 2021 18:52:38 +0000 Received: from localhost ([127.0.0.1]:39796 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mHsaE-0007Uo-3Z for submit@debbugs.gnu.org; Sun, 22 Aug 2021 14:52:38 -0400 Received: from out0.migadu.com ([94.23.1.103]:24690) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mHsaA-0007Ue-Ey for 48044@debbugs.gnu.org; Sun, 22 Aug 2021 14:52:37 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mgsn.dev; s=key1; t=1629658352; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=wj8JLohI/pi2FOe8kyq7G+X7wWTPMCVEvO7yFh/OkkA=; b=RJE67rp+cC4buZGg5NnYrapIY7GJyIYZQWmRJQuXVrJv4VgrtiJzVIsFmZULtybNJ8qKDs DwKtTdv/6J55oQ63DjF1KG3cTq9ovtukzq4HoFWb1/bIsFiWmYVrRq9NH6m70j5A0gn/M5 daJQ0oHS8u6vMvBI1RPbPRik3JUVpQI= From: Sarah Morgensen Date: Sun, 22 Aug 2021 11:52:29 -0700 In-Reply-To: Efraim Flashner's message of "Sun, 22 Aug 2021 13:20:14 +0300 (8 hours, 12 minutes, 33 seconds ago)" Message-ID: <86r1el48ia.fsf@mgsn.dev> MIME-Version: 1.0 Content-Type: text/plain X-Migadu-Auth-User: iskarian@mgsn.dev 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1629658395; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post: dkim-signature; bh=wj8JLohI/pi2FOe8kyq7G+X7wWTPMCVEvO7yFh/OkkA=; b=t3mN7mpBinMsXvREjO28ZcVZDpjG2mBbQKt1YNB/65O+XuiLFdHP2ROYhmkLZTpEgXJUdz tkoszObXdZZSv5ZGmT8HeyMKD/XLCWc3H/AX7MfvCdliy43U6g8rWzEX5YKbRKXVxuuHCG 0m/M7KXmHHOBr0yhnw8Uw3Yorkb1WC5uFDXd7fAx/Dm5JlCWtadgJhUEA0N2D2bKW5gUXG YOe5US8AAehPwFsZKQzAcovVppWJzq43yzQyCMpOfN2dg7nxrclHf7JWu7jUko4dySj1Pg Z9eud/TVv1SRMYuw22OLYaxZdY5F7IaBOZ9uLz8w7UXgin2JKkiPEuqo8x9vkw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1629658395; a=rsa-sha256; cv=none; b=BK0oJ/gfxRqNmlfVDhUIflQOBd/VQA98BZcdXdJ7Dcu76z+MTBHXwcyCKLHqjNr6DVowQh xEIoXehLT4CiyFE31d3VTb2mDk8lSCuxqoGxHk2NzbpxZ0cRus++lzBL4hS19JO63xxk3Z o5LYN5qxpUnw0GG872d1vhlvm2fM+358GjllHgjbxiVgAm4e3PRkeNO1p1xlYiN7vcig4u zmHrhQJQkldw2S0LOL3L0Tm9HvR5xjk2D3WGmblo0ZzUU9n+yZOkIohj6OJTwbDm1PtF8J 2UNQt18f2EDZFShwTL+RyWTR3RioRISENzDNR8+8PIDQGvos0SC8gssy/bW96Q== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=mgsn.dev header.s=key1 header.b=RJE67rp+; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: -1.33 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=mgsn.dev header.s=key1 header.b=RJE67rp+; dmarc=fail reason="SPF not aligned (relaxed)" header.from=mgsn.dev (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 1809E21AAB X-Spam-Score: -1.33 X-Migadu-Scanner: scn0.migadu.com X-TUID: OoVwW2CHew3j Hi Efraim, Thanks for doing this work! I'm excited to see it in action. Efraim Flashner 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