From patchwork Wed Aug 2 13:24:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Pierre De Jesus DIAZ X-Patchwork-Id: 52461 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 7576127BBEA; Wed, 2 Aug 2023 14:25:35 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable 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 EBC0D27BBE2 for ; Wed, 2 Aug 2023 14:25:33 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRBqi-00025P-ON; Wed, 02 Aug 2023 09:25:12 -0400 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 1qRBqg-00025E-TI for guix-patches@gnu.org; Wed, 02 Aug 2023 09:25:11 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRBqf-0001S9-LP; Wed, 02 Aug 2023 09:25:09 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qRBqY-0005cO-1c; Wed, 02 Aug 2023 09:25:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#65016] [PATCH] gnu: cross-libc: Return #f if no libc for target. Resent-From: Jean-Pierre De Jesus DIAZ Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, efraim@flashner.co.il, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, vagrant@debian.org, guix-patches@gnu.org Resent-Date: Wed, 02 Aug 2023 13:25:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 65016 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 65016@debbugs.gnu.org Cc: Jean-Pierre De Jesus DIAZ , guix@cbaines.net, efraim@flashner.co.il, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, vagrant@debian.org X-Debbugs-Original-To: guix-patches@gnu.org X-Debbugs-Original-Xcc: guix@cbaines.net, efraim@flashner.co.il, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, vagrant@debian.org Received: via spool by submit@debbugs.gnu.org id=B.169098266921546 (code B ref -1); Wed, 02 Aug 2023 13:25:01 +0000 Received: (at submit) by debbugs.gnu.org; 2 Aug 2023 13:24:29 +0000 Received: from localhost ([127.0.0.1]:49220 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qRBq0-0005bS-KF for submit@debbugs.gnu.org; Wed, 02 Aug 2023 09:24:29 -0400 Received: from lists.gnu.org ([2001:470:142::17]:54484) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qRBpx-0005bA-VV for submit@debbugs.gnu.org; Wed, 02 Aug 2023 09:24:27 -0400 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 1qRBpr-000219-Az for guix-patches@gnu.org; Wed, 02 Aug 2023 09:24:19 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRBpo-0008TQ-61 for guix-patches@gnu.org; Wed, 02 Aug 2023 09:24:18 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3fbc63c2e84so72879865e9.3 for ; Wed, 02 Aug 2023 06:24:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foundationdevices.com; s=google; t=1690982653; x=1691587453; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=mO+bfCq1sNyINBN0o6e7QjBr38J0eEy5sIQAG+nam/M=; b=T8D7YybEqLwfAoKotAuriy3MjrXbmMhDniqnOQr8OWpw2eiOqnRzdiDZh2DdyvkDrP SkoLIQUdrRLMDuT1W/SddhCG0bxNFgeZ1YukfxiY6mFZPm7crQW2jJCJfkr865ONL82P cb2fVl0IMECbqLwKwRf7HTcjtWvWt0dA13aGLOKGpdPNGKBxQddsrvKe8hevZbmk1DUs i02GU9+E0IqNgLCM9IXjZoNG8D+9Hybj8gv/JBuThnwd6T3RQwQyR5XGYtZGZ//D4QRu tppzEaKpVQnvZisdXT4To9tzR24IG/F/j13SDnwQ0zp8ZyL0Ckzv2MpOoJbl2AaoBwI1 0Dlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690982653; x=1691587453; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=mO+bfCq1sNyINBN0o6e7QjBr38J0eEy5sIQAG+nam/M=; b=LJu8NwR9me9koYta7vu1eV9LeskFeIQ/KYpC4wOzDwg9oj2/vychRRV/1C/cw84aUy 69YhpBrFV1FfnhbYzDOQyIpkuHiOV2Ez5bRfwBGFIajAfqXteKaPakLd9TfE/xTh1qvV D1N3heC/tPhUk5WM3EmxxDqfV/ObyIh/hgvlXKqoZ/oqFjYnekkMoFoyDZK9AmQE/hJx aP/73+dG3ripffXg+pgNL3q8VxcOTPanvxLDG/VIax+Eo7Ezm52BpVRCBpmY5donzEmw jye3ToX7FqJj3I5F+NIIj9W6kBGRhbIpn7vY3sQ4hYPsGysmoQWQa1N6ykypk+2NzXqQ x6Ww== X-Gm-Message-State: ABy/qLZLbC/t0JSUys9VUGJBoEhzNtED5m7RuvWKy2vlTX38bo83C49T 8YsMy6cIHa0dafVlmtGcuEwfuzmqTc/nQt1NptL46Q== X-Google-Smtp-Source: APBJJlFJ30FASoMR1TOg4jnTi0EvMmeXkdDhI1hAYaOxwXKKDJxAcDJ7mSFBn1TLGj/x9Yu9NhcGdw== X-Received: by 2002:a1c:7505:0:b0:3fc:2e8:ea8b with SMTP id o5-20020a1c7505000000b003fc02e8ea8bmr4949484wmc.28.1690982653200; Wed, 02 Aug 2023 06:24:13 -0700 (PDT) Received: from omen15.home ([89.131.29.87]) by smtp.gmail.com with ESMTPSA id 7-20020a05600c22c700b003fe1a96845bsm1660684wmg.2.2023.08.02.06.24.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 06:24:12 -0700 (PDT) Date: Wed, 2 Aug 2023 15:24:08 +0200 Message-Id: <20230802132408.1164570-1-jean@foundationdevices.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=jean@foundationdevices.com; helo=mail-wm1-x336.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Reply-to: Jean-Pierre De Jesus DIAZ X-ACL-Warn: , Jean-Pierre De Jesus DIAZ via Guix-patches X-Patchwork-Original-From: Jean-Pierre De Jesus DIAZ via Guix-patches via From: Jean-Pierre De Jesus DIAZ 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 * gnu/packages/cross-base.scm (cross-libc): Return #f if TARGET does not contain a libc implementation. This is the common case for most of the bare metal targets like aarch64-none-elf et al. Some bare-metal targets like `avr' do include AVR Libc though, but this patch allows handling that separately in the future. As glibc now only has been tested to work on Linux and GNU Hurd it makes sense to contain it only for those targets. This essentially allows to specify targets on packages like: (arguments (list #:target "aarch64-none-elf" ...)) And it should provide the implicit cross inputs packages without a libc. And opens the door for bare-metal platform definitions on GNU Guix as it'd be nice to have proper cross toolchains and package management for bare metal packages as the industry right now relies on bundling each other's dependencies to compile entire systems. * guix/build-system/gnu.scm (standard-cross-packages): Only add libc inputs if actually present as a result of returning #f on cross-libc. Do the same for the `static' output. Signed-off-by: Jean-Pierre De Jesus DIAZ --- gnu/packages/cross-base.scm | 139 ++++++++++++++++++------------------ guix/build-system/gnu.scm | 6 +- 2 files changed, 75 insertions(+), 70 deletions(-) diff --git a/gnu/packages/cross-base.scm b/gnu/packages/cross-base.scm index 14cb365099..d24d85c179 100644 --- a/gnu/packages/cross-base.scm +++ b/gnu/packages/cross-base.scm @@ -610,74 +610,77 @@ (define* (cross-libc* target (xbinutils (cross-binutils target)) (xheaders (cross-kernel-headers target))) "Return LIBC cross-built for TARGET, a GNU triplet. Use XGCC and XBINUTILS -and the cross tool chain." - (if (target-mingw? target) - (let ((machine (substring target 0 (string-index target #\-)))) - (make-mingw-w64 machine - #:xgcc xgcc - #:xbinutils xbinutils)) - (package - (inherit libc) - (name (string-append "glibc-cross-" target)) - (arguments - (substitute-keyword-arguments - `( ;; Disable stripping (see above.) - #:strip-binaries? #f - - ;; This package is used as a target input, but it should not have - ;; the usual cross-compilation inputs since that would include - ;; itself. - #:implicit-cross-inputs? #f - - ;; We need SRFI 26. - #:modules ((guix build gnu-build-system) - (guix build utils) - (srfi srfi-26)) - - ,@(package-arguments libc)) - ((#:configure-flags flags) - `(cons ,(string-append "--host=" target) - ,(if (target-hurd? target) - `(append (list "--disable-werror" - ,@%glibc/hurd-configure-flags) - ,flags) - flags))) - ((#:phases phases) - `(modify-phases ,phases - (add-before 'configure 'set-cross-kernel-headers-path - (lambda* (#:key inputs #:allow-other-keys) - (let* ((kernel (assoc-ref inputs "kernel-headers")) - (cpath (string-append kernel "/include"))) - (for-each (cut setenv <> cpath) - ',%gcc-cross-include-paths) - (setenv "CROSS_LIBRARY_PATH" - (string-append kernel "/lib")) ; for Hurd's libihash - #t))) - ,@(if (target-hurd? target) - '((add-after 'install 'augment-libc.so - (lambda* (#:key outputs #:allow-other-keys) - (let* ((out (assoc-ref outputs "out"))) - (substitute* (string-append out "/lib/libc.so") - (("/[^ ]+/lib/libc.so.0.3") - (string-append out "/lib/libc.so.0.3" - " libmachuser.so libhurduser.so")))) - #t))) - '()))))) - - ;; Shadow the native "kernel-headers" because glibc's recipe expects the - ;; "kernel-headers" input to point to the right thing. - (propagated-inputs `(("kernel-headers" ,xheaders))) - - (native-inputs `(("cross-gcc" ,xgcc) - ("cross-binutils" ,xbinutils) - ,@(if (target-hurd? target) - `(("cross-mig" - ,(cross-mig target - #:xgcc xgcc - #:xbinutils xbinutils))) - '()) - ,@(package-inputs libc) ;FIXME: static-bash - ,@(package-native-inputs libc)))))) +and the cross tool chain. If TARGET does not have a libc then #f is returned." + (match target + ((? target-mingw?) + (let ((machine (substring target 0 (string-index target #\-)))) + (make-mingw-w64 machine + #:xgcc xgcc + #:xbinutils xbinutils))) + ((or (? target-linux?) (? target-hurd?)) + (package + (inherit libc) + (name (string-append "glibc-cross-" target)) + (arguments + (substitute-keyword-arguments + `( ;; Disable stripping (see above.) + #:strip-binaries? #f + + ;; This package is used as a target input, but it should not have + ;; the usual cross-compilation inputs since that would include + ;; itself. + #:implicit-cross-inputs? #f + + ;; We need SRFI 26. + #:modules ((guix build gnu-build-system) + (guix build utils) + (srfi srfi-26)) + + ,@(package-arguments libc)) + ((#:configure-flags flags) + `(cons ,(string-append "--host=" target) + ,(if (target-hurd? target) + `(append (list "--disable-werror" + ,@%glibc/hurd-configure-flags) + ,flags) + flags))) + ((#:phases phases) + `(modify-phases ,phases + (add-before 'configure 'set-cross-kernel-headers-path + (lambda* (#:key inputs #:allow-other-keys) + (let* ((kernel (assoc-ref inputs "kernel-headers")) + (cpath (string-append kernel "/include"))) + (for-each (cut setenv <> cpath) + ',%gcc-cross-include-paths) + (setenv "CROSS_LIBRARY_PATH" + (string-append kernel "/lib")) ; for Hurd's libihash + #t))) + ,@(if (target-hurd? target) + '((add-after 'install 'augment-libc.so + (lambda* (#:key outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out"))) + (substitute* (string-append out "/lib/libc.so") + (("/[^ ]+/lib/libc.so.0.3") + (string-append out "/lib/libc.so.0.3" + " libmachuser.so libhurduser.so")))) + #t))) + '()))))) + + ;; Shadow the native "kernel-headers" because glibc's recipe expects the + ;; "kernel-headers" input to point to the right thing. + (propagated-inputs `(("kernel-headers" ,xheaders))) + + (native-inputs `(("cross-gcc" ,xgcc) + ("cross-binutils" ,xbinutils) + ,@(if (target-hurd? target) + `(("cross-mig" + ,(cross-mig target + #:xgcc xgcc + #:xbinutils xbinutils))) + '()) + ,@(package-inputs libc) ;FIXME: static-bash + ,@(package-native-inputs libc))))) + (else #f))) ;;; Concrete cross tool chains are instantiated like this: diff --git a/guix/build-system/gnu.scm b/guix/build-system/gnu.scm index c1aa187c42..1483f6baeb 100644 --- a/guix/build-system/gnu.scm +++ b/guix/build-system/gnu.scm @@ -460,10 +460,12 @@ (define standard-cross-packages `(("cross-gcc" ,(gcc target #:xbinutils (binutils target) #:libc libc)) - ("cross-libc" ,libc) + ,@(if libc + `(("cross-libc" ,libc)) + '()) ;; MinGW's libc doesn't have a "static" output. - ,@(if (member "static" (package-outputs libc)) + ,@(if (and libc (member "static" (package-outputs libc))) `(("cross-libc:static" ,libc "static")) '()))))))))