package dkml-install

  1. Overview
  2. Docs

Source file types.ml

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
module Context = struct
  (** ABI V2 is the version 2 of the supported list of ABIs *)
  module Abi_v2 = struct
    type t =
      | Android_arm64v8a
      | Android_arm32v7a
      | Android_x86
      | Android_x86_64
      | Darwin_arm64
      | Darwin_x86_64
      | Linux_arm64
      | Linux_arm32v6
      | Linux_arm32v7
      | Linux_x86_64
      | Linux_x86
      | Windows_x86_64
      | Windows_x86
      | Windows_arm64
      | Windows_arm32
    [@@deriving eq, ord, enum]

    let of_string = function
      | "Android_arm64v8a" -> Ok Android_arm64v8a
      | "Android_arm32v7a" -> Ok Android_arm32v7a
      | "Android_x86" -> Ok Android_x86
      | "Android_x86_64" -> Ok Android_x86_64
      | "Darwin_arm64" -> Ok Darwin_arm64
      | "Darwin_x86_64" -> Ok Darwin_x86_64
      | "Linux_arm64" -> Ok Linux_arm64
      | "Linux_arm32v6" -> Ok Linux_arm32v6
      | "Linux_arm32v7" -> Ok Linux_arm32v7
      | "Linux_x86_64" -> Ok Linux_x86_64
      | "Linux_x86" -> Ok Linux_x86
      | "Windows_x86_64" -> Ok Windows_x86_64
      | "Windows_x86" -> Ok Windows_x86
      | "Windows_arm64" -> Ok Windows_arm64
      | "Windows_arm32" -> Ok Windows_arm32
      | s -> Error ("Unknown v2 ABI: " ^ s)

    (** [to_string abi] is the enumeration value of
        [abi]; for example ["Linux_x86"]. *)
    let to_string = function
      | Android_arm64v8a -> "Android_arm64v8a"
      | Android_arm32v7a -> "Android_arm32v7a"
      | Android_x86 -> "Android_x86"
      | Android_x86_64 -> "Android_x86_64"
      | Darwin_arm64 -> "Darwin_arm64"
      | Darwin_x86_64 -> "Darwin_x86_64"
      | Linux_arm64 -> "Linux_arm64"
      | Linux_arm32v6 -> "Linux_arm32v6"
      | Linux_arm32v7 -> "Linux_arm32v7"
      | Linux_x86_64 -> "Linux_x86_64"
      | Linux_x86 -> "Linux_x86"
      | Windows_x86_64 -> "Windows_x86_64"
      | Windows_x86 -> "Windows_x86"
      | Windows_arm64 -> "Windows_arm64"
      | Windows_arm32 -> "Windows_arm32"

    (** [to_canonical_string abi] will give the canonical representation of
        the ABI to DkML tools and APIs. *)
    let to_canonical_string = function
      | Android_arm64v8a -> "android_arm64v8a"
      | Android_arm32v7a -> "android_arm32v7a"
      | Android_x86 -> "android_x86"
      | Android_x86_64 -> "android_x86_64"
      | Darwin_arm64 -> "darwin_arm64"
      | Darwin_x86_64 -> "darwin_x86_64"
      | Linux_arm64 -> "linux_arm64"
      | Linux_arm32v6 -> "linux_arm32v6"
      | Linux_arm32v7 -> "linux_arm32v7"
      | Linux_x86_64 -> "linux_x86_64"
      | Linux_x86 -> "linux_x86"
      | Windows_x86_64 -> "windows_x86_64"
      | Windows_x86 -> "windows_x86"
      | Windows_arm64 -> "windows_arm64"
      | Windows_arm32 -> "windows_arm32"

    let show = to_string
    let pp fmt abi = Format.pp_print_string fmt (show abi)

    let is_windows = function
      | Windows_x86_64 | Windows_x86 | Windows_arm64 | Windows_arm32 -> true
      | _ -> false

    let is_linux = function
      | Linux_arm64 | Linux_arm32v6 | Linux_arm32v7 | Linux_x86_64 | Linux_x86
        ->
          true
      | _ -> false

    let is_darwin = function Darwin_arm64 | Darwin_x86_64 -> true | _ -> false

    let is_android = function
      | Android_arm64v8a | Android_arm32v7a | Android_x86 | Android_x86_64 ->
          true
      | _ -> false

    (** [word_size] is the number of bits in a word for the machine's CPU architecture.
        The number of bits will be [32] or [64], but may be something else for
        more exotic future architectures. *)
    let word_size = function
      | Android_arm64v8a -> 64
      | Android_arm32v7a -> 32
      | Android_x86 -> 32
      | Android_x86_64 -> 64
      | Darwin_arm64 -> 64
      | Darwin_x86_64 -> 64
      | Linux_arm64 -> 64
      | Linux_arm32v6 -> 32
      | Linux_arm32v7 -> 32
      | Linux_x86_64 -> 64
      | Linux_x86 -> 32
      | Windows_x86_64 -> 64
      | Windows_x86 -> 32
      | Windows_arm64 -> 64
      | Windows_arm32 -> 32

    let values =
      List.init
        (max - min + 1)
        (fun i ->
          match of_enum (min + i) with Some v -> Some v | None -> None)
      |> List.filter_map Fun.id
  end

  type t = {
    path_eval : string -> Fpath.t;
    eval : string -> string;
    target_abi_v2 : Abi_v2.t;
    log_config : Log_config.t;
  }
  (** [t] is the record type for the context.

{1 Context Fields}

The following fields are available from the context:

{ul
  {- [ctx.path_eval "/some/path/expression"]

  Evaluates the given path expression, resolving any templates embedded in the
  expression. You may use slashes ("/") even on Windows; the evaluation of the
  expression will convert the path into native Windows (ex. C:\Program Files)
  or Unix format (ex. /usr/local/share).

  An example expression is ["%{ocamlrun:share}%/generic/bin/ocamlrun"]
  which would be the location of ocamlrun.exe within the staging files directory.

  Templates:

  - ["%{prefix}%"] is the absolute path of the final installation directory. If you
    are following {{:https://www.gnu.org/prep/standards/html_node/Directory-Variables.html} GNU directory standards},
    you should populate ["%{prefix}%"] with subdirectories "bin/", "share/", etc.
  - ["%{archive}%"] is the absolute path of the staging files directory.
  - ["%{tmp}%"] is the absolute path to a temporary directory unique to the
    component that is currently being installed. No other component will use the
    same temporary directory.
  - ["%{_:share-generic}%"] is the absolute path to the ``generic`` Staging Files
    directory of the component currently being installed.
  - ["%{_:share-abi}%"] is the absolute path to the ``<abi>`` Staging Files
    of the component currently being installed, where ``<abi>`` is the
    ABI currently being installed

  More templates available to all [ctx] except [needs_admin ctx]:

  - ["%{COMPONENT_NAME:share-generic}%"] is the absolute path to
    the ``generic`` Staging Files of the named component.
    {e {b Only COMPONENT_NAMEs that are transitive dependencies
    of the currently-being-installed component will be resolved.}}
  - ["%{COMPONENT_NAME:share-abi}%"] is the absolute path to
    the ``<abi>`` Staging Files of the named component, where
    ``<abi>`` is the ABI currently being installed

  {e {b Only COMPONENT_NAMEs that are transitive dependencies
  of the currently-being-installed component will be resolved.}}

  Usually the staging files include a bytecode executable to run a component's
  installation logic.

  Variations:

  - {b Staging Files}:
    When dkml-install-runner.exe is run with the ["--staging-files DIR"] option
    then the staging directory is simply ["<DIR>/<COMPONENT_NAME>"]. During an
    end-user installation the ["--staging-files DIR"] option is automatically
    used.
    When dkml-install-runner.exe is run with the ["--opam-context"] option then
    the staging directory is
    ["$OPAM_SWITCH_PREFIX/share/dkml-component-<COMPONENT_NAME>/staging-files"]. You can use
    the ["--opam-context"] option to test your components in an Opam environment.
  }

  {- [ctx.eval "/some/expression"]

  Evaluates the given expression, resolving any templates embedded in the
  expression.

  An example expression is ["%{components:all}%"].

  All templates that are available with [path_eval] are available with [eval].
  However unlike [path_eval] the [eval] function will do no path conversions on
  Windows. In addition [eval] has templates that are not available in
  [path_eval].

  Templates available to [eval] but not in [path_eval]:

  - ["%{name}%"] is the name of the component currently being installed
  - ["%{components:all}%"] is the space separated names of the components that are
  or will be installed
  }

  {- [ctx.target_abi_v2]

  The ABI for the end-user's machine from the list of V2 ABIs. You cannot rely on
  inspecting the OCaml bytecode interpreter since the interpreter is often
  compiled to 32-bit for maximum portability. When more ABIs are
  supported they will go into a future [ctx.host_abi_v3] or later;
  for type-safety [ctx.target_abi_v2] will give a [Result.Error] for those
  new ABIs.

  Values for the V2 ABI include:

  * Android_arm64v8a
  * Android_arm32v7a
  * Android_x86
  * Android_x86_64
  * Darwin_arm64
  * Darwin_x86_64
  * Linux_arm64
  * Linux_arm32v6
  * Linux_arm32v7
  * Linux_x86_64
  * Linux_x86
  * Windows_x86_64
  * Windows_x86
  }

  {- [ctx.log_config]

  The logging configuration. See the Logging section of {!Dkml_install_api}
  for how to use it.
  }
}
*)
end
OCaml

Innovation. Community. Security.