Subject: Re: bug#63641: [PATCH 0/8] Add libc specific to Hurd and update components

From: Ludovic Courtès <[email-masked]>
Date: Wed, 14 Jun 2023 11:29:21 +0200

Hello Janneke & Josselin,

Janneke Nieuwenhuizen <[email-masked]> skribis:

> Janneke Nieuwenhuizen writes:

[...]

>> As discussed on IRC, I found that we're still building glibc-2.35 during
>> commencement.  I overlooked that this recent patch of yours made these
>> changes in commencement, so I already made patches for this (attached).
>
> Even with these patches (on wip-hurd now), gcc-toolchain still depends
> on glibc-2.35 for offload builds, as you can see when doing
>
>     ./pre-inst-env guix build --system=i568-gnu -d gcc-toolchain
>
> from GNU/Linux.  When running this same build in a childhurd, the
> glibc-2.35 dependency is gone.  Note that gcc-final, i.e.
>
>     ./pre-inst-env guix build --system=i568-gnu -d \
>        -e '(@@ (gnu packages commencement) gcc-final)'
>
> does not depend ond glibc-2.35, but both glibc-final and
> glibc-final-with-bootstrap-bash build 2.35 when using --system.

Turns out that this was because ‘%final-inputs’ now also needs to be
parameterized by system type so it returns the right ‘glibc-final’
package.  Patch below.

Josselin, Janneke: could you squash this with the original
‘libc-for-target’ patch?

(Eventually we should update callers of ‘standard-packages’ so they pass
the ‘system’ argument.)

Thanks,
Ludo’.

