diff options
author | Mathieu Othacehe <othacehe@gnu.org> | 2022-05-02 12:56:16 +0200 |
---|---|---|
committer | Mathieu Othacehe <othacehe@gnu.org> | 2022-05-22 15:15:33 +0200 |
commit | 4f2320f79d97410ed6568c0c65054b71a1ca59c2 (patch) | |
tree | f2c8279c5fac1414af2301fb262d6378aca6e5ea | |
parent | platform: Introduce new platforms. (diff) | |
download | guix-4f2320f79d97410ed6568c0c65054b71a1ca59c2.tar.gz guix-4f2320f79d97410ed6568c0c65054b71a1ca59c2.tar.bz2 guix-4f2320f79d97410ed6568c0c65054b71a1ca59c2.tar.xz |
platform: Add discovery support.
* 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 <othacehe@gnu.org>
-rw-r--r-- | gnu/platform.scm | 101 |
1 files 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 @@ | |||
17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | 17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. |
18 | 18 | ||
19 | (define-module (gnu platform) | 19 | (define-module (gnu platform) |
20 | #:use-module (guix discovery) | ||
21 | #:use-module (guix memoization) | ||
20 | #:use-module (guix records) | 22 | #:use-module (guix records) |
23 | #:use-module (guix ui) | ||
24 | #:use-module (srfi srfi-1) | ||
21 | #:export (platform | 25 | #:export (platform |
22 | platform? | 26 | platform? |
23 | platform-target | 27 | platform-target |
24 | platform-system | 28 | platform-system |
25 | platform-linux-architecture)) | 29 | platform-linux-architecture |
30 | |||
31 | platform-modules | ||
32 | platforms | ||
33 | lookup-platform-by-system | ||
34 | lookup-platform-by-target | ||
35 | lookup-platform-by-target-or-system | ||
36 | platform-system->target | ||
37 | platform-target->system | ||
38 | |||
39 | systems | ||
40 | targets)) | ||
26 | 41 | ||
27 | 42 | ||
28 | ;;; | 43 | ;;; |
29 | ;;; Platform record. | 44 | ;;; Platform record. |
30 | ;;; | 45 | ;;; |
31 | 46 | ||
32 | ;; Description of a platform supported by the GNU system. | 47 | ;; Description of a platform supported by GNU Guix. |
48 | ;; | ||
49 | ;; The 'target' field must be a valid GNU triplet as defined here: | ||
50 | ;; https://www.gnu.org/software/autoconf/manual/autoconf-2.68/html_node/Specifying-Target-Triplets.html. | ||
51 | ;; It is used for cross-compilation purposes. | ||
52 | ;; | ||
53 | ;; The 'system' field is the name of the corresponding system as defined in | ||
54 | ;; the (gnu packages bootstrap) module. It can be for instance | ||
55 | ;; "aarch64-linux" or "armhf-linux". It is used to emulate a different host | ||
56 | ;; architecture, for instance i686-linux on x86_64-linux-gnu, or armhf-linux | ||
57 | ;; on x86_64-linux, using the QEMU binfmt transparent emulation mechanism. | ||
58 | ;; | ||
59 | ;; The 'linux-architecture' is only relevant if the kernel is Linux. In that | ||
60 | ;; case, it corresponds to the ARCH variable used when building Linux. | ||
33 | (define-record-type* <platform> platform make-platform | 61 | (define-record-type* <platform> platform make-platform |
34 | platform? | 62 | platform? |
35 | (target platform-target) ;"x86_64-linux-gnu" | 63 | (target platform-target) ;"x86_64-linux-gnu" |
36 | (system platform-system) ;"x86_64-linux" | 64 | (system platform-system) ;"x86_64-linux" |
37 | (linux-architecture platform-linux-architecture ;"amd64" | 65 | (linux-architecture platform-linux-architecture ;"x86" |
38 | (default #f))) | 66 | (default #f))) |
67 | |||
68 | ;;; | ||
69 | ;;; Platforms. | ||
70 | ;;; | ||
71 | |||
72 | (define (platform-modules) | ||
73 | "Return the list of platform modules." | ||
74 | (all-modules (map (lambda (entry) | ||
75 | `(,entry . "gnu/platforms")) | ||
76 | %load-path) | ||
77 | #:warn warn-about-load-error)) | ||
78 | |||
79 | (define platforms | ||
80 | ;; The list of publically-known platforms. | ||
81 | (memoize | ||
82 | (lambda () | ||
83 | (fold-module-public-variables (lambda (obj result) | ||
84 | (if (platform? obj) | ||
85 | (cons obj result) | ||
86 | result)) | ||
87 | '() | ||
88 | (platform-modules))))) | ||
89 | |||
90 | (define (lookup-platform-by-system system) | ||
91 | "Return the platform corresponding to the given SYSTEM." | ||
92 | (find (lambda (platform) | ||
93 | (let ((s (platform-system platform))) | ||
94 | (and (string? s) (string=? s system)))) | ||
95 | (platforms))) | ||
96 | |||
97 | (define (lookup-platform-by-target target) | ||
98 | "Return the platform corresponding to the given TARGET." | ||
99 | (find (lambda (platform) | ||
100 | (let ((t (platform-target platform))) | ||
101 | (and (string? t) (string=? t target)))) | ||
102 | (platforms))) | ||
103 | |||
104 | (define (lookup-platform-by-target-or-system target-or-system) | ||
105 | "Return the platform corresponding to the given TARGET or SYSTEM." | ||
106 | (or (lookup-platform-by-target target-or-system) | ||
107 | (lookup-platform-by-system target-or-system))) | ||
108 | |||
109 | (define (platform-system->target system) | ||
110 | "Return the target matching the given SYSTEM if it exists or false | ||
111 | otherwise." | ||
112 | (let ((platform (lookup-platform-by-system system))) | ||
113 | (and=> platform platform-target))) | ||
114 | |||
115 | (define (platform-target->system target) | ||
116 | "Return the system matching the given TARGET if it exists or false | ||
117 | otherwise." | ||
118 | (let ((platform (lookup-platform-by-target system))) | ||
119 | (and=> platform platform-system))) | ||
120 | |||
121 | |||
122 | ;;; | ||
123 | ;;; Systems & Targets. | ||
124 | ;;; | ||
125 | |||
126 | (define (systems) | ||
127 | "Return the list of supported systems." | ||
128 | (delete-duplicates | ||
129 | (filter-map platform-system (platforms)))) | ||
130 | |||
131 | (define (targets) | ||
132 | "Return the list of supported targets." | ||
133 | (map platform-target (platforms))) | ||