diff mbox series

[bug#57050,v2,08/13] gnu: racket: Support cross-compiling the VM packages.

Message ID c3b1f87232f152742f0a46d87437d4cad6a205d7.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
Cross-compilation works for 'racket-vm-cgc', 'racket-vm-bc', and
'racket-vm-cs'. These changes are not enough to cross-compile
'racket-minimal' or 'racket': that would require building and loading
cross-compilation pluggins for 'racket-vm-cs', which will be much
easier once we can build the package 'raco-cross'.

* gnu/packages/racket.scm (racket-vm-cgc): Add 'this-package' when
cross-compiling.
(racket-vm-bc)[native-inputs]: Adjust accordingly.
(racket-vm-cs)[native-inputs]: Use 'racket-vm-cs' instead of
'racket-vm-bc' when cross-compiling. Adapt to changes to
'racket-vm-cgc'.
[arguments]<#:configure-flags>: Fix '--enable-scheme' for
cross-compilation.
---
 gnu/packages/racket.scm | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

Comments

Liliana Marie Prikler Aug. 11, 2022, 11:58 a.m. UTC | #1
Am Donnerstag, dem 11.08.2022 um 07:08 -0400 schrieb Philip McGrath:
> Cross-compilation works for 'racket-vm-cgc', 'racket-vm-bc', and
> 'racket-vm-cs'. These changes are not enough to cross-compile
> 'racket-minimal' or 'racket': that would require building and loading
> cross-compilation pluggins for 'racket-vm-cs', which will be much
plugins
> easier once we can build the package 'raco-cross'.
> 
> * gnu/packages/racket.scm (racket-vm-cgc): Add 'this-package' when
> cross-compiling.
> (racket-vm-bc)[native-inputs]: Adjust accordingly.
> (racket-vm-cs)[native-inputs]: Use 'racket-vm-cs' instead of
> 'racket-vm-bc' when cross-compiling. Adapt to changes to
> 'racket-vm-cgc'.
Is that needed?  Can racket-vm-cs not be "cross-bootstrapped"?
> [arguments]<#:configure-flags>: Fix '--enable-scheme' for
> cross-compilation.

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

On Thu, Aug 11, 2022, at 7:58 AM, Liliana Marie Prikler wrote:
> Am Donnerstag, dem 11.08.2022 um 07:08 -0400 schrieb Philip McGrath:
>> Cross-compilation works for 'racket-vm-cgc', 'racket-vm-bc', and
>> 'racket-vm-cs'. These changes are not enough to cross-compile
>> 'racket-minimal' or 'racket': that would require building and loading
>> cross-compilation pluggins for 'racket-vm-cs', which will be much
> plugins
>> easier once we can build the package 'raco-cross'.
>> 
>> * gnu/packages/racket.scm (racket-vm-cgc): Add 'this-package' when
>> cross-compiling.
>> (racket-vm-bc)[native-inputs]: Adjust accordingly.
>> (racket-vm-cs)[native-inputs]: Use 'racket-vm-cs' instead of
>> 'racket-vm-bc' when cross-compiling. Adapt to changes to
>> 'racket-vm-cgc'.
> Is that needed?  Can racket-vm-cs not be "cross-bootstrapped"?

I'm not sure what "cross-bootstrapped" means.

Chez Scheme is more like GCC than LLVM in that it only generates code for one target at a time. Unlike GCC, you don't have a separate executable for each backend: the C part and the pure Scheme part can be shared. For cross-compilation, you generate an "xpatch" file, a compiler plugin somewhat like a bootfile, for the target machine type. You use it by loading it into a running `scheme` process: AIUI it, as a side-effect, mutates parts of the compiler to turn it into a compiler for the target architecture. Once an "xpatch" is loaded, some parts of the host functionality are no longer accessible. Racket provides a somewhat more convenient interface, including the ability to run a copy of itself in a subprocess to drive the compilation. In keeping with Racket's overall design, the VM layer provides only primitive hooks, leaving it up to packages to provide higher-level interfaces that deal with managing native- and cross-compiled files in parallel, dependency management, and other issues.

The shorter version is that I asked Matthew Flatt how he recommended managing cross-compilation, and he strongly suggested first getting non-cross package builds working well, then reusing as much of `raco cross` as possible.

-Philip
diff mbox series

Patch

diff --git a/gnu/packages/racket.scm b/gnu/packages/racket.scm
index 31f3394fa3..ef353103d6 100644
--- a/gnu/packages/racket.scm
+++ b/gnu/packages/racket.scm
@@ -332,8 +332,11 @@  (define-public racket-vm-cgc
      (inputs (list ncurses ;; <- common to all variants (for #%terminal)
                    bash-minimal ;; <- common to all variants (for `system`)
                    libffi)) ;; <- only for BC variants
-     (native-inputs (list zuo ;; <- for all variants
-                          libtool)) ;; <- only for BC variants
+     (native-inputs (cons* zuo ;; <- for all variants
+                           libtool ;; <- only for BC variants
+                           (if (%current-target-system)
+                               (list this-package)
+                               '())))
      (outputs '("out" "debug"))
      (build-system gnu-build-system)
      (arguments
@@ -421,8 +424,10 @@  (define-public racket-vm-bc
     (inherit racket-vm-cgc)
     (name "racket-vm-bc")
     (native-inputs
-     (modify-inputs (package-native-inputs racket-vm-cgc)
-       (prepend racket-vm-cgc)))
+     (if (%current-target-system)
+         (package-native-inputs racket-vm-cgc)
+         (modify-inputs (package-native-inputs racket-vm-cgc)
+           (prepend racket-vm-cgc))))
     (arguments
      (substitute-keyword-arguments (package-arguments racket-vm-cgc)
        ((#:configure-flags _ '())
@@ -452,11 +457,17 @@  (define-public racket-vm-cs
        (prepend zlib lz4)
        (delete "libffi")))
     (native-inputs
-     (modify-inputs (package-native-inputs racket-vm-cgc)
-       (delete "libtool")
-       (prepend chez-scheme-for-racket
-                chez-nanopass-bootstrap
-                racket-vm-bc)))
+     (let ((native-inputs (package-native-inputs racket-vm-cgc)))
+       (modify-inputs (if (%current-target-system)
+                          (modify-inputs native-inputs
+                            (delete "racket-vm-cgc"))
+                          native-inputs)
+         (delete "libtool")
+         (prepend chez-scheme-for-racket
+                  chez-nanopass-bootstrap
+                  (if (%current-target-system)
+                      racket-vm-cs
+                      racket-vm-bc)))))
     (arguments
      (substitute-keyword-arguments (package-arguments racket-vm-cgc)
        ((#:phases those-phases #~%standard-phases)
@@ -470,7 +481,7 @@  (define-public racket-vm-cs
                  "--enable-libz"
                  "--enable-lz4"
                  (string-append "--enable-scheme="
-                                #$(this-package-native-input
+                                #+(this-package-native-input
                                    "chez-scheme-for-racket")
                                 "/bin/scheme")
                  #$(racket-vm-common-configure-flags)))))