From patchwork Sun May 8 20:07:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip McGrath X-Patchwork-Id: 39166 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 2464927BBEA; Sun, 8 May 2022 21:36:07 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 3236627BBE9 for ; Sun, 8 May 2022 21:36:06 +0100 (BST) Received: from localhost ([::1]:47152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nnndN-00045H-Cx for patchwork@mira.cbaines.net; Sun, 08 May 2022 16:36:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50028) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nnnEE-0003pH-Qg for guix-patches@gnu.org; Sun, 08 May 2022 16:10:07 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:33158) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nnnED-0000Fm-Uy for guix-patches@gnu.org; Sun, 08 May 2022 16:10:06 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nnnED-0002Ns-Pq for guix-patches@gnu.org; Sun, 08 May 2022 16:10:05 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#55248] [PATCH v2 7/9] gnu: chez-upstream-features-for-system: Improve implementation. Resent-From: Philip McGrath Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 08 May 2022 20:10:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55248 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 55248@debbugs.gnu.org Cc: Liliana Marie Prikler , Maxime Devos , Philip McGrath , Liliana Marie Prikler Received: via spool by 55248-submit@debbugs.gnu.org id=B55248.16520405909069 (code B ref 55248); Sun, 08 May 2022 20:10:05 +0000 Received: (at 55248) by debbugs.gnu.org; 8 May 2022 20:09:50 +0000 Received: from localhost ([127.0.0.1]:55277 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nnnDx-0002MC-TO for submit@debbugs.gnu.org; Sun, 08 May 2022 16:09:50 -0400 Received: from mail-vs1-f49.google.com ([209.85.217.49]:36778) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nnnDv-0002Lm-TV for 55248@debbugs.gnu.org; Sun, 08 May 2022 16:09:48 -0400 Received: by mail-vs1-f49.google.com with SMTP id a127so12080541vsa.3 for <55248@debbugs.gnu.org>; Sun, 08 May 2022 13:09:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philipmcgrath.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ASOED8ZT+HX4kIHd14wSy3Dx+MokroCBH0hfgSIxOpE=; b=Ezr7JH/JuwOJ6PGGBZqpdz0HieDpQi2giG/jpqSx9cZ3xU4PZgS2ZKUb3W8H88V84g /ODeF1NWZLgbVgHxnZ0dAmRex0fIZNHDSyZBtQc1OBwo0O+bsGjIizILtRsO+4hkTnsK 1nYviT/nlY/duyCUiuaSN44ohqtYU7AHPSWhbuXyGTd3LMe5ANwn4CS7NQVp8RPdiw79 X8dbeP2qGvjEO4Jq4HtE2FAUTY/64lfkot8mDuaB6uSgnzOY4z+mceRvdN4lyaVFcbCE axQn06iwz3og72IED1e8LEhVGrqDXdDfCy/82lI3/HBigk6zI1YZ+VQVpZq6tZc2cTNJ xd/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ASOED8ZT+HX4kIHd14wSy3Dx+MokroCBH0hfgSIxOpE=; b=NWD/sFxC/EM9pUBfyxoKh9UPHaPKPibuh6bX1883WgNR1scMsuZDEfx4B/hU7krPev JtoB3DISFZb65YJdXws+dJ/6o5s0M8fX7l3kJ9KC3cAfiJ2AjH4GU4kmmiVRuSIFvDuv 6OsVVsJPYbERzh1V/R0eMJi53ijZbvHBgQw4FWGB27v3dkslyVi29NlZDyJ3ELpW2kHv r8p9SAT6wZapq/4u4VaEjIPcf+mavsHDN15TBz3QLdgn4Uq1HFe/md8J+8qJdN57Umhh soTq/76yfTk3e3TLeACJZIaoagCVILyXgp06WN4d22CLsesCQTklTVO//4iAZSN4S/Rj TWVA== X-Gm-Message-State: AOAM532uS+bDEMcBU2j5nsXnjz8eo17hfJtyMR6Rn+4U/b//GctNqHtJ I+1nq5eY/J0sgDJ/xPyd6yxXAHmc29I4VX54 X-Google-Smtp-Source: ABdhPJw9VmS1XREQ5m6Cuoj3esucVfH1Fdq3Jz4+Vn0EbmUjZOTmXY6TGuzH56fDPuXi5WWZQKUhuQ== X-Received: by 2002:a67:6684:0:b0:32d:c24:98b7 with SMTP id a126-20020a676684000000b0032d0c2498b7mr6343567vsc.78.1652040582261; Sun, 08 May 2022 13:09:42 -0700 (PDT) Received: from localhost (c-73-125-98-51.hsd1.fl.comcast.net. [73.125.98.51]) by smtp.gmail.com with UTF8SMTPSA id b2-20020ab06902000000b003626f894df9sm1323929uas.39.2022.05.08.13.09.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 08 May 2022 13:09:42 -0700 (PDT) From: Philip McGrath Date: Sun, 8 May 2022 16:07:50 -0400 Message-Id: <3deb541efd59acd25410f7019670071368291ad4.1652039837.git.philip@philipmcgrath.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches This commit is a follow-up to b8fc9169515ef1a6d6037c84e30ad308e5418b6f. While that commit fixed a breaking build, this one begins to address the faulty assumptions that lead to the failure: see also . In this commit, we reimplement 'chez-upstream-features-for-system' using the new '%chez-features-table', which explicitly specifies platform support for both 'chez-scheme' and 'chez-scheme-for-racket', rather than assuming a non-false result from 'nix-system->chez-machine' means that the system is supported. The remaining uses of 'nix-system->chez-machine' still make that incorrect assumption and must be repaired in a future commit. * gnu/packages/chez.scm (%nix-arch-to-chez-alist, %nix-os-to-chez-alist): Replace with ... (target-chez-arch, target-chez-os): ... these new variables. (nix-system->chez-machine): Rewrite using them. (%chez-features-table): New variable. (chez-upstream-features-for-system): Rewrite using it. (chez-scheme)[supported-systems]: Update armhf-linux comment. (chez-scheme-bootstrap-bootfiles)[supported-systems]: Use 'chez-upstream-features-for-system'. (chez-machine->nonthreaded, chez-machine->threaded, chez-machine->nix-system): Remove unused functions. --- gnu/packages/chez.scm | 234 ++++++++++++++++++++++++------------------ 1 file changed, 134 insertions(+), 100 deletions(-) diff --git a/gnu/packages/chez.scm b/gnu/packages/chez.scm index dd485d37e1..41f083e0ac 100644 --- a/gnu/packages/chez.scm +++ b/gnu/packages/chez.scm @@ -49,8 +49,6 @@ (define-module (gnu packages chez) #:use-module (srfi srfi-26) #:export (chez-scheme-for-system nix-system->chez-machine - chez-machine->nonthreaded - chez-machine->threaded unpack-nanopass+stex)) ;; Commentary: @@ -82,68 +80,57 @@ (define* (chez-scheme-for-system #:optional 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 -MACHINE. The returned string may share storage with MACHINE." - ;; Chez Scheme documentation consistently uses "nonthreaded" rather than - ;; e.g. "unthreaded" - (if (eqv? #\t (string-ref machine 0)) - (substring machine 1) - machine)) -(define (chez-machine->threaded machine) - "Like @code{chez-machine->nonthreaded}, but returns the threaded machine -type." - (if (eqv? #\t (string-ref machine 0)) - machine - (string-append "t" machine))) - -;; Based on the implementation from raco-cross-lib/private/cross/platform.rkt -;; in https://github.com/racket/raco-cross. -;; For supported platforms, refer to release_notes/release_notes.stex in the -;; upstream Chez Scheme repository or to racket/src/ChezScheme/README.md -;; in https://github.com/racket/racket. -(define %nix-arch-to-chez-alist - `(("x86_64" . "a6") - ("i386" . "i3") - ("aarch64" . "arm64") - ("armhf" . "arm32") ;; Chez supports ARM v6+ - ("ppc" . "ppc32"))) -(define %nix-os-to-chez-alist - `(("w64-mingw32" . "nt") - ("darwin" . "osx") - ("linux" . "le") - ("freebsd" . "fb") - ("openbsd" . "ob") - ("netbsd" . "nb") - ("solaris" . "s2"))) - -(define (chez-machine->nix-system machine) - "Return the Nix system type corresponding to the Chez Scheme machine type -MACHINE. If MACHINE is not a string representing a known machine type, an -exception is raised. This function does not distinguish between threaded and -nonthreaded variants of MACHINE. +(define* (target-chez-arch #:optional (system + (or (%current-target-system) + (%current-system)))) + "Return a string representing the architecture of SYSTEM as used in Chez +Scheme machine types, or '#f' if none is defined." + (cond + ((target-x86-64? system) + "a6") + ((target-x86-32? system) + "i3") + ((target-aarch64? system) + "arm64") + ((target-arm32? system) + "arm32") + ((target-ppc64le? system) + #f) + ((target-ppc32? system) + "ppc32") + ((target-riscv64? system) + #f) + (else + #f))) -Note that this function only handles Chez Scheme machine types in the -strictest sense, not other kinds of descriptors sometimes used in place of a -Chez Scheme machine type by Racket, such as @code{\"pb\"}, @code{#f}, or -@code{\"racket\"}. (When using such extensions, the Chez Scheme machine type -for the host system is often still relevant.)" - (let ((machine (chez-machine->nonthreaded machine))) - (let find-arch ((alist %nix-arch-to-chez-alist)) - (match alist - (((nix . chez) . alist) - (if (string-prefix? chez machine) - (string-append - nix "-" (let ((machine-os - (substring machine (string-length chez)))) - (let find-os ((alist %nix-os-to-chez-alist)) - (match alist - (((nix . chez) . alist) - (if (equal? chez machine-os) - nix - (find-os alist))))))) - (find-arch alist))))))) +(define* (target-chez-os #:optional (system (or (%current-target-system) + (%current-system)))) + "Return a string representing the operating system kernel of SYSTEM as used +in Chez Scheme machine types, or '#f' if none is defined." + ;; e.g. "le" includes both GNU/Linux and Android + (cond + ((target-linux? system) + "le") + ((target-hurd? system) + #f) + ((target-mingw? system) + "nt") + ;; missing (guix utils) predicates + ;; cf. https://github.com/NixOS/nixpkgs/blob/master/lib/systems/doubles.nix + ((string-suffix? "-darwin" system) + "osx") + ((string-suffix? "-freebsd" system) + "fb") + ((string-suffix? "-openbsd" system) + "ob") + ((string-suffix? "-netbsd" system) + "nb") + ;; Nix says "x86_64-solaris", but accommodate "-solaris2" + ((string-contains system "solaris") + "s2") + ;; unknown + (else + #f))) (define* (nix-system->chez-machine #:optional (system (or (%current-target-system) @@ -153,16 +140,81 @@ (define* (nix-system->chez-machine #:optional machine type is undefined. It is unspecified whether the resulting string will name a threaded or a -nonthreaded machine type: when the distinction is relevant, use -@code{chez-machine->nonthreaded} or @code{chez-machine->threaded} to adjust -the result." - (let* ((hyphen (string-index system #\-)) - (nix-arch (substring system 0 hyphen)) - (nix-os (substring system (+ 1 hyphen))) - (chez-arch (assoc-ref %nix-arch-to-chez-alist nix-arch)) - (chez-os (assoc-ref %nix-os-to-chez-alist nix-os))) +nonthreaded machine type." + (let* ((chez-arch (target-chez-arch system)) + (chez-os (target-chez-os system))) (and chez-arch chez-os (string-append chez-arch chez-os)))) +(define %chez-features-table + ;; An alist of alists mapping: + ;; os -> arch -> (or/c #f (listof symbol?)) + ;; where: + ;; - `os` is a string for the OS part of a Chez Scheme machine type; and + ;; - `arch` is a string for the architecture part of a Chez machine type. + ;; + ;; The absence of an entry for a given arch--os pair means that neither + ;; upstream Chez Scheme nor the Racket variant can generate native code for + ;; that system. (The Racket variant can still provide support via its + ;; ``portable bytecode'' backends and optional compilation to C.) A value + ;; of `#f` means that upstream Chez Scheme does not support the arch--os + ;; pair at all, but the Racket variant does. A list has the same meaning as + ;; a result from `chez-upstream-features-for-system`. + ;; + ;; The arch--os pairs marked "commented out" have been commented out in the + ;; STeX source for the upstream release notes since the initial release as + ;; free software, but they are reported to work and/or have been described + ;; as supported by upstream maintainers. + ;; + ;; For this overall approach to make sense, we assume that Racket's variant + ;; of Chez Scheme can generate native code for a superset of the platforms + ;; supported upstream, supports threads on all platforms it supports at all + ;; (because they are needed for Racket), and doesn't need bootstrap + ;; bootfiles. Those assumptions have held for several years. + '(;; Linux + ("le" + ("i3" threads bootstrap-bootfiles) + ("a6" threads bootstrap-bootfiles) + ("arm32" bootstrap-bootfiles) + ("arm64" . #f) + ("ppc32" threads)) + ;; FreeBSD + ("fb" + ("i3" threads) ;; commented out + ("a6" threads) ;; commented out + ("arm32" . #f) + ("arm64" . #f) + ("ppc32" . #f)) + ;; OpenBSD + ("ob" + ("i3" threads) ;; commented out + ("a6" threads) ;; commented out + ("arm32" . #f) + ("arm64" . #f) + ("ppc32" . #f)) + ;; NetBSD + ("nb" + ("i3" threads) ;; commented out + ("a6" threads) ;; commented out + ("arm32" . #f) + ("arm64" . #f) + ("ppc32" . #f)) + ;; OpenSolaris / OpenIndiana / Illumos + ("s2" + ("i3" threads) ;; commented out + ("a6" threads)) ;; commented out + ;; Windows + ("nt" + ("i3" threads bootstrap-bootfiles) + ("a6" threads bootstrap-bootfiles) + ;; ^ threads "experiemental", but reportedly fine + ("arm64" . #f)) + ;; Darwin + ("osx" + ("i3" threads bootstrap-bootfiles) + ("a6" threads bootstrap-bootfiles) + ("arm64" . #f) + ("ppc32" . #f)))) + (define* (chez-upstream-features-for-system #:optional (system (or (%current-target-system) @@ -172,20 +224,14 @@ (define* (chez-upstream-features-for-system #:optional does not support SYSTEM at all. If native threads are supported, the returned list will include -@code{'threads}. Other feature symbols may be added in the future." - (cond - ((not (nix-system->chez-machine system)) - #f) - ((target-aarch64? system) - #f) - ((target-arm32? system) - (and (target-linux? system) - '())) - ((target-ppc32? system) - (and (target-linux? system) - '(threads))) - (else - '(threads)))) +@code{'threads}. If bootstrap bootfiles for SYSTEM are distributed in the +upstream Chez Scheme repository, the returned list will include +@code{'bootstrap-bootfiles}. Other feature symbols may be added in the +future." + (let ((chez-arch (target-chez-arch system)) + (chez-os (target-chez-os system))) + (and=> (assoc-ref %chez-features-table chez-os) + (cut assoc-ref <> chez-arch)))) ;; ;; Chez Scheme: @@ -365,14 +411,9 @@ (define-public chez-scheme ((pth) (symlink pth "csug.pdf"))))))))) - ;; Chez Scheme does not have a MIPS backend. - ;; FIXME: Debian backports patches to get armhf working. - ;; We should too. It is the Chez machine type arm32le - ;; (no threaded version upstream yet, though there is in - ;; Racket's fork), more specifically (per the release notes) ARMv6. (supported-systems (delete - "armhf-linux" ;; <-- should work, but reportedly broken + "armhf-linux" ;; XXX reportedly broken, needs checking (filter chez-upstream-features-for-system %supported-systems))) (home-page "https://cisco.github.io/ChezScheme/") @@ -471,16 +512,9 @@ (define-public chez-scheme-bootstrap-bootfiles (list #:install-plan #~`(("boot/" "lib/chez-scheme-bootfiles")))) (supported-systems - ;; Upstream only distributes pre-built bootfiles for - ;; arm32le and t?(i3|a6)(le|nt|osx) (filter (lambda (system) - (let ((machine (and=> (nix-system->chez-machine system) - chez-machine->nonthreaded))) - (or (equal? "arm32le" machine) - (and machine - (member (substring machine 0 2) '("i3" "a6")) - (or-map (cut string-suffix? <> machine) - '("le" "nt" "osx")))))) + (and=> (chez-upstream-features-for-system system) + (cut memq 'bootstrap-bootfiles <>))) %supported-systems)) (synopsis "Chez Scheme bootfiles (binary seed)") (description