Subject: [bug#78050] [PATCH 1/5] build-system: gnu: Improve gnu-cross-build style.

From: Nicolas Graves <[email-masked]>
Date: Fri, 25 Apr 2025 02:04:46 +0200

* guix/build-system/gnu.scm
(gnu-cross-build): Use with-imported-modules around the
gnu-cross-build builder gexp.

Change-Id: I47246571b1d84a82a67a8c289fd5ad4b5a3b5aeb
---
 guix/build-system/gnu.scm | 96 ++++++++++++++++++++-------------------
 1 file changed, 49 insertions(+), 47 deletions(-)

diff --git a/guix/build-system/gnu.scm b/guix/build-system/gnu.scm
index 3a314d34b72..a71162c3005 100644
--- a/guix/build-system/gnu.scm
+++ b/guix/build-system/gnu.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2012-2024 Ludovic Courtès <[email-masked]>
+;;; Copyright © 2024 Nicolas Graves <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -520,59 +521,60 @@ (define* (gnu-cross-build name
 cross-built inputs, and NATIVE-INPUTS are inputs that run on the build
 platform."
   (define builder
-    #~(begin
-        (use-modules #$@(sexp->gexp modules))
+    (with-imported-modules imported-modules
+      #~(begin
+          (use-modules #$@(sexp->gexp modules))
 
-        (define %build-host-inputs
-          #+(input-tuples->gexp build-inputs))
+          (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-target-inputs
+            (append #$(input-tuples->gexp host-inputs)
+                    #+(input-tuples->gexp target-inputs)))
 
-        (define %build-inputs
-          (append %build-host-inputs %build-target-inputs))
+          (define %build-inputs
+            (append %build-host-inputs %build-target-inputs))
 
-        (define %outputs
-          #$(outputs->gexp outputs))
+          (define %outputs
+            #$(outputs->gexp outputs))
 
-        (gnu-build #:source #+source
-                   #:system #$system
-                   #:build #$build
-                   #:target #$target
-                   #:outputs %outputs
-                   #:inputs %build-target-inputs
-                   #:native-inputs %build-host-inputs
-                   #:search-paths '#$(sexp->gexp
-                                      (map search-path-specification->sexp
-                                           search-paths))
-                   #:native-search-paths '#$(sexp->gexp
-                                             (map
-                                              search-path-specification->sexp
-                                              native-search-paths))
-                   #:phases #$(if (pair? phases)
-                                  (sexp->gexp phases)
-                                  phases)
-                   #:locale #$locale
-                   #:separate-from-pid1? #$separate-from-pid1?
-                   #:bootstrap-scripts #$bootstrap-scripts
-                   #:configure-flags #$configure-flags
-                   #:make-flags #$make-flags
-                   #:out-of-source? #$out-of-source?
-                   #:tests? #$tests?
-                   #:test-target #$test-target
-                   #:parallel-build? #$parallel-build?
-                   #:parallel-tests? #$parallel-tests?
-                   #:patch-shebangs? #$patch-shebangs?
-                   #:license-file-regexp #$license-file-regexp
-                   #:strip-binaries? #$strip-binaries?
-                   #:validate-runpath? #$validate-runpath?
-                   #:make-dynamic-linker-cache? #$make-dynamic-linker-cache?
-                   #:license-file-regexp #$license-file-regexp
-                   #:strip-flags #$strip-flags
-                   #:strip-directories #$strip-directories)))
+          (gnu-build #:source #+source
+                     #:system #$system
+                     #:build #$build
+                     #:target #$target
+                     #:outputs %outputs
+                     #:inputs %build-target-inputs
+                     #:native-inputs %build-host-inputs
+                     #:search-paths '#$(sexp->gexp
+                                        (map search-path-specification->sexp
+                                             search-paths))
+                     #:native-search-paths '#$(sexp->gexp
+                                               (map
+                                                search-path-specification->sexp
+                                                native-search-paths))
+                     #:phases #$(if (pair? phases)
+                                    (sexp->gexp phases)
+                                    phases)
+                     #:locale #$locale
+                     #:separate-from-pid1? #$separate-from-pid1?
+                     #:bootstrap-scripts #$bootstrap-scripts
+                     #:configure-flags #$configure-flags
+                     #:make-flags #$make-flags
+                     #:out-of-source? #$out-of-source?
+                     #:tests? #$tests?
+                     #:test-target #$test-target
+                     #:parallel-build? #$parallel-build?
+                     #:parallel-tests? #$parallel-tests?
+                     #:patch-shebangs? #$patch-shebangs?
+                     #:license-file-regexp #$license-file-regexp
+                     #:strip-binaries? #$strip-binaries?
+                     #:validate-runpath? #$validate-runpath?
+                     #:make-dynamic-linker-cache? #$make-dynamic-linker-cache?
+                     #:license-file-regexp #$license-file-regexp
+                     #:strip-flags #$strip-flags
+                     #:strip-directories #$strip-directories))))
 
-  (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
+    (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
                                                   system #:graft? #f)))
     (gexp->derivation name builder
                       #:system system
-- 
2.49.0