Subject: [bug#68266] [PATCH 2/7] gnu: Memozise cross-binutils results.

From: Christopher Baines <[email-masked]>
Date: Fri, 5 Jan 2024 16:40:44 +0000

To ensure that it just returns a single package record for some given
arguments, as this helps to avoid poor performance of the store connection
object cache.

* gnu/packages/cross-base.scm (cross-binutils*): Move code to
cross-binutils/implementation and call it.
(cross-binutils/implementation) New procedure.
(cross-binutils/deprecated): Call cross-binutils/implementation.

Change-Id: Ic7a493177026c7a699108ab6d75482ff3c189340
---
 gnu/packages/cross-base.scm | 92 +++++++++++++++++++------------------
 1 file changed, 48 insertions(+), 44 deletions(-)

diff --git a/gnu/packages/cross-base.scm b/gnu/packages/cross-base.scm
index 6ee7b315d8..a04e4f9c9e 100644
--- a/gnu/packages/cross-base.scm
+++ b/gnu/packages/cross-base.scm
@@ -89,56 +89,60 @@ (define (contains-keyword? args)
   (find keyword? args))
 
 (define* (cross-binutils . args)
+  "Return a cross-Binutils for TARGET using BINUTILS."
   (if (or (= (length args) 1) (contains-keyword? args))
       (apply cross-binutils* args)
       (apply cross-binutils/deprecated args)))
 
+(define* (cross-binutils* target #:key (binutils binutils))
+  (cross-binutils/implementation target binutils))
+
 (define* (cross-binutils/deprecated target #:optional (binutils binutils))
   (warning (G_ "'cross-binutils' must be used with keyword arguments~%"))
-  (cross-binutils* target #:binutils binutils))
-
-(define* (cross-binutils* target #:key (binutils binutils))
-  "Return a cross-Binutils for TARGET using BINUTILS."
-  (let ((binutils (package
-                    (inherit binutils)
-                    (arguments
-                     (substitute-keyword-arguments (package-arguments
-                                                    binutils)
-                       ((#:configure-flags flags)
-                        ;; Build with `--with-sysroot' so that ld honors
-                        ;; DT_RUNPATH entries when searching for a needed
-                        ;; library.  This works because as a side effect
-                        ;; `genscripts.sh' sets `USE_LIBPATH=yes', which tells
-                        ;; elf32.em to use DT_RUNPATH in its search list.
-                        ;; See <http://sourceware.org/ml/binutils/2013-05/msg00312.html>.
-                        ;;
-                        ;; In theory choosing / as the sysroot could lead ld
-                        ;; to pick up native libs instead of target ones.  In
-                        ;; practice the RUNPATH of target libs only refers to
-                        ;; target libs, not native libs, so this is safe.
-                        `(cons "--with-sysroot=/" ,flags)))))))
-
-    ;; For Xtensa, apply Qualcomm's patch.
-    (cross (cond ((string-prefix? "xtensa-" target)
-                  (package-with-patches binutils
-                                        (search-patches
-                                         "ath9k-htc-firmware-binutils.patch")))
-                 ((target-mingw? target)
-                  (package-with-extra-patches
-                   (package-with-extra-configure-variable
-                    ;; mingw binutils does not work correctly when configured
-                    ;; with `--enable-compressed-debug-sections`. An error
-                    ;; like the following will occur whenever you try to link:
-                    ;;
-                    ;;   x86_64-w64-mingw32-ld: final link failed: bad value
-                    ;;
-                    ;; TODO: This seems like a deeper problem that warrants
-                    ;; deeper investigation.
-                    binutils "--enable-compressed-debug-sections" "no")
-                   (search-patches "binutils-mingw-w64-timestamp.patch"
-                                   "binutils-mingw-w64-deterministic.patch")))
-                 (else binutils))
-           target)))
+  (cross-binutils/implementation target binutils))
+
+(define cross-binutils/implementation
+  (mlambda (target binutils)
+    (let ((binutils (package
+                      (inherit binutils)
+                      (arguments
+                       (substitute-keyword-arguments (package-arguments
+                                                      binutils)
+                         ((#:configure-flags flags)
+                          ;; Build with `--with-sysroot' so that ld honors
+                          ;; DT_RUNPATH entries when searching for a needed
+                          ;; library.  This works because as a side effect
+                          ;; `genscripts.sh' sets `USE_LIBPATH=yes', which tells
+                          ;; elf32.em to use DT_RUNPATH in its search list.
+                          ;; See <http://sourceware.org/ml/binutils/2013-05/msg00312.html>.
+                          ;;
+                          ;; In theory choosing / as the sysroot could lead ld
+                          ;; to pick up native libs instead of target ones.  In
+                          ;; practice the RUNPATH of target libs only refers to
+                          ;; target libs, not native libs, so this is safe.
+                          `(cons "--with-sysroot=/" ,flags)))))))
+
+      ;; For Xtensa, apply Qualcomm's patch.
+      (cross (cond ((string-prefix? "xtensa-" target)
+                    (package-with-patches binutils
+                                          (search-patches
+                                           "ath9k-htc-firmware-binutils.patch")))
+                   ((target-mingw? target)
+                    (package-with-extra-patches
+                     (package-with-extra-configure-variable
+                      ;; mingw binutils does not work correctly when configured
+                      ;; with `--enable-compressed-debug-sections`. An error
+                      ;; like the following will occur whenever you try to link:
+                      ;;
+                      ;;   x86_64-w64-mingw32-ld: final link failed: bad value
+                      ;;
+                      ;; TODO: This seems like a deeper problem that warrants
+                      ;; deeper investigation.
+                      binutils "--enable-compressed-debug-sections" "no")
+                     (search-patches "binutils-mingw-w64-timestamp.patch"
+                                     "binutils-mingw-w64-deterministic.patch")))
+                   (else binutils))
+             target))))
 
 (define (cross-gcc-arguments target xgcc libc)
   "Return build system arguments for a cross-gcc for TARGET, using XGCC as the
-- 
2.41.0