diff mbox series

[bug#67969,2/4] guix: scons: Support cross-compilation.

Message ID cc1caf439cc7936ff6c3c009bbf0e48467bc1b10.1703248242.git.jean@foundationdevices.com
State New
Headers show
Series guix: scons: Support cross-compilation. | expand

Commit Message

Jean-Pierre De Jesus DIAZ Dec. 22, 2023, 12:37 p.m. UTC
* guix/build-system/scons.scm (lower): Add cross compilation support.

* guix/build-system/scons.scm (scons-build-cross): New procedure.

Change-Id: I90413c4b573f17455b007672f701ac81f514e057
---
 guix/build-system/scons.scm | 107 ++++++++++++++++++++++++++++++------
 1 file changed, 91 insertions(+), 16 deletions(-)
diff mbox series

Patch

diff --git a/guix/build-system/scons.scm b/guix/build-system/scons.scm
index 6cbffcab63..3db007901c 100644
--- a/guix/build-system/scons.scm
+++ b/guix/build-system/scons.scm
@@ -1,6 +1,7 @@ 
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2017 Arun Isaac <arunisaac@systemreboot.net>
 ;;; Copyright © 2021 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2023 Foundation Devices, Inc. <hello@foundationdevices.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -56,22 +57,28 @@  (define* (lower name
   (define private-keywords
     '(#:target #:scons #:inputs #:native-inputs))
 
-  (and (not target)                               ;XXX: no cross-compilation
-       (bag
-         (name name)
-         (system system)
-         (host-inputs `(,@(if source
-                              `(("source" ,source))
-                              '())
-                        ,@inputs
-
-                        ;; Keep the standard inputs of 'gnu-build-system'.
-                        ,@(standard-packages)))
-         (build-inputs `(("scons" ,scons)
-                         ,@native-inputs))
-         (outputs outputs)
-         (build scons-build)
-         (arguments (strip-keyword-arguments private-keywords arguments)))))
+  (bag
+    (name name)
+    (system system)
+    (target target)
+    (build-inputs `(("scons" ,scons)
+                    ,@(if source
+                         `(("source" ,source))
+                         '())
+                    ,@native-inputs
+
+                    ,@(if target '() inputs)
+                    ,@(if target
+                          (standard-cross-packages target 'host)
+                          '())
+                    ,@(standard-packages system)))
+    (host-inputs (if target inputs '()))
+    (target-inputs (if target
+                       (standard-cross-packages target 'target)
+                       '()))
+    (outputs outputs)
+    (build (if target scons-build-cross scons-build))
+    (arguments (strip-keyword-arguments private-keywords arguments))))
 
 (define* (scons-build name inputs
                       #:key
@@ -122,6 +129,74 @@  (define* (scons-build name inputs
                     #:graft? #f
                     #:guile-for-build guile))
 
+(define* (scons-build-cross name
+                            #:key
+                            target
+                            build-inputs target-inputs host-inputs
+                            guile source
+                            (tests? #f)
+                            (scons-flags ''())
+                            (build-targets #~'())
+                            (test-target "test")
+                            (install-targets #~'("install"))
+                            (phases '%standard-phases)
+                            (outputs '("out"))
+                            (search-paths '())
+                            (native-search-paths '())
+                            (system (%current-system))
+                            (build (nix-system->gnu-triplet system))
+                            (imported-modules %scons-build-system-modules)
+                            (modules '((guix build scons-build-system)
+                                       (guix build utils))))
+  (define builder
+    #~(begin
+        (use-modules #$@(sexp->gexp modules))
+
+        (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-inputs
+          (append %build-host-inputs %build-target-inputs))
+
+        (define %outputs
+          #$(outputs->gexp outputs))
+
+        (scons-build #:name #$name
+                     #:source #+source
+                     #:scons-flags #$(if (pair? scons-flags)
+                                         (sexp->gexp scons-flags)
+                                         scons-flags)
+                     #:system #$system
+                     #:build #$build
+                     #:target #$target
+                     #:build-targets #$build-targets
+                     #:test-target #$test-target
+                     #:tests? #$tests?
+                     #:install-targets #$install-targets
+                     #:phases #$(if (pair? phases)
+                                    (sexp->gexp phases)
+                                    phases)
+                     #: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)))))
+
+  (gexp->derivation name builder
+                    #:system system
+                    #:target target
+                    #:graft? #f
+                    #:modules imported-modules
+                    #:guile-for-build guile))
+
 (define scons-build-system
   (build-system
     (name 'scons)