From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id yLQSKrCuAmIMbQEAgWs5BA (envelope-from ) for ; Tue, 08 Feb 2022 18:56:00 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id ON25JrCuAmKmvwAAauVa8A (envelope-from ) for ; Tue, 08 Feb 2022 18:56:00 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D002133FB2 for ; Tue, 8 Feb 2022 18:55:59 +0100 (CET) Received: from localhost ([::1]:47406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHUib-0000Fi-Jb for larch@yhetil.org; Tue, 08 Feb 2022 12:55:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42356) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHSIr-00063O-2t for guix-patches@gnu.org; Tue, 08 Feb 2022 10:21:17 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:54456) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHSIh-0008Sf-N4 for guix-patches@gnu.org; Tue, 08 Feb 2022 10:21:09 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nHSIh-0006sz-Jt for guix-patches@gnu.org; Tue, 08 Feb 2022 10:21:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#53878] [RFC PATCH 4/9] gnu: chez-and-racket-bootstrap: Add utilities for Chez machine types. Resent-From: Philip McGrath Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 08 Feb 2022 15:21:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 53878 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 53878@debbugs.gnu.org Cc: Philip McGrath Received: via spool by 53878-submit@debbugs.gnu.org id=B53878.164433360726273 (code B ref 53878); Tue, 08 Feb 2022 15:21:03 +0000 Received: (at 53878) by debbugs.gnu.org; 8 Feb 2022 15:20:07 +0000 Received: from localhost ([127.0.0.1]:48333 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nHSHm-0006pb-Hd for submit@debbugs.gnu.org; Tue, 08 Feb 2022 10:20:07 -0500 Received: from mail-qt1-f175.google.com ([209.85.160.175]:37455) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nHSHi-0006oc-Ro for 53878@debbugs.gnu.org; Tue, 08 Feb 2022 10:20:04 -0500 Received: by mail-qt1-f175.google.com with SMTP id k25so14970007qtp.4 for <53878@debbugs.gnu.org>; Tue, 08 Feb 2022 07:20:02 -0800 (PST) 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=Lox4biAAsxxoQq6Fxhf7L0m7IO8uJocQ7vmE7rh9eMo=; b=d/SXfZZZKNPr3Izd1vZH+0Vl1JVAWxj1tcETStFR/LR9JdXnlEDPudcYWqo5qI0TAl lg3gM2U58beMYCGqGngN+t1PWpawLflEdkqP3PljUHRWoMMBCOycwBvrwMSQ6z8j5M90 LtekX6+xzrDofxvCQBcRnCNkLVt5EvAkCRdbvae5r7GiJanL7Hs+e9BeBxBrZgng2Z3g B8gu5WW6ZDGJ2h+9T8aijb/QsG/cKnxkscZXH7EYvKhElUxpC8ujnd2pifP5DCFTC1je 3FvwX00I55UTYq9W9Ylj/L14/l5bmBCBI+HOY9WOChpaMSwlW/BHcLNdPKGyJ69Qftcs Z2LQ== 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=Lox4biAAsxxoQq6Fxhf7L0m7IO8uJocQ7vmE7rh9eMo=; b=PD2rS2zFXF5Q7JBOlbmsdcaMkheQMIGLQAgNODxfKzjKNvH7006MOuc5V+NYBqKllY F48aT3YOSWOVgJ3jN0UWNTgJYJ1XqkQYv8/JTFLf5N1Sc39i7DcTGD0pasWe8DBnzgvT /S5NxFYNwvrH5zQHGD2QblNPOJ6PLgrSPQZ27eZw/6nhCeKeaO6po9d2bST5i+rtzUvJ 2GmSdre9tkpQp0mbUytUXQNwI58Nh6kNOSMwQy+WHoECAuq5dGaGMqy8WPTCZvIIuXkU mqdw4DBUoXt2mClK3QGfAQGI5C+NtBAhpFohjNBLWPlLuwCOVFyqNCI9WmZuVYzb2hkF kkLg== X-Gm-Message-State: AOAM533I6s+IMuyvn1SUNqtQ7Id3uEj6YMOJPWGEVQ5LQOL5kCBDNRdQ nO/3wKQVSlBHNw7ez9B8FOKG5ChWN3IYTqbvXVc= X-Google-Smtp-Source: ABdhPJwxRY4fMALJhhf9CHH/SnTYMV6okkLOetQf398LAQRbDv0nHrUPVGYXzvEwTlD8Y9xhHrB9dQ== X-Received: by 2002:ac8:5c83:: with SMTP id r3mr3381850qta.400.1644333597194; Tue, 08 Feb 2022 07:19:57 -0800 (PST) Received: from localhost (c-73-125-98-51.hsd1.fl.comcast.net. [73.125.98.51]) by smtp.gmail.com with UTF8SMTPSA id de43sm6815533qkb.4.2022.02.08.07.19.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Feb 2022 07:19:57 -0800 (PST) From: Philip McGrath Date: Tue, 8 Feb 2022 10:18:52 -0500 Message-Id: <20220208151857.1900389-4-philip@philipmcgrath.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220208151857.1900389-1-philip@philipmcgrath.com> References: <20220208151316.1897345-1-philip@philipmcgrath.com> <20220208151857.1900389-1-philip@philipmcgrath.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1644342959; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=Lox4biAAsxxoQq6Fxhf7L0m7IO8uJocQ7vmE7rh9eMo=; b=FvJbDvYC5ESTU9kVeoKukbsowLLUPQz4FRqulUAUz0wwQMK1d0FLPt+BZpdw1WbJnW2WTM TCN5hh9UN/nhu2rpL/EyQKH5tlCrwgZlGE4Y0p/RJZI5vzUPptJVQZrOsQTbjlJcf3urFp DUfdZ14nBHJBrpaQSDYFHV7XjSK/ssLSkylb+bk9rSoLOrKt5KVL82NHCMj+KINO2jXci8 lurmdOfIcLZD52PKusWUBkaCbFjQcODLPM/gh8lfz/kg46KDd2v1pCFkIprPEgFsRZF29E pxqpsurQdwBMpycEcZhCxzQwc5h8r/z/wfcXnQJjjSv8NsOsjBCq3BCFIPrH7w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1644342959; a=rsa-sha256; cv=none; b=QOjzF/z25KSTb9R6zhB3XZ8ubyJFzxiln7g5g9XL/GOERF2Dga6fZBIMQGbwr6bULPl8+B vPpQTF3HJVCFp4fbs6TRmNkx7YsMDw0siLyvFyX2NetoClZ4YpZbUlcesBvV9Mcg8x7/1O D1DheN0jF4uA6Us91CGJuNN1unNxvrNXexBe3lm9JGV7GCZ22yzfAe/atmMgQorRgQezmT 2/XEt1VTW08P9mq4QjLtUL9fK1w30pJaH6h9L6uXTgCwQ2mIFw5/dnJAIJmLu6fn54wyhp 3rZBBhpv8RkjwzZSsD449O+u7uTz0RH1GVyOyCAdDp42ODTy4BNpMOrqf74AhQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=philipmcgrath.com header.s=google header.b="d/SXfZZZ"; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -0.63 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=philipmcgrath.com header.s=google header.b="d/SXfZZZ"; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: D002133FB2 X-Spam-Score: -0.63 X-Migadu-Scanner: scn1.migadu.com X-TUID: GcSdB+iYCerv * gnu/packages/chez-and-racket-bootstrap.scm (chez-machine->unthreaded, chez-machine->upstream-restriction, chez-machine->nix-system, nix-system->chez-machine): New private functions. (%nix-arch-to-chez-alist, %nix-os-to-chez-alist): New private constants. (chez-scheme)[supported-systems]: Compute based on 'nix-system->chez-machine' and 'chez-machine->upstream-restriction'. --- gnu/packages/chez-and-racket-bootstrap.scm | 142 ++++++++++++++++++++- 1 file changed, 140 insertions(+), 2 deletions(-) diff --git a/gnu/packages/chez-and-racket-bootstrap.scm b/gnu/packages/chez-and-racket-bootstrap.scm index 11d570059b..fc1da53178 100644 --- a/gnu/packages/chez-and-racket-bootstrap.scm +++ b/gnu/packages/chez-and-racket-bootstrap.scm @@ -28,7 +28,9 @@ (define-module (gnu packages chez-and-racket-bootstrap) #:use-module (guix utils) #:use-module (guix gexp) #:use-module (ice-9 match) + #:use-module (ice-9 regex) #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) #:use-module (guix build-system gnu) #:use-module (gnu packages) #:use-module (gnu packages compression) @@ -61,6 +63,134 @@ (define-module (gnu packages chez-and-racket-bootstrap) ;; ;; Code: +(define (chez-machine->unthreaded mach) + "Given a string MACH naming a Chez Scheme machine type, returns a string +naming the unthreaded machine type for the same architecture and OS as MACH. +The returned string may share storage with MACH." + (if (eqv? #\t (string-ref mach 0)) + (substring mach 1) + mach)) +(define (chez-machine->threaded mach) + "Like @code{chez-machine->unthreaded}, but returns the threaded machine +type." + (if (eqv? #\t (string-ref mach 0)) + mach + (string-append "t" mach))) + +;; 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->upstream-restriction mach) + "Given a string MACH naming a Chez Scheme machine type, returns a symbol +naming a restriction on the upstream Chez Scheme implementation compared to +the Racket variant, or @code{#f} if no such restriction exists. The +restriction is reported for the architecture--OS pair, regardless of whether +MACH specifies a threaded or an unthreaded variant. + +Possible restrictions currently include: +@itemize @bullet +@item +@code{'no-threads}: Support for native threads is not available upstream. +@item +@code{'no-support}: The upstream release doesn't claim to support this +architecture--OS combination at all. +@end itemize + +See @code{chez-machine->nix-system} for more details about acceptable values +for MACH." + (let ((mach (chez-machine->unthreaded mach))) + (cond + ((string-prefix? "arm64" mach) + 'no-support) + ((string-prefix? "arm32" mach) + (if (string-suffix? "le" mach) + 'no-threads + 'no-support)) + ((string-prefix? "ppc32" mach) + (if (string-suffix? "le" mach) + #f + 'no-support)) + (else + #f)))) + +(define (chez-machine->nix-system mach) + "Return the Nix system type corresponding to the Chez Scheme machine type +MACH. If MACH is not a string representing a known machine type, an exception +is raised. This function does not distinguish between threaded and unthreaded +variants of MACH. + +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 the 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 ((mach (chez-machine->unthreaded mach))) + (let find-arch ((alist %nix-arch-to-chez-alist)) + (match alist + (((nix . chez) . alist) + (if (string-prefix? chez mach) + (string-append + nix "-" (let ((mach-os (substring mach (string-length chez)))) + (let find-os ((alist %nix-os-to-chez-alist)) + (match alist + (((nix . chez) . alist) + (if (equal? chez mach-os) + nix + (find-os alist))))))) + (find-arch alist))))))) + +(define* (nix-system->chez-machine #:optional (system (%current-system)) + #:key (threads? 'always)) + "Return the Chez Scheme machine type corresponding to the Nix system +identifier SYSTEM, or @code{#f} if the translation of SYSTEM to a Chez Scheme +machine type is undefined. + +When THREADS? is @code{'always} (the default), the threaded variant of the +machine type will be returned: note that the package returned by +@code{chez-scheme-for-system} will always support native threads. When +THREADS? is @code{#f}, the unthreaded machine type will be returned. If +THREADS? is @code{'upstream} (the default), the threaded variant of the +machine type will be returned if and only if it is supported by upstream Chez +Scheme (see @code{chez-machine->upstream-restriction}). If THREADS? is any +other value, an exception is raised." + (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)) + (mach (and chez-arch chez-os (string-append chez-arch chez-os)))) + (and mach + (match threads? + ('always + (chez-machine->threaded mach)) + (#f + mach) + ('upstream + (if (chez-machine->upstream-restriction mach) + mach + (chez-machine->threaded mach))))))) + +;; +;; Chez Scheme: +;; + (define nanopass (let ((version "1.9.2")) (origin @@ -264,8 +394,16 @@ (define* (stex-make #:optional (suffix "")) ;; 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 (fold delete %supported-systems - '("mips64el-linux" "armhf-linux"))) + (supported-systems + (delete + "armhf-linux" ;; <-- should work, but reportedly broken + (filter + (lambda (system) + (and=> (nix-system->chez-machine system) + (lambda (mach) + (not (eq? 'no-support + (chez-machine->upstream-restriction mach)))))) + %supported-systems))) (home-page "https://cisco.github.io/ChezScheme/") (synopsis "R6RS Scheme compiler and run-time") (description -- 2.32.0