From patchwork Fri Jan 20 14:30:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekaitz Zarraga X-Patchwork-Id: 9305 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 9131F27BBED; Fri, 20 Jan 2023 14:31:29 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 2462D27BBEB for ; Fri, 20 Jan 2023 14:31:28 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pIsQA-0007cB-3g; Fri, 20 Jan 2023 09:31:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pIsQ4-0007ba-Mp for guix-patches@gnu.org; Fri, 20 Jan 2023 09:31:05 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pIsQ2-00085K-MC for guix-patches@gnu.org; Fri, 20 Jan 2023 09:31:04 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pIsQ2-0004Aq-4L for guix-patches@gnu.org; Fri, 20 Jan 2023 09:31:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#60889] Tentative cross-compilation support References: <7NnZFxGvY0oj1TtDERAWi3dMBqoRv2AJoGBlaDPJA6vueGK91igAml6SLzMhNJyc1TssJW--OgezzmxLl5yv5MSgd7Wz6MRkORfOT62_f3w=@elenq.tech> In-Reply-To: <7NnZFxGvY0oj1TtDERAWi3dMBqoRv2AJoGBlaDPJA6vueGK91igAml6SLzMhNJyc1TssJW--OgezzmxLl5yv5MSgd7Wz6MRkORfOT62_f3w=@elenq.tech> Resent-From: Ekaitz Zarraga Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 20 Jan 2023 14:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60889 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: "60889@debbugs.gnu.org" <60889@debbugs.gnu.org> Received: via spool by 60889-submit@debbugs.gnu.org id=B60889.167422503613618 (code B ref 60889); Fri, 20 Jan 2023 14:31:02 +0000 Received: (at 60889) by debbugs.gnu.org; 20 Jan 2023 14:30:36 +0000 Received: from localhost ([127.0.0.1]:45991 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pIsPb-0003WW-O7 for submit@debbugs.gnu.org; Fri, 20 Jan 2023 09:30:36 -0500 Received: from mail-4018.proton.ch ([185.70.40.18]:24499) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pIsPX-00030H-GX for 60889@debbugs.gnu.org; Fri, 20 Jan 2023 09:30:34 -0500 Date: Fri, 20 Jan 2023 14:30:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=elenq.tech; s=protonmail; t=1674225024; x=1674484224; bh=ciGTXQEU6rhnqMPWu4wCmWI9RRM1VjvpXmi/J8zAbM0=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=eaR100GDYavjIRydButB9E0Tke/O26LuxW2aDFks9PgPQvBmg+57Fm8MtH7d3ji2k HNeeyPrMuhPad5ESDOY8m9h6jJEqNFqp19Aw2GsIYlw7pqo4V2cM8wvu3NKlfnRE3O rsaqL9dD/9VSt3Hnbo+zRqVYHCJozFncPNYA15nT15baLVsirSOu1A0yYsFxE1ICCM x39wCNlzH48W7uKUVN3cQMIQpvDmdVXsI+CmcQ6KZozoIvCzOFjS98V58W50j+Jaah uWVdA3e60HByaMZZnwPQfTsds0bZA4sIWjYEhHUKW+MHwtd0wUwQuYvnXoxtRIuT8Z fWrZ7VYUWwhVw== From: Ekaitz Zarraga Message-ID: Feedback-ID: 3263582:user:proton MIME-Version: 1.0 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+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches Hi, Let me add a tentative cross-compilation support for the previous patch set. I just tested it with the tigerbeetle package included and it generated an aarch64-linux-gnu binary with no problem but I'm not sure about the implementation. It needs an in-depth review. Cheers, Ekaitz From 61f10dd2da81252338b3852b1ed4daf513d4ee87 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Fri, 20 Jan 2023 14:21:23 +0100 Subject: [PATCH 3/3] Tentative cross-compilation support for zig --- guix/build-system/zig.scm | 114 ++++++++++++++++++++++++++------ guix/build/zig-build-system.scm | 6 +- 2 files changed, 98 insertions(+), 22 deletions(-) diff --git a/guix/build-system/zig.scm b/guix/build-system/zig.scm index 16b8a712cc..abea1c0cc6 100644 --- a/guix/build-system/zig.scm +++ b/guix/build-system/zig.scm @@ -84,6 +84,75 @@ (define builder #:system system #:guile-for-build guile))) +(define* (zig-cross-build name + #:key + source target + build-inputs target-inputs host-inputs + (phases '%standard-phases) + (outputs '("out")) + (search-paths '()) + (native-search-paths '()) + (tests? #t) + (test-target #f) + (zig-build-flags ''()) + (zig-test-flags ''()) + (zig-release-type #f) + (system (%current-system)) + (guile #f) + (imported-modules %zig-build-system-modules) + (modules '((guix build zig-build-system) + (guix build utils)))) + "Build SOURCE using Zig, and with INPUTS." + (define builder + (with-imported-modules imported-modules + #~(begin + (use-modules #$@(sexp->gexp modules)) + + (define %build-host-inputs + #+(input-tuples->gexp build-inputs)) + + (define %build-target-inputs + (append #$(input-tuples->gexp host-inputs) + #+(input-tuples->gexp target-inputs))) + + (define %build-inputs + (append %build-host-inputs %build-target-inputs)) + + (define %outputs + #$(outputs->gexp outputs)) + + (zig-build #:name #$name + #:source #+source + #:system #$system + #:phases #$phases + #:outputs %outputs + #:target #$target + #:test-target #$test-target + #:inputs %build-target-inputs + #:native-inputs %build-host-inputs + #:search-paths '#$(map search-path-specification->sexp + search-paths) + #:native-search-paths '#$(map + search-path-specification->sexp + native-search-paths) + #:zig-build-flags #$zig-build-flags + #:zig-test-flags #$zig-test-flags + #:zig-release-type #$zig-release-type + #:tests? #$tests? + #:search-paths '#$(sexp->gexp + (map search-path-specification->sexp + search-paths)))))) + + (mlet %store-monad ((guile (package->derivation (or guile (default-guile)) + system #:graft? #f))) + (gexp->derivation name builder + #:system system + #:target target + #:graft? #f + #:substitutable? substitutable? + #:guile-for-build guile))) + + (define* (lower name #:key source inputs native-inputs outputs system target (zig (default-zig)) @@ -94,27 +163,30 @@ (define* (lower name (define private-keywords '(#:target #:zig #:inputs #:native-inputs #:outputs)) - ;; TODO: support cross-compilation - ;; It's as simple as adding some build flags to `zig-build-flags` - ;; -Dtarget=aarch64-linux-musl, for example. - (and (not target) - (bag - (name name) - (system system) - (target target) - (host-inputs `(,@(if source - `(("source" ,source)) - '()) - ,@inputs - - ;; Keep the standard inputs of 'gnu-build-system' - ;; TODO: do we need this? - ,@(standard-packages))) - (build-inputs `(("zig" ,zig) - ,@native-inputs)) - (outputs outputs) - (build zig-build) - (arguments (strip-keyword-arguments private-keywords arguments))))) + (bag + (name name) + (system system) + (target target) + (build-inputs `(,@(if source + `(("source" ,source)) + '()) + ,@`(("zig" ,zig)) + ,@native-inputs + ,@(if target '() inputs) + ,@(if target + ;; Use the standard cross inputs of + ;; 'gnu-build-system'. + (standard-cross-packages target 'host) + '()) + ;; Keep the standard inputs of 'gnu-build-system'. + ,@(standard-packages))) + (host-inputs (if target inputs '())) + (target-inputs (if target + (standard-cross-packages target 'target) + '())) + (outputs outputs) + (build (if target zig-cross-build zig-build)) + (arguments (strip-keyword-arguments private-keywords arguments)))) (define zig-build-system (build-system diff --git a/guix/build/zig-build-system.scm b/guix/build/zig-build-system.scm index d414ebfb17..2a055128dc 100644 --- a/guix/build/zig-build-system.scm +++ b/guix/build/zig-build-system.scm @@ -47,6 +47,7 @@ (define* (build #:key zig-build-flags zig-release-type ;; "safe", "fast" or "small" empty for a ;; debug build" + target #:allow-other-keys) "Build a given Zig package." @@ -56,6 +57,9 @@ (define* (build #:key "--prefix-lib-dir" "lib" "--prefix-exe-dir" "bin" "--prefix-include-dir" "include" + ,@(if target + (list (string-append "-Dtarget=" target)) + '()) ,@(if zig-release-type (list (string-append "-Drelease-" zig-release-type)) '()) @@ -63,7 +67,7 @@ (define* (build #:key (format #t "running: ~s~%" call) (apply invoke call))) -(define* (check #:key tests? +(define* (check #:key target (tests? (not target)) zig-test-flags #:allow-other-keys) "Run all the tests" -- 2.38.0