From patchwork Thu Feb 17 20:50:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip McGrath X-Patchwork-Id: 37293 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 0CB8127BBEA; Thu, 17 Feb 2022 20:53:10 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED 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 2F61827BBEB for ; Thu, 17 Feb 2022 20:53:05 +0000 (GMT) Received: from localhost ([::1]:35568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKnlw-0006Xw-A4 for patchwork@mira.cbaines.net; Thu, 17 Feb 2022 15:53:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43486) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKnky-000613-Dq for guix-patches@gnu.org; Thu, 17 Feb 2022 15:52:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:58875) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nKnky-0001UE-4E for guix-patches@gnu.org; Thu, 17 Feb 2022 15:52:04 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nKnky-0003W5-3u for guix-patches@gnu.org; Thu, 17 Feb 2022 15:52:04 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#53878] [PATCH v2 04/15] 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: Thu, 17 Feb 2022 20:52:04 +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 , zimoun , Ludovic =?utf-8?q?Court=C3=A8s?= , Liliana Marie Prikler , Attila Lendvai , Malte Gerdes Received: via spool by 53878-submit@debbugs.gnu.org id=B53878.164513111613458 (code B ref 53878); Thu, 17 Feb 2022 20:52:04 +0000 Received: (at 53878) by debbugs.gnu.org; 17 Feb 2022 20:51:56 +0000 Received: from localhost ([127.0.0.1]:52764 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nKnkp-0003Uy-RF for submit@debbugs.gnu.org; Thu, 17 Feb 2022 15:51:56 -0500 Received: from mail-qk1-f172.google.com ([209.85.222.172]:45905) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nKnki-0003U8-EM for 53878@debbugs.gnu.org; Thu, 17 Feb 2022 15:51:52 -0500 Received: by mail-qk1-f172.google.com with SMTP id b22so5934562qkk.12 for <53878@debbugs.gnu.org>; Thu, 17 Feb 2022 12:51:48 -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=voen33luSuZnifO97fQiqSCtXHVzAz6OmjDwr/H6AjE=; b=UPg7jnkZ61Qd23NYkZskT0KiELRSi4xkunI1jhgFGIa5M3CZnujB7NDxzRtA8o0MVm fHd51aiFjEY5AZ1C+M4vzqzkXSG4C8k5cIDSGp9aEhlLJ6/uq4xU3BbMea/PRB495Zxx XrjstVvFD8XgsGZ7lqxOV4iCmQgVvctQvOaNWynn8bTZiMrAHR2TnOfeY2IBezGfqFBb XxzqcTaDDsYFChGRKZPdrTLGSUuhXqADqeAkijgA00U0Oz6A4cAjtRVmIjH2QQGDFXVZ IFS7DaMUix2y/eoEkDwrkKMorxKTNB8nOEBJ7UBWwdSNprZZ0BPRZJiIttc18GLLLjAi RHWA== 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=voen33luSuZnifO97fQiqSCtXHVzAz6OmjDwr/H6AjE=; b=G/ORYXXgAA5gaYJ/qHGlwXiq81oMn9KZeQ581ZmNgCmg72XnBkPO9NYyAu89aN4oLf 5htXru8HWbuIN2antulUZyKa8Z7mz5YbdVtWMfVWebfhXH/0dvghwtX32uDpOF3dNWvg 6/ZUZy/R636Gtxj7Gx9LSFHWjwxrwhz85vWv4eQ0ZxAMnbSCH3BDB0rPEMndqM6NQwg9 DvePru/fRS1yhClQLvZRpShN06Bx0H7wg6tDcUWvsHe/O9Sc9oq3vjw36XKndrh8s1du UTPtZ0HcK1Bd3oMnakVNnwHlckvx4LmyPGPhutzvo3pW29P5sm3srqtR2fKjOt7NlF1q Ujsg== X-Gm-Message-State: AOAM5305oGrfKviGnduKCaR2isFy9/UQLrS4ZsLotMpROn5mJbNagGf7 kI2ohxaPiBDKg1ic1ReMCGwsvE7ruQ17LYlEYzY= X-Google-Smtp-Source: ABdhPJzsPFOW9qkgVW3HtwyfwUEG5qLJr+FLzx//ZCNFRtf1ZAo8iu1dYQOfDtv937xB/NMOVSsEHA== X-Received: by 2002:a37:a38b:0:b0:47d:bcad:2f49 with SMTP id m133-20020a37a38b000000b0047dbcad2f49mr2848223qke.504.1645131102725; Thu, 17 Feb 2022 12:51:42 -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 w10sm25355944qtj.73.2022.02.17.12.51.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Feb 2022 12:51:42 -0800 (PST) From: Philip McGrath Date: Thu, 17 Feb 2022 15:50:37 -0500 Message-Id: <20220217205048.967383-5-philip@philipmcgrath.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220217205048.967383-1-philip@philipmcgrath.com> References: <97f8916ae5bd8d8459bdfd507864f2f55cc217a1.camel@ist.tugraz.at> <20220217205048.967383-1-philip@philipmcgrath.com> 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 * gnu/packages/chez-and-racket-bootstrap.scm (chez-machine->nonthreaded, chez-machine->threaded, chez-machine->nix-system, nix-system->chez-machine, chez-upstream-features-for-system): 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-upstream-features-for-system'. --- gnu/packages/chez-and-racket-bootstrap.scm | 118 ++++++++++++++++++++- 1 file changed, 116 insertions(+), 2 deletions(-) diff --git a/gnu/packages/chez-and-racket-bootstrap.scm b/gnu/packages/chez-and-racket-bootstrap.scm index 11d570059b..1a923fe62d 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,115 @@ (define-module (gnu packages chez-and-racket-bootstrap) ;; ;; Code: +(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")) (origin @@ -264,8 +375,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