From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id qASsGmaadmIJVAEAbAwnHQ (envelope-from ) for ; Sat, 07 May 2022 18:12:22 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id wGWwGmaadmKxuAAA9RJhRA (envelope-from ) for ; Sat, 07 May 2022 18:12:22 +0200 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 0899F2AC49 for ; Sat, 7 May 2022 18:12:22 +0200 (CEST) Received: from localhost ([::1]:45702 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nnN2a-0006eh-V6 for larch@yhetil.org; Sat, 07 May 2022 12:12:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37672) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nnN2I-00067h-OD for guix-patches@gnu.org; Sat, 07 May 2022 12:12:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:58912) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nnN2I-00038S-Fu for guix-patches@gnu.org; Sat, 07 May 2022 12:12:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nnN2I-0006N8-BP for guix-patches@gnu.org; Sat, 07 May 2022 12:12:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#55220] [PATCH v2 2/6] platform: Add discovery support. Resent-From: Mathieu Othacehe Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 07 May 2022 16:12:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55220 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 55220@debbugs.gnu.org Cc: Mathieu Othacehe Received: via spool by 55220-submit@debbugs.gnu.org id=B55220.165193990724406 (code B ref 55220); Sat, 07 May 2022 16:12:02 +0000 Received: (at 55220) by debbugs.gnu.org; 7 May 2022 16:11:47 +0000 Received: from localhost ([127.0.0.1]:52795 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nnN22-0006LY-AR for submit@debbugs.gnu.org; Sat, 07 May 2022 12:11:46 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44334) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nnN20-0006Kn-H8 for 55220@debbugs.gnu.org; Sat, 07 May 2022 12:11:44 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:41092) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nnN1v-00032N-98 for 55220@debbugs.gnu.org; Sat, 07 May 2022 12:11:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=3V5APXjzhmLTWK9RABEXykFLvecakNsvos0LnxZYYJc=; b=GIj0bf2IrBQN4hvsi0Ir K8sAPVwgjhk8He2x/8+x2KtYwC0GGOxoAo6TZ+MA4aZVcGvmlgzheG72vg7j0Lkw1WETy/5SDZV1b LJlZJTP/YP6AmJY8H9lZXukRLN3Dh2gOMDOEldWl0o6lJ8JoW2eCHryaoxGWsrTtt/ocGwweEWe3k 6U08kFHBuTdz17KaBHhMfKsOgM4O4IJKY3ZVTvLCEE0bSehrkFRDCSI6hlzZgRmcJY0EtDLLKJFaB xZu8vlouNqwsJVaOJzsIe+hJlGNjLSlbbNXpkEuXHGwCQjHY7V5cwaFZGgSteHIKfB/Vwr5lQGJZN RawbwhkNhbMFqQ==; Received: from 71.125.192.77.rev.sfr.net ([77.192.125.71]:40324 helo=localhost.localdomain) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nnN1r-0004uM-3n; Sat, 07 May 2022 12:11:38 -0400 From: Mathieu Othacehe Date: Sat, 7 May 2022 18:11:22 +0200 Message-Id: <20220507161126.14553-3-othacehe@gnu.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220507161126.14553-1-othacehe@gnu.org> References: <20220507161126.14553-1-othacehe@gnu.org> 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-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1651939942; 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=QdniqrKeHesXiAIB1HK1S/TJWROSX3EzIDgxabrzcGY=; b=of+OsWWDeINqyf3eEj5j1Tmw5If8mX91GjUx/qUO6WkKp+Af2aNON4heI4PE7Z/VkSscqH oXIfcigMwTAM+nU2lt7A1W4aGnOeJ14qISoi5GCQAQRwsLOuZPGHRPmC1trSjN8eCnKT6k vV9bVptPVxqwQWrfv9TlAW8fXSH3KEodEjZUG3Rj1rc1gytxRbbm4vXgUBs0GXdxcIzjtr 34lENt7UcDK8NpTxOMEOJ84pKJvRdNROXDxgwdOLd4xiP+K/nHcZ3Yqf0unZbPMz4XBXmm yI+POsXOVhyR+8OUQ5bRXOg25UZhjiJ/ITGo735OIKhgLAMq7L3IdBVJpkf2WQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1651939942; a=rsa-sha256; cv=none; b=WqPmWWg74vvAdiJqhGvLh+lMvh33aOBsF7F/5zwM1uq9qv33Ev2gu2FjMDb6+xt/Ne0QBb DW/FEpku77vmof7spf1LB5nfr/ZW5+6qYU/V6HJ9by6RYjsbSerRWBYuZqFo8zTTj21ten 2TUOB3OWn5eqpez31S8uc7RUIsGxUTP3e1UH/tzFgPqOtNNnL/6ibG1KZAIV1RcE89al40 jRlcd+7REDypERYvGkJJFIKfqxcATNKtnwu2n0nPKlmSp+707x9x03+lyqnVbwQsFKGaeE qX73ObyCgh6J3/9ywNQWnSAJYRMj66LJqL/+xO/BZEPl5ktl+FGexKQGwq99aw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=GIj0bf2I; dmarc=pass (policy=none) header.from=gnu.org; 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.30 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=GIj0bf2I; dmarc=pass (policy=none) header.from=gnu.org; 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: 0899F2AC49 X-Spam-Score: -2.30 X-Migadu-Scanner: scn0.migadu.com X-TUID: 9Yj2i6yAq2sN * gnu/platform.scm (platform-modules, systems, targets, lookup-platform-by-system, lookup-platform-by-target, lookup-platform-by-target-or-system platform-system->target, platform-target->system): New procedures. (%platforms): New variable. Signed-off-by: Mathieu Othacehe --- gnu/platform.scm | 101 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 98 insertions(+), 3 deletions(-) diff --git a/gnu/platform.scm b/gnu/platform.scm index bb6519c71a..4c5211e107 100644 --- a/gnu/platform.scm +++ b/gnu/platform.scm @@ -17,22 +17,117 @@ ;;; along with GNU Guix. If not, see . (define-module (gnu platform) + #:use-module (guix discovery) + #:use-module (guix memoization) #:use-module (guix records) + #:use-module (guix ui) + #:use-module (srfi srfi-1) #:export (platform platform? platform-target platform-system - platform-linux-architecture)) + platform-linux-architecture + + platform-modules + platforms + lookup-platform-by-system + lookup-platform-by-target + lookup-platform-by-target-or-system + platform-system->target + platform-target->system + + systems + targets)) ;;; ;;; Platform record. ;;; -;; Description of a platform supported by the GNU system. +;; Description of a platform supported by GNU Guix. +;; +;; The 'target' field must be a valid GNU triplet as defined here: +;; https://www.gnu.org/software/autoconf/manual/autoconf-2.68/html_node/Specifying-Target-Triplets.html. +;; It is used for cross-compilation purposes. +;; +;; The 'system' field is the name of the corresponding system as defined in +;; the (gnu packages bootstrap) module. It can be for instance +;; "aarch64-linux" or "armhf-linux". It is used to emulate a different host +;; architecture, for instance i686-linux on x86_64-linux-gnu, or armhf-linux +;; on x86_64-linux, using the QEMU binfmt transparent emulation mechanism. +;; +;; The 'linux-architecture' is only relevant if the kernel is Linux. In that +;; case, it corresponds to the ARCH variable used when building Linux. (define-record-type* platform make-platform platform? (target platform-target) ;"x86_64-linux-gnu" (system platform-system) ;"x86_64-linux" - (linux-architecture platform-linux-architecture ;"amd64" + (linux-architecture platform-linux-architecture ;"x86" (default #f))) + +;;; +;;; Platforms. +;;; + +(define (platform-modules) + "Return the list of platform modules." + (all-modules (map (lambda (entry) + `(,entry . "gnu/platforms")) + %load-path) + #:warn warn-about-load-error)) + +(define platforms + ;; The list of publically-known platforms. + (memoize + (lambda () + (fold-module-public-variables (lambda (obj result) + (if (platform? obj) + (cons obj result) + result)) + '() + (platform-modules))))) + +(define (lookup-platform-by-system system) + "Return the platform corresponding to the given SYSTEM." + (find (lambda (platform) + (let ((s (platform-system platform))) + (and (string? s) (string=? s system)))) + (platforms))) + +(define (lookup-platform-by-target target) + "Return the platform corresponding to the given TARGET." + (find (lambda (platform) + (let ((t (platform-target platform))) + (and (string? t) (string=? t target)))) + (platforms))) + +(define (lookup-platform-by-target-or-system target-or-system) + "Return the platform corresponding to the given TARGET or SYSTEM." + (or (lookup-platform-by-target target-or-system) + (lookup-platform-by-system target-or-system))) + +(define (platform-system->target system) + "Return the target matching the given SYSTEM if it exists or false +otherwise." + (let ((platform (lookup-platform-by-system system))) + (and=> platform platform-target))) + +(define (platform-target->system target) + "Return the system matching the given TARGET if it exists or false +otherwise." + (let ((platform (lookup-platform-by-target system))) + (and=> platform platform-system))) + + +;;; +;;; Systems & Targets. +;;; + +(define (systems) + "Return the list of supported systems." + (delete-duplicates + (filter-map platform-system (platforms)))) + +(define (targets) + "Return the list of supported targets." + (map platform-target (platforms))) -- 2.36.0