diff mbox series

[bug#57050,v2,07/13] gnu: chez-scheme-for-racket: Support cross-compilation.

Message ID c4a4369546a20e92b6301abdc89164b7b72f59f4.1660215295.git.philip@philipmcgrath.com
State Accepted
Headers show
Series gnu: Update Racket to 8.6. Add Zuo. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git-branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Philip McGrath Aug. 11, 2022, 11:08 a.m. UTC
* gnu/packages/chez.scm (racket-cs-native-supported-system): Change to
return the applicable machine type instead of '#t'.
(chez-scheme-for-racket)[native-inputs]: When cross-compiling, add
'this-package'.
[arguments]<#:configure-flags>: When cross-compiling, supply '-m=' and
'--toolprefix='.
<#:phases>: Work around cross-compilation issues in 'build' and
'install-docs'.
(chez-scheme-for-racket-bootstrap-bootfiles): When cross-compiling,
use 'zuo' and 'chez-scheme-for-racket' instead of 'racket-vm-bc'.
[arguments]<#:phases>: Adapt 'build' phase for cross-compilation.
---
 gnu/packages/chez.scm | 85 +++++++++++++++++++++++++++++++++++--------
 1 file changed, 70 insertions(+), 15 deletions(-)

Comments

Liliana Marie Prikler Aug. 11, 2022, 11:56 a.m. UTC | #1
Am Donnerstag, dem 11.08.2022 um 07:08 -0400 schrieb Philip McGrath:
> * gnu/packages/chez.scm (racket-cs-native-supported-system): Change
> to
> return the applicable machine type instead of '#t'.
> (chez-scheme-for-racket)[native-inputs]: When cross-compiling, add
> 'this-package'.
> [arguments]<#:configure-flags>: When cross-compiling, supply '-m='
> and
> '--toolprefix='.
> <#:phases>: Work around cross-compilation issues in 'build' and
> 'install-docs'.
> (chez-scheme-for-racket-bootstrap-bootfiles): When cross-compiling,
> use 'zuo' and 'chez-scheme-for-racket' instead of 'racket-vm-bc'.
> [arguments]<#:phases>: Adapt 'build' phase for cross-compilation.
I think this patch can further be split into one for the bootstrap-
bootfiles and one for chez-scheme.  I don't know where exactly racket-
cs-native-supported-system fits into any of this and what the
dependencies for it are.

Cheers
Philip McGrath Aug. 11, 2022, 10:49 p.m. UTC | #2
Hi,

On Thu, Aug 11, 2022, at 7:56 AM, Liliana Marie Prikler wrote:
> Am Donnerstag, dem 11.08.2022 um 07:08 -0400 schrieb Philip McGrath:
>> * gnu/packages/chez.scm (racket-cs-native-supported-system): Change
>> to
>> return the applicable machine type instead of '#t'.
>> (chez-scheme-for-racket)[native-inputs]: When cross-compiling, add
>> 'this-package'.
>> [arguments]<#:configure-flags>: When cross-compiling, supply '-m='
>> and
>> '--toolprefix='.
>> <#:phases>: Work around cross-compilation issues in 'build' and
>> 'install-docs'.
>> (chez-scheme-for-racket-bootstrap-bootfiles): When cross-compiling,
>> use 'zuo' and 'chez-scheme-for-racket' instead of 'racket-vm-bc'.
>> [arguments]<#:phases>: Adapt 'build' phase for cross-compilation.
> I think this patch can further be split into one for the bootstrap-
> bootfiles and one for chez-scheme.  I don't know where exactly racket-
> cs-native-supported-system fits into any of this and what the
> dependencies for it are.
>

Among other issues, if you cross-compile the bootfiles but can't compile anything that uses the cross-compiled bootfiles, there's no reasonable way to tell if the bootfiles you've built actually work.

-Philip
diff mbox series

Patch

diff --git a/gnu/packages/chez.scm b/gnu/packages/chez.scm
index 294edca1a4..be9884b3d2 100644
--- a/gnu/packages/chez.scm
+++ b/gnu/packages/chez.scm
@@ -236,14 +236,15 @@  (define* (racket-cs-native-supported-system? #:optional
                                              (system
                                               (or (%current-target-system)
                                                   (%current-system))))
-  "Can Racket's variant of Chez Scheme generate native code for SYSTEM?
-Otherwise, SYSTEM can use only the ``portable bytecode'' backends."
+  "Can Racket's variant of Chez Scheme generate native code for SYSTEM?  If
+so, return the applicable machine type as a string.  Otherwise, when SYSTEM
+can use only the ``portable bytecode'' backends, return #f."
   (let ((chez-arch (target-chez-arch system))
         (chez-os (target-chez-os system)))
     (and (and=> (assoc-ref %chez-features-table chez-os)
                 ;; NOT assoc-ref: supported even if cdr is #f
                 (cut assoc chez-arch <>))
-         #t)))
+         (string-append "t" chez-arch chez-os))))
 
 ;;
 ;; Chez Scheme:
@@ -457,8 +458,12 @@  (define-public chez-scheme-for-racket
         (replace "chez-scheme-bootstrap-bootfiles"
           chez-scheme-for-racket-bootstrap-bootfiles)))
     (native-inputs
-     (modify-inputs (package-native-inputs chez-scheme)
-       (append zuo)))
+     (let ((native-inputs (modify-inputs (package-native-inputs chez-scheme)
+                            (append zuo))))
+       (if (%current-target-system)
+           (modify-inputs native-inputs
+             (append this-package))
+           native-inputs)))
     (arguments
      (substitute-keyword-arguments (package-arguments chez-scheme)
        ((#:out-of-source? _ #f)
@@ -472,6 +477,15 @@  (define-public chez-scheme-for-racket
        ((#:configure-flags cfg-flags #~'())
         #~`("--disable-x11"
             "--threads" ;; ok to potentially duplicate
+            #$@(if (%current-target-system)
+                   (list (string-append "-m="
+                                        (racket-cs-native-supported-system?)))
+                   '())
+            #$@(if (%current-target-system)
+                   (list (string-append "--toolprefix="
+                                        (%current-target-system)
+                                        "-"))
+                   '())
             ,@(let* ((chez+version (strip-store-file-name #$output))
                      (doc-prefix (assoc-ref %outputs "doc"))
                      (doc-dir (string-append doc-prefix
@@ -494,18 +508,42 @@  (define-public chez-scheme-for-racket
                  #$mk-flags))
        ((#:phases those-phases #~%standard-phases)
         #~(let* ((those-phases #$those-phases)
-                 (unpack (assoc-ref those-phases 'unpack)))
+                 (gnu:unpack (assoc-ref those-phases 'unpack))
+                 (gnu:build (assoc-ref those-phases 'build)))
             (modify-phases those-phases
+              (replace 'build
+                ;; need to override target for cross-compilation
+                ;; https://racket.discourse.group/t/950/19
+                (lambda* (#:key target (make-flags '()) (parallel-build? #t)
+                          #:allow-other-keys)
+                  (gnu:build #:make-flags (if target
+                                              (cons "kernel" make-flags)
+                                              make-flags)
+                             #:parallel-build? parallel-build?)))
               (replace 'install-docs
-                (lambda* (#:key make-flags #:allow-other-keys)
+                (lambda* (#:key native-inputs (make-flags '())
+                          #:allow-other-keys)
+                  ;; The tests for 'native-inputs' are cross-compilation
+                  ;; workarounds that would be better to address upstream:
+                  ;; see <https://racket.discourse.group/t/950/20>.
+                  (when native-inputs
+                    (substitute* "Makefile"
+                      (("install-docs: build \\$[(]ZUO[)]")
+                       "install-docs: $(ZUO)")))
                   (apply invoke
                          "make"
                          "install-docs"
-                         make-flags)))
+                         (if native-inputs
+                             (cons (string-append
+                                    "Scheme="
+                                    (search-input-file native-inputs
+                                                       "/bin/scheme"))
+                                   make-flags)
+                             make-flags))))
               (replace 'unpack
                 (lambda args
-                  (unpack #:source #$(or (package-source this-package)
-                                         (package-source racket-vm-bc)))))
+                  (gnu:unpack #:source #$(or (package-source this-package)
+                                             (package-source racket-vm-bc)))))
               (add-after 'unpack 'chdir
                 (lambda args
                   (chdir "racket/src/ChezScheme"))))))))
@@ -587,8 +625,12 @@  (define-public chez-scheme-for-racket-bootstrap-bootfiles
     (name "chez-scheme-for-racket-bootstrap-bootfiles")
     (version (package-version chez-scheme-for-racket))
     (source #f) ; avoid problematic cycle with racket.scm
-    (native-inputs (list chez-nanopass-bootstrap racket-vm-bc))
-    ;; TODO: cross compilation
+    (native-inputs
+     (cons* chez-nanopass-bootstrap
+            (if (%current-target-system)
+                (list zuo
+                      chez-scheme-for-racket)
+                (list racket-vm-bc))))
     (arguments
      (substitute-keyword-arguments
          (package-arguments chez-scheme-bootstrap-bootfiles)
@@ -608,9 +650,22 @@  (define-public chez-scheme-for-racket-bootstrap-bootfiles
                   #$unpack-nanopass+stex))
               (add-before 'install 'build
                 (lambda* (#:key native-inputs inputs #:allow-other-keys)
-                  (invoke (search-input-file (or native-inputs inputs)
-                                             "/opt/racket-vm/bin/racket")
-                          "rktboot/main.rkt"))))))))
+                  #$(cond
+                     ((%current-target-system)
+                      ;; cross-compiling
+                      #~(invoke
+                         (search-input-file (or native-inputs inputs)
+                                            "/bin/zuo")
+                         "makefiles/boot.zuo"
+                         (search-input-file (or native-inputs inputs)
+                                            "/bin/scheme")
+                         #$(racket-cs-native-supported-system?)))
+                     (else
+                      ;; bootstrapping
+                      #~(invoke
+                         (search-input-file (or native-inputs inputs)
+                                            "/opt/racket-vm/bin/racket")
+                         "rktboot/main.rkt"))))))))))
     (supported-systems
      (package-supported-systems chez-scheme-for-racket))
     (home-page "https://github.com/racket/ChezScheme")