unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Jean-Pierre De Jesus DIAZ via Guix-patches via <guix-patches@gnu.org>
To: 65016@debbugs.gnu.org
Cc: Jean-Pierre De Jesus DIAZ <jean@foundationdevices.com>,
	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
Subject: [bug#65016] [PATCH] gnu: cross-libc: Return #f if no libc for target.
Date: Wed,  2 Aug 2023 15:24:08 +0200	[thread overview]
Message-ID: <20230802132408.1164570-1-jean@foundationdevices.com> (raw)

* 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 <jean@foundationdevices.com>
---
 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)))
 
 \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"))
                    '()))))))))
 
-- 
2.34.1





             reply	other threads:[~2023-08-02 13:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-02 13:24 Jean-Pierre De Jesus DIAZ via Guix-patches via [this message]
2023-10-05 15:20 ` bug#65016: [PATCH] gnu: cross-libc: Return #f if no libc for target Mathieu Othacehe

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

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230802132408.1164570-1-jean@foundationdevices.com \
    --to=guix-patches@gnu.org \
    --cc=65016@debbugs.gnu.org \
    --cc=dev@jpoiret.xyz \
    --cc=efraim@flashner.co.il \
    --cc=guix@cbaines.net \
    --cc=jean@foundationdevices.com \
    --cc=ludo@gnu.org \
    --cc=me@tobias.gr \
    --cc=othacehe@gnu.org \
    --cc=rekado@elephly.net \
    --cc=vagrant@debian.org \
    --cc=zimon.toutoune@gmail.com \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).