-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathocaml_version.mli
352 lines (265 loc) · 11.4 KB
/
ocaml_version.mli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
(* Copyright (c) 2017-2018 Anil Madhavapeddy <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*)
(** Manipulate, parse and generate OCaml version strings.
These are of the form [major.minor.patch+extra], where the
[patch] and [extra] fields are optional. *)
type t
(** Type of an OCaml version string *)
val v : ?patch:int -> ?extra:string -> int -> int -> t
(** [v ?patch ?extra major minor] will construct an OCaml
version string with the appropriate parameters. The
[patch] and [extra] indicators are optional, but it is
conventional to include a [patch] value of 0 for most
recent OCaml releases. *)
(** {2 Parsers and serializers} *)
val to_string : ?sep:char -> t -> string
(** [to_string ?sep t] will convert the version [t] into
a human-readable representation. The [sep] will default
to [+] which is the normal representation of extra
version strings, but can be changed to another character
by supplying [sep]. One such usecase is to generate
Docker container tags from OCaml version strings, where
only dashes and alphanumeric characters are allowed. *)
val of_string : string -> (t, [> `Msg of string ]) result
(** [of_string t] will parse the version string in [t].
The return value is compatible with the {!Result}
combinators defined in the [rresult] library. *)
val of_string_exn : string -> t
(** [of_string_exn t] behaves as {!of_string} but raises
[Invalid_argument] if the string cannot be parsed. *)
val compare : t -> t -> int
(** [compare a b] is the comparison function for two OCaml
version strings. Returns [-1] if [a<b], [0] if they are
equal and [1] if [a>b]. Comparison is done using integer
comparison for the major, minor and patch versions, and
lexical comparison for any extra version strings present. *)
val pp : Format.formatter -> t -> unit
(** [pp fmt t] will output a human-readable version string of
[t] to the [fmt] formatter. *)
(** {2 Architecture Support }
These definitions cover the CPU architectures that OCaml
runs and is supported on. *)
type arch = [ `X86_64 | `Aarch64 | `Aarch32 | `Ppc64le ]
(** Type of CPU architectures.
TODO: This is currently an incomplete list, and lists just
those used by the opam test systems. Contributions welcome
to complete it. *)
val arches : arch list
(** [arches] is an enumeration of all of the possible {!arch} values. *)
val string_of_arch : arch -> string
(** [string_of_arch arch] will convert [arch] into a human-readable
CPU architecture string. The result will follow the
{{:https://golang.org/doc/install/source#environment}GOARCH}
convention used by Golang. *)
val arch_of_string : string -> (arch, [> `Msg of string ]) result
(** [arch_of_string t] will parse the architecture string in [t].
The return value is compatible with the {!Result}
combinators defined in the [rresult] library. This function
is liberal and will attempt to understand variants of the
same architecture. For example, both [aarch64] and [arm64]
are parsed into {!`Aarch64}. *)
val arch_of_string_exn: string -> arch
(** [arch_of_string_exn t] is the same as {!arch_of_string},
except that it raises [Invalid_argument] in case of error. *)
(** {2 Accessors} *)
val major : t -> int
(** [major t] will return the major version number of an OCaml
release. For example, [of_string "4.03.0" |> major] will
return [4]. *)
val minor : t -> int
(** [minor t] will return the minor version number of an OCaml
release. For example, [of_string "4.03.0" |> minor] will
return [3]. *)
val patch : t -> int option
(** [patch t] will return the patch version number of an OCaml
release. For example, [of_string "4.03.0" |> minor] will
return [Some 0]. *)
val extra : t -> string option
(** [extra t] will return the additional information string of
an OCaml release.
For example, [of_string "4.03.0+flambda" |> extra] will
return [Some "flambda"]. *)
val with_variant : t -> string option -> t
(** [with_variant t extra] will return a fresh value with
the extra version information in [t] to
[extra], and remove it if [None] is supplied. *)
val without_variant : t -> t
(** [without_variant t] is {!with_variant} [t None]. It removes
any extra version information from the version string [t]. *)
val with_patch : t -> int option -> t
(** [with_patch t patch] will return a fresh value with
the patch number in [t] to [patch], and remove it if [None]
is supplied. *)
val without_patch : t -> t
(** [without_patch t] is as {!with_patch} [t None]. It removes
the least significant number from the version string.
This is useful for the Docker OCaml containers, which are
all named without a patch number and compiled using the
latest patch release (e.g. [4.06] instead of [4.06.1]). *)
val with_just_major_and_minor : t -> t
(** [with_just_major_and_minor t] strips out any patch and
extra version information to return the X.Y form of the
OCaml release. For example, [4.08.0+trunk+flambda] will
return the version representing [4.08]. *)
(** {2 Constants } *)
val sys_version : t
(** [sys_version] is the version of OCaml that this library is
currently compiled with, which will be the same as
{!Sys.ocaml_version}. *)
(** Values representing official releases of OCaml. *)
module Releases : sig
val v4_00_1 : t
(** Version 4.00.1 *)
val v4_00 : t
(** Latest release in the 4.00.x series *)
val v4_01_0 : t
(** Version 4.01.0 *)
val v4_01 : t
(** Latest release in the 4.01.x series *)
val v4_02_0 : t
(** Version 4.02.0 *)
val v4_02_1 : t
(** Version 4.02.1 *)
val v4_02_2 : t
(** Version 4.02.2 *)
val v4_02_3 : t
(** Version 4.02.3 *)
val v4_02 : t
(** Latest release in the 4.02.x series *)
val v4_03_0 : t
(** Version 4.03.0 *)
val v4_03 : t
(** Latest release in the 4.03.x series *)
val v4_04_0 : t
(** Version 4.04.0 *)
val v4_04_1 : t
(** Version 4.04.1 *)
val v4_04_2 : t
(** Version 4.04.2 *)
val v4_04 : t
(** Latest release in the 4.04.x series *)
val v4_05_0 : t
(** Version 4.05.0 *)
val v4_05 : t
(** Latest release in the 4.05.x series *)
val v4_06_0 : t
(** Version 4.06.0 *)
val v4_06_1 : t
(** Version 4.06.1 *)
val v4_06 : t
(** Latest release in the 4.06.x series *)
val v4_07_0 : t
(** Version 4.07.0 *)
val v4_07_1 : t
(** Version 4.07.1 *)
val v4_07 : t
(** Latest release in the 4.07.x series *)
val v4_08_0 : t
(** Versior 4.08.0 *)
val v4_08 : t
(** Latest release in the 4.08.x series *)
val v4_09_0 : t
(** Version 4.09.0 *)
val v4_09 : t
(** Latest release in the 4.09.x series *)
val v4_10_0 : t
(** Version 4.10.0 *)
val v4_10 : t
(** Latest release in the 4.10.x series *)
val all_patches : t list
(** [all_patches] is an enumeration of all OCaml releases, including every patch release.
To get the major and minor releases with the latest patch version, use {!all} instead. *)
val all : t list
(** [all] is an enumeration of all the OCaml releases, with the latest patch versions in
each major and minor release. *)
val dev : t list
(** Enumeration of the latest development OCaml releases.
This is usually just one, but may include two active dev
versions if a release branch has just been cut. *)
val latest: t
(** [latest] is the most recent stable release of OCaml. *)
val recent : t list
(** [recent] is the last five releases of OCaml, with each at the latest patch level.
This is the set that is most reliably tested in the opam package repository. *)
val recent_with_dev : t list
(** [recent_with_dev] are the last four stable releases of OCaml and the latest
development branches. *)
val is_dev : t -> bool
(** [is_dev t] will return true if the release [t] represents a development
release instead of a stable archive. *)
end
(** Values relating to the source code and version control of OCaml *)
module Sources : sig
val trunk : t
(** [trunk] is the version of the development head of the OCaml git repository. *)
val git_tag : t -> string
(* [git_tag v] returns the Git tag or branch that corresponds to the release
[v] of OCaml. If [v] does not have a patch releases, then it will be a branch
that points to the relevant release branch. *)
end
(** {2 Feature Selection} *)
(** Determine which release a feature or architecture first appeared in. *)
module Since : sig
val bytes: t
(** [bytes] is the release that the {!Bytes} module first appeared in. *)
val arch : arch -> t
(** [arch a] will return the first release of OCaml that the architecture
was reasonably stably supported on. *)
end
(** Test whether a release has a given feature. *)
module Has : sig
val bytes : t -> bool
(** [bytes t] will return {!true} if that release has a {!bytes} type.
Note that opam provides a [bytes] compatibility package for older releases. *)
val arch : arch -> t -> bool
(** [arch a t] will return {!true} if architecture [a] is supported on release [t]. *)
end
(** Configuration parameters that affect the behaviour of OCaml at compiler-build-time. *)
module Configure_options : sig
type o =
[ `Afl
| `Default_unsafe_string
| `Flambda
| `Force_safe_string
| `Frame_pointer ]
(** Configuration options available at compiler build time. *)
val to_string : o -> string
(** [to_string o] returns a compact representation of {!o} suitable for use in opam version strings. *)
val to_description : o -> string
(** [to_description o] returns a human-readable representation of {!o}. *)
val to_configure_flag : o -> string
(** [to_configure_flag o] returns a string that can be passed to OCaml's [configure] script to activate that feature. *)
end
val compiler_variants : arch -> t -> Configure_options.o list list
(** [compiler_variants v] returns a list of configuration options that are available and useful
for version [v] of the compiler. *)
(** Opam compiler switches.
These are available from the public {{:https://github.com/ocaml/opam-repository}opam-repository}. *)
module Opam : sig
(** Opam 2.0 functions *)
module V2 : sig
val name : t -> string
(** [package t] returns the opam2 package for that compiler version. *)
val variant_switch : t -> Configure_options.o list -> t
(** [variant_switch t cs] returns an OCaml version [t] whose
variant version field reflects the configuration options in [cs] *)
val switches : arch -> t -> t list
(** [switches arch t] returns the list of opam switches that
are available for that compiler and architecture combination.
For example, an x86_64 one would yield a list that includes
flambda and the flambda-with-frame-pointer combinations. *)
end
end