From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id WPcuDq8lGmJTJQAAgWs5BA (envelope-from ) for ; Sat, 26 Feb 2022 14:05:51 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id CCmwCq8lGmKZcwEAauVa8A (envelope-from ) for ; Sat, 26 Feb 2022 14:05:51 +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 A76282A03D for ; Sat, 26 Feb 2022 14:05:50 +0100 (CET) Received: from localhost ([::1]:53878 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nNwlh-0000zJ-Ku for larch@yhetil.org; Sat, 26 Feb 2022 08:05:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:44722) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNwk5-00074H-Cq for guix-patches@gnu.org; Sat, 26 Feb 2022 08:04:09 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:60582) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nNwk5-0003CN-3W for guix-patches@gnu.org; Sat, 26 Feb 2022 08:04:09 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nNwk4-0005YW-Tg; Sat, 26 Feb 2022 08:04:08 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#53878] [PATCH v5 11/22] gnu: chez: Add utilities for Chez machine types. Resent-From: Philip McGrath Original-Sender: "Debbugs-submit" Resent-CC: philip@philipmcgrath.com, guix-patches@gnu.org Resent-Date: Sat, 26 Feb 2022 13:04:08 +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, Liliana Marie Prikler , zimoun Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxime Devos , Attila Lendvai , Malte Gerdes , raingloom , philip@philipmcgrath.com X-Debbugs-Original-Xcc: philip@philipmcgrath.com Received: via spool by 53878-submit@debbugs.gnu.org id=B53878.164588064321258 (code B ref 53878); Sat, 26 Feb 2022 13:04:08 +0000 Received: (at 53878) by debbugs.gnu.org; 26 Feb 2022 13:04:03 +0000 Received: from localhost ([127.0.0.1]:54452 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nNwjz-0005WY-0Z for submit@debbugs.gnu.org; Sat, 26 Feb 2022 08:04:03 -0500 Received: from mail-qk1-f182.google.com ([209.85.222.182]:41507) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nNwjj-0005Ut-HJ for 53878@debbugs.gnu.org; Sat, 26 Feb 2022 08:03:48 -0500 Received: by mail-qk1-f182.google.com with SMTP id d84so6786149qke.8 for <53878@debbugs.gnu.org>; Sat, 26 Feb 2022 05:03:47 -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=Mlc/qhGedBkcO/u3jAnfRZ74tW1eDlJyXNhnlOfQlJM=; b=MFwR+BllMo6vD6nqhDC2Pbup/TnBXRWm58D6VBfRPC2ts6x4Th6Th3Ozsz2q4ai34c WQD9LPiC1uFQj3wwbLur4RWLkktv9R0LW5eYZ64A1qMyh+VO356KV252vtHHgOuuJ4d5 CEtSQRg1IDSAlYUjZAsaDkfZF/rCOVkxKFTznAb/ispnaoF4+ALA5FnFInRl6+y4lXFq 8wFvujB1eX9IQD/SIA42isrw7LXXzFOhJkI6GYKcVH1mrc3mm/aarKU0evVHvPY+/mJt zAEly6gefgaFNGiB4clFXqnzbIIYsVU1UI+QUxx4pEOKLizcxArVM9xsnEXt5QwZOoX9 YQbw== 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=Mlc/qhGedBkcO/u3jAnfRZ74tW1eDlJyXNhnlOfQlJM=; b=rMPY1kZO4DDrxzp04ITq+ndn+u0kkK9EnK/vlx1JBWtxKuMtWZqpP/DM6q12NFzCj2 qLGWBBpzPOk281A01YiNGqP6mYtSk4wNqpXFLIksmJ2vuS0tCEig7S72KlDrRwwp650p lDISla4b94bboqiTxxXGk7agRJXySP1j9tA/nZ5qeoNGrcIlmgSb+AnZK+diIDyQgYj0 ikN9bqcz5s0n31p4J7IW1xhvrMToC9FuNY4rR4KLDaSZzIbyPgVbhvf1Q2WiIuHBzkBU Cx9EEpixgoW97U9VRIzq4BOLmZArRMn86ZjFKEKgbGSzSkWrCvbSdYXwFWQM1azrmDGX zv5g== X-Gm-Message-State: AOAM530B50ns8MY5FQxXtcRCxqQBRqBFqHN3dEpLE5V8kpxPFNw+T+86 IHwLXSU0AeCk9Y7VrZ+9NqWQKq1HA1hUOUgeOk8= X-Google-Smtp-Source: ABdhPJyM41EvnKU2hkGODW8f5uwdwQm24sORkWPjr83+TvvaU+up5BgrIezNBi4ejTBZfKubtLWujA== X-Received: by 2002:a37:610c:0:b0:5f1:83b8:a6c9 with SMTP id v12-20020a37610c000000b005f183b8a6c9mr7116053qkb.196.1645880621774; Sat, 26 Feb 2022 05:03:41 -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 192-20020a3704c9000000b00648d50e398asm2531270qke.109.2022.02.26.05.03.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 26 Feb 2022 05:03:41 -0800 (PST) From: Philip McGrath Date: Sat, 26 Feb 2022 08:02:43 -0500 Message-Id: <20220226130254.1301333-12-philip@philipmcgrath.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220226130254.1301333-1-philip@philipmcgrath.com> References: <20220220060610.178131-1-philip@philipmcgrath.com> <20220226130254.1301333-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=1645880750; 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=Mlc/qhGedBkcO/u3jAnfRZ74tW1eDlJyXNhnlOfQlJM=; b=WHF/qNazoF97D8r1lOm8QWMkv0CNtppWNKrgV8whFnJk2KRMbqIlfnMIR2+t0NxgMZy8+z D3ZiPgFwa9glvAdX5UXuDQ03tqHVEK4fvn7pzSELzLfJVUdsrlK2XkHIFHquv178ICJ6D3 6NasteR5SxWTtPRz/jkfq3tqHu0CQoJE6h8k7Im40WBF9oLqY/+ZB/EqoSFcSr3zAYAUiw Sf+nGcEsAAIT4xOPzwCVrABHBrUzZ9h81Mizp8LNex/SfTuT+9V9oZMpzGx8t04NxC4QjT KWZELxi6ijQ3kOYpohqefTNyewD/H329Wzz7EZz+cf45YOzTnJkbmqO/C69SIQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1645880750; a=rsa-sha256; cv=none; b=s+QQSilj0Fg9A7/+psSVAxoDVve+OQcdsevo4FGPYj+Wn3mujbhot16ivXuA6HXgtnbzz8 uMIjW8cd1qIxfn/D9tDHAGWuskskk8nLu+mshWo+/d6clw4KbmwCtEobbIeUH+bPU4aCua 9VGSDCf4RrwiOObdmuxvrci439mKnWloe0ncEv52wkCRyLoT4FNTN1bUygkWPmv2+35DbX lppRm5SyM5r1hVqdENsqKtcK9jBn56zQkpDp8AenqizlTkGzE9l3NVCNw949Z9hy/fpA8E alvWpzv56BfhSFneKTgIqhEnpeSJEZh9a5LyCADeAQDsnC/YktdC98vS58aWZA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=philipmcgrath.com header.s=google header.b=MFwR+Bll; 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: 2.88 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=philipmcgrath.com header.s=google header.b=MFwR+Bll; 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: A76282A03D X-Spam-Score: 2.88 X-Migadu-Scanner: scn0.migadu.com X-TUID: /unQvYphTbnL * gnu/packages/chez.scm (chez-machine->nonthreaded, chez-machine->threaded, chez-machine->nix-system, nix-system->chez-machine, chez-upstream-features-for-system): New 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-upstream-features-for-system'. (chez-scheme-for-racket-bootstrap-bootfiles)[supported-systems]: Compute based on 'nix-system->chez-machine'. --- gnu/packages/chez.scm | 127 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 124 insertions(+), 3 deletions(-) diff --git a/gnu/packages/chez.scm b/gnu/packages/chez.scm index 046bb3dcdc..603fc4201e 100644 --- a/gnu/packages/chez.scm +++ b/gnu/packages/chez.scm @@ -44,7 +44,119 @@ (define-module (gnu packages chez) #:use-module (gnu packages image) #:use-module (gnu packages xorg) #:use-module (ice-9 match) - #:use-module (srfi srfi-1)) + #:use-module (srfi srfi-1) + #:export (nix-system->chez-machine + chez-machine->nonthreaded + chez-machine->threaded)) + +(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. + +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* (nix-system->chez-machine #:optional + (system (or (%current-target-system) + (%current-system)))) + "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. + +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))) + (and chez-arch chez-os (string-append chez-arch chez-os)))) + +(define* (chez-upstream-features-for-system #:optional + (system + (or (%current-target-system) + (%current-system)))) + "Return a list of symbols naming features supported by upstream Chez Scheme +for the Nix system identifier SYSTEM, or @code{#f} if upstream Chez Scheme +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)))) + +;; +;; Chez Scheme: +;; (define nanopass (let ((version "1.9.2")) @@ -251,8 +363,11 @@ (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 chez-upstream-features-for-system + %supported-systems))) (home-page "https://cisco.github.io/ChezScheme/") (synopsis "R6RS Scheme compiler and run-time") (description @@ -300,6 +415,8 @@ (define-public chez-scheme-for-racket-bootstrap-bootfiles (invoke (search-input-file (or native-inputs inputs) "/opt/racket-vm/bin/racket") "rktboot/main.rkt"))))))) + (supported-systems (filter nix-system->chez-machine + %supported-systems)) (home-page "https://github.com/racket/ChezScheme") ;; ^ This is downstream of https://github.com/racket/racket, ;; but it's designed to be a friendly landing place for people @@ -322,6 +439,10 @@ (define-public chez-scheme-for-racket-bootstrap-bootfiles Chez Scheme.") (license (list asl2.0)))) +;; +;; Packages: +;; + (define-public chez-srfi (package (name "chez-srfi") -- 2.32.0