Subject: [bug#53878] [PATCH v4 14/15] gnu: chez-and-racket-bootstrap: Add 'chez-scheme-for-system'.

From: Philip McGrath <[email-masked]>
Date: Sun, 20 Feb 2022 01:06:09 -0500

* gnu/packages/chez-and-racket-bootstrap.scm (chez-scheme-for-system): New
procedure.
* gnu/packages/loko.scm (loko-scheme): Use 'chez-scheme-for-system'.
* gnu/packages/emacs-xyz.scm (emacs-geiser-chez): Likewise
* gnu/packages/chez.scm (chez-srfi):
(chez-web):
(chez-sockets):
(chez-matchable):
(chez-irregex):
(chez-fmt):
(chez-mit):
(chez-scmutils): Likewise.
---
 gnu/packages/chez-and-racket-bootstrap.scm | 17 ++++++++++++++++-
 gnu/packages/chez.scm                      | 16 ++++++++--------
 gnu/packages/emacs-xyz.scm                 |  2 +-
 gnu/packages/loko.scm                      |  2 +-
 4 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/gnu/packages/chez-and-racket-bootstrap.scm b/gnu/packages/chez-and-racket-bootstrap.scm
index f8fc4c7ea1..e837d49c63 100644
--- a/gnu/packages/chez-and-racket-bootstrap.scm
+++ b/gnu/packages/chez-and-racket-bootstrap.scm
@@ -45,7 +45,8 @@ (define-module (gnu packages chez-and-racket-bootstrap)
   #:use-module (gnu packages tex)
   #:use-module (gnu packages xorg)
   #:use-module ((guix licenses)
-                #:prefix license:))
+                #:prefix license:)
+  #:export (chez-scheme-for-system))
 
 ;; Commentary:
 ;;
@@ -197,6 +198,20 @@ (define-module (gnu packages chez-and-racket-bootstrap)
 ;;
 ;; Code:
 
+(define* (chez-scheme-for-system #:optional
+                                 (system (or (%current-target-system)
+                                             (%current-system))))
+  "Return 'chez-scheme' unless only 'chez-scheme-for-racket' supports SYSTEM,
+including support for native threads."
+  (if (or
+       ;; full support upstream
+       (and=> (chez-upstream-features-for-system system)
+              (cut memq 'threads <>))
+       ;; no support anywhere
+       (not (nix-system->chez-machine system)))
+      chez-scheme
+      chez-scheme-for-racket))
+
 (define (chez-machine->nonthreaded machine)
   "Given a string MACHINE naming a Chez Scheme machine type, returns a string
 naming the nonthreaded machine type for the same architecture and OS as
diff --git a/gnu/packages/chez.scm b/gnu/packages/chez.scm
index be251798c3..d5007e0cfd 100644
--- a/gnu/packages/chez.scm
+++ b/gnu/packages/chez.scm
@@ -74,7 +74,7 @@ (define-public chez-srfi
        (file-name (git-file-name name version))))
     (build-system gnu-build-system)
     (native-inputs
-     (list chez-scheme))
+     (list (chez-scheme-for-system)))
     (arguments
      (list #:make-flags (chez-make-flags name version)
            #:test-target "test"
@@ -105,7 +105,7 @@ (define-public chez-web
           (base32 "1dq25qygyncbfq4kwwqqgyyakfqjwhp5q23vrf3bff1p66nyfl3b"))))
       (build-system gnu-build-system)
       (native-inputs
-       (list chez-scheme
+       (list (chez-scheme-for-system)
              ghostscript
              ;; FIXME: This package fails to build with the error:
              ;;     mktexpk: don't know how to create bitmap font for bchr8r
@@ -170,7 +170,7 @@ (define-public chez-sockets
           (base32 "1n5fbwwz51fdzvjackgmnsgh363g9inyxv7kmzi0469cwavwcx5m"))))
       (build-system gnu-build-system)
       (native-inputs
-       (list chez-scheme
+       (list (chez-scheme-for-system)
              chez-web
              (texlive-updmap.cfg (list texlive-pdftex))))
       (arguments
@@ -256,7 +256,7 @@ (define-public chez-matchable
     (inputs
      (list chez-srfi)) ; for tests
     (native-inputs
-     (list chez-scheme))
+     (list (chez-scheme-for-system)))
     (arguments
      (list #:make-flags (chez-make-flags name version)
            #:test-target "test"
@@ -288,7 +288,7 @@ (define-public chez-irregex
     (propagated-inputs
      (list chez-srfi)) ; for irregex-utils
     (native-inputs
-     (list chez-scheme))
+     (list (chez-scheme-for-system)))
     (arguments
      (list #:make-flags (chez-make-flags name version)
            #:test-target "test"
@@ -319,7 +319,7 @@ (define-public chez-fmt
     (propagated-inputs
      (list chez-srfi)) ; for irregex-utils
     (native-inputs
-     (list chez-scheme))
+     (list (chez-scheme-for-system)))
     (arguments
      (list #:make-flags (chez-make-flags name version)
            #:test-target "chez-check"
@@ -382,7 +382,7 @@ (define string->uninterned-symbol
     (inputs
      (list chez-srfi))       ; for tests
     (native-inputs
-     (list chez-scheme))
+     (list (chez-scheme-for-system)))
     (arguments
      (list #:make-flags (chez-make-flags name version)
            #:test-target "test"
@@ -413,7 +413,7 @@ (define-public chez-scmutils
     (inputs
      (list chez-srfi))       ; for tests
     (native-inputs
-     (list chez-scheme))
+     (list (chez-scheme-for-system)))
     (propagated-inputs
      (list chez-mit chez-srfi))
     (arguments
diff --git a/gnu/packages/emacs-xyz.scm b/gnu/packages/emacs-xyz.scm
index 6430318ec5..ccd05130ca 100644
--- a/gnu/packages/emacs-xyz.scm
+++ b/gnu/packages/emacs-xyz.scm
@@ -451,7 +451,7 @@ (define-public emacs-geiser-chez
                 (string-append
                  "(eval-after-load 'geiser-impl '" all ")"))))))))
     (inputs
-     (list chez-scheme))
+     (list (chez-scheme-for-system)))
     (propagated-inputs
      (list emacs-geiser))
     (home-page "https://nongnu.org/geiser/")
diff --git a/gnu/packages/loko.scm b/gnu/packages/loko.scm
index 74a649b8a1..a7ab12a0c4 100644
--- a/gnu/packages/loko.scm
+++ b/gnu/packages/loko.scm
@@ -71,7 +71,7 @@ (define-public loko-scheme
              #t)))))
     (native-inputs
      `(("akku" ,akku)
-       ("chez-scheme" ,chez-scheme)
+       ("chez-scheme" ,(chez-scheme-for-system))
        ("struct" ,guile-struct-pack)
        ("laesare" ,guile-laesare)
        ("pfds" ,guile-pfds)
-- 
2.32.0