diff --git a/gnu/packages/base.scm b/gnu/packages/base.scm
index 9435161969..7fb02cb3e8 100644
--- a/gnu/packages/base.scm
+++ b/gnu/packages/base.scm
@@ -1677,6 +1677,6 @@ (define-public (%final-inputs)
   "Return the list of \"final inputs\"."
   ;; Avoid circular dependency by lazily resolving 'commencement'.
   (let ((iface (resolve-interface '(gnu packages commencement))))
-    (module-ref iface '%final-inputs)))
+    ((module-ref iface '%final-inputs) (%current-system))))
 
 ;;; base.scm ends here
diff --git a/gnu/packages/commencement.scm b/gnu/packages/commencement.scm
index 055e14ba68..fb67b272a1 100644
--- a/gnu/packages/commencement.scm
+++ b/gnu/packages/commencement.scm
@@ -3406,45 +3406,49 @@ (define sed-final
     (package/inherit sed (native-inputs `(("perl" ,perl-boot0))))))
 
 (define-public %final-inputs
-  ;; Final derivations used as implicit inputs by 'gnu-build-system'.  We
-  ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
-  ;; used for origins that have patches, thereby avoiding circular
-  ;; dependencies.
-  (let ((finalize (compose with-boot6
-                           package-with-bootstrap-guile)))
-    `(,@(map (match-lambda
-               ((name package)
-                (list name (finalize package))))
-             `(("tar" ,tar)
-               ("gzip" ,gzip)
-               ("bzip2" ,bzip2)
-               ("file" ,file)
-               ("diffutils" ,diffutils)
-               ("patch" ,patch)
-               ("findutils" ,findutils)
-               ("gawk" ,gawk)))
-      ("sed" ,sed-final)
-      ("grep" ,grep-final)
-      ("xz" ,xz-final)
-      ("coreutils" ,coreutils-final)
-      ("make" ,gnu-make-final)
-      ("bash" ,bash-final)
-      ("ld-wrapper" ,ld-wrapper)
-      ("binutils" ,binutils-final)
-      ("gcc" ,gcc-final)
-      ("libc" ,glibc-final)
-      ("libc:static" ,glibc-final "static")
-      ("locales" ,glibc-utf8-locales-final))))
+  ;; The 'glibc-final' package is not the same depending on what system is
+  ;; targeted, so this whole list must be parameterized.
+  (mlambda (system)
+    ;; Final derivations used as implicit inputs by 'gnu-build-system'.  We
+    ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
+    ;; used for origins that have patches, thereby avoiding circular
+    ;; dependencies.
+    (let ((finalize (compose with-boot6
+                             package-with-bootstrap-guile)))
+      `(,@(map (match-lambda
+                 ((name package)
+                  (list name (finalize package))))
+               `(("tar" ,tar)
+                 ("gzip" ,gzip)
+                 ("bzip2" ,bzip2)
+                 ("file" ,file)
+                 ("diffutils" ,diffutils)
+                 ("patch" ,patch)
+                 ("findutils" ,findutils)
+                 ("gawk" ,gawk)))
+        ("sed" ,sed-final)
+        ("grep" ,grep-final)
+        ("xz" ,xz-final)
+        ("coreutils" ,coreutils-final)
+        ("make" ,gnu-make-final)
+        ("bash" ,bash-final)
+        ("ld-wrapper" ,ld-wrapper)
+        ("binutils" ,binutils-final)
+        ("gcc" ,gcc-final)
+        ("libc" ,glibc-final)
+        ("libc:static" ,glibc-final "static")
+        ("locales" ,glibc-utf8-locales-final)))))
 
 (define-public canonical-package
-  (let ((name->package (fold (lambda (input result)
-                               (match input
-                                 ((_ package . outputs)
-                                  (vhash-cons (package-full-name package)
-                                              package result))))
-                             vlist-null
-                             `(("guile" ,guile-final)
-                               ,@%final-inputs))))
+  (let ((name->package (mlambda (system)
+                         (fold (lambda (input result)
+                                 (match input
+                                   ((_ package . outputs)
+                                    (vhash-cons (package-full-name package)
+                                                package result))))
+                               vlist-null
+                               `(("guile" ,guile-final)
+                                 ,@(%final-inputs system))))))
     (lambda (package)
       "Return the 'canonical' variant of PACKAGE---i.e., if PACKAGE is one of
 the implicit inputs of 'gnu-build-system', return that one, otherwise return
@@ -3454,7 +3458,8 @@ (define-public canonical-package
 COREUTILS-FINAL vs. COREUTILS, etc."
       ;; XXX: This doesn't handle dependencies of the final inputs, such as
       ;; libunistring, GMP, etc.
-      (match (vhash-assoc (package-full-name package) name->package)
+      (match (vhash-assoc (package-full-name package)
+                          (name->package (%current-system)))
         ((_ . canon)
          ;; In general we want CANON, except if we're cross-compiling: CANON
          ;; uses explicit inputs, so it is "anchored" in the bootstrapped
@@ -3536,7 +3541,8 @@ (define* (make-gcc-toolchain gcc
       ;; install everything that we need, and (2) to make sure ld-wrapper comes
       ;; before Binutils' ld in the user's profile.
       (inputs `(("gcc" ,gcc)
-                ("ld-wrapper" ,(car (assoc-ref %final-inputs "ld-wrapper")))
+                ("ld-wrapper" ,(car (assoc-ref (%final-inputs (%current-system))
+                                               "ld-wrapper")))
                 ("binutils" ,binutils-final)
                 ("libc" ,libc)
                 ("libc-debug" ,libc "debug")
diff --git a/guix/build-system/gnu.scm b/guix/build-system/gnu.scm
index 3308302472..c1aa187c42 100644
--- a/guix/build-system/gnu.scm
+++ b/guix/build-system/gnu.scm
@@ -266,13 +266,13 @@ (define (package-with-restricted-references p refs)
       p))
 
 
-(define (standard-packages)
+(define* (standard-packages #:optional (system (%current-system)))
   "Return the list of (NAME PACKAGE OUTPUT) or (NAME PACKAGE) tuples of
 standard packages used as implicit inputs of the GNU build system."
 
   ;; Resolve (gnu packages commencement) lazily to hide circular dependency.
   (let ((distro (resolve-module '(gnu packages commencement))))
-    (module-ref distro '%final-inputs)))
+    ((module-ref distro '%final-inputs) system)))
 
 (define* (lower name
                 #:key source inputs native-inputs outputs target
@@ -303,7 +303,7 @@ (define* (lower name
                           (standard-cross-packages target 'host)
                           '())
                     ,@(if implicit-inputs?
-                          (standard-packages)
+                          (standard-packages system)
                           '())))
     (host-inputs (if target inputs '()))
 
diff --git a/guix/scripts/refresh.scm b/guix/scripts/refresh.scm
index 9676271542..02716abc12 100644
--- a/guix/scripts/refresh.scm
+++ b/guix/scripts/refresh.scm
@@ -228,7 +228,8 @@ (define (options->update-specs opts)
     (let* ((input->package (match-lambda
                              ((name (? package? package) _ ...) package)
                              (_ #f)))
-           (final-inputs   (map input->package %final-inputs))
+           (final-inputs   (map input->package
+                                (%final-inputs (%current-system))))
            (core           (append final-inputs
                                    (append-map (compose (cut filter-map input->package <>)
                                                         package-transitive-inputs)