package js_of_ocaml-compiler
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
Compiler from OCaml bytecode to JavaScript
Install
dune-project
Dependency
Authors
Maintainers
Sources
js_of_ocaml-6.4.1.tbz
sha256=e59bbffcaefaba3191620556514b7f53bb3249e3f881a070d72724234dffd819
sha512=bb470f316f9c81a3b2b8dedd0b0f18f8e06beb48dd70df1d9f846de90ffab439cab5ef7a93a8166af0998068b06097e8319bc0d9f4f23a7159b0de8b3b515746
doc/src/js_of_ocaml-compiler/build_info.ml.html
Source file build_info.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 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(* Js_of_ocaml compiler * http://www.ocsigen.org/js_of_ocaml/ * Copyright (C) 2022 Hugo Heuzard * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, with linking exception; * either version 2.1 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) open! Stdlib type kind = [ `Runtime | `Exe | `Cmo | `Cma | `Unknown ] let all = [ `Runtime; `Exe; `Cmo; `Cma; `Unknown ] let string_of_kind = function | `Runtime -> "runtime" | `Exe -> "exe" | `Cmo -> "cmo" | `Cma -> "cma" | `Unknown -> "unknown" let string_of_effects_backend : Config.effects_backend -> string = function | `Disabled -> "disabled" | `Cps -> "cps" | `Double_translation -> "double-translation" | `Jspi -> "jspi" | `Native -> "native" let effects_backend_of_string_result = function | "disabled" -> Ok `Disabled | "cps" -> Ok `Cps | "double-translation" -> Ok `Double_translation | "jspi" -> Ok `Jspi | "native" -> Ok `Native | s -> Error (Printf.sprintf "unknown effects backend %s" s) let effects_backend_of_string s = match effects_backend_of_string_result s with | Ok b -> b | Error _ -> invalid_arg "effects_backend_of_string" let effects_backends_javascript = [ "cps", `Cps; "double-translation", `Double_translation; "disabled", `Disabled ] let effects_backends_wasm = [ "jspi", `Jspi; "cps", `Cps; "native", `Native; "disabled", `Disabled ] type config_key = | Bool_key of { name : string ; get : unit -> bool ; set : bool -> unit ; default : bool } | Enum_key of { name : string ; get : unit -> string ; set : string -> unit ; valid : string list } let config_key_name = function | Bool_key { name; _ } -> name | Enum_key { name; _ } -> name let config_keys target = let effects_valid = match target with | `JavaScript -> List.map ~f:fst effects_backends_javascript | `Wasm -> List.map ~f:fst effects_backends_wasm in let effects_get () = string_of_effects_backend (Config.effects ()) in [ Enum_key { name = "effects" ; get = effects_get ; set = (fun s -> Config.set_effects_backend (effects_backend_of_string s)) ; valid = effects_valid } ; Bool_key { name = "use-js-string" ; get = Config.Flag.use_js_string ; set = Config.Flag.set "use-js-string" ; default = true } ; Bool_key { name = "toplevel" ; get = Config.Flag.toplevel ; set = Config.Flag.set "toplevel" ; default = false } ] @ match target with | `Wasm -> [ Bool_key { name = "wasi" ; get = Config.Flag.wasi ; set = Config.Flag.set "wasi" ; default = false } ] | `JavaScript -> [] let config_key_values = function | Bool_key _ -> [ "true"; "false" ] | Enum_key { valid; _ } -> valid let get_values keys = List.map ~f:(fun key -> match key with | Bool_key { name; get; _ } -> name, string_of_bool (get ()) | Enum_key { name; get; _ } -> name, get ()) keys let set_values keys entries = (* Reject unknown keys before applying anything. *) List.iter entries ~f:(fun (k, _) -> if not (List.exists keys ~f:(fun key -> String.equal (config_key_name key) k)) then failwith (Printf.sprintf "unknown config key %S" k)); (* Iterate over [keys] (not [entries]) so that a key omitted from [entries] is reset to its default rather than silently keeping whatever value the caller left it at. *) List.iter keys ~f:(fun key -> let name = config_key_name key in let v = List.find_map entries ~f:(fun (k, v) -> if String.equal k name then Some v else None) in match key with | Bool_key { set; default; _ } -> ( match v with | None -> set default | Some "true" -> set true | Some "false" -> set false | Some v -> failwith (Printf.sprintf "key %S expects true or false, got %S" name v)) | Enum_key { set; valid; _ } -> ( match v with | None -> failwith (Printf.sprintf "missing required config key %S" name) | Some v -> if List.mem ~eq:String.equal v valid then set v else failwith (Printf.sprintf "key %S expects one of {%s}, got %S" name (String.concat ~sep:", " valid) v))) let parse_entries ~sep s = if String.is_empty s then [] else s |> String.split_on_char ~sep |> List.map ~f:String.trim |> List.map ~f:(fun s -> match String.lsplit2 ~on:'=' s with | None -> failwith (Printf.sprintf "invalid config entry %S: missing '='" s) | Some (k, v) -> k, v) let entries_to_string ~sep entries = let entries = List.sort ~cmp:(fun (k1, _) (k2, _) -> String.compare k1 k2) entries in String.concat ~sep (List.map ~f:(fun (k, v) -> Printf.sprintf "%s=%s" k v) entries) (* Like [get_values] but omits any bool key whose current value equals its default. Used to produce a compact [--build-config] output: [set_values] resets an omitted bool back to its default, so the omitted-at-default convention round-trips. Keeps the build-config directory name dune derives from this output short on Windows. *) let get_non_default_values keys = List.filter_map keys ~f:(fun key -> match key with | Bool_key { name; get; default; _ } -> let v = get () in if Bool.equal v default then None else Some (name, string_of_bool v) | Enum_key { name; get; _ } -> Some (name, get ())) let to_config_string entries = entries_to_string ~sep:"+" entries let parse_config_string s = parse_entries ~sep:'+' s let kind_of_string s = match List.find_opt all ~f:(fun k -> String.equal s (string_of_kind k)) with | None -> `Unknown | Some k -> k type t = string StringMap.t let kind t = match StringMap.find "kind" t with | exception Not_found -> `Unknown | s -> kind_of_string s let create kind = let version = match Compiler_version.git_version with | "" -> Compiler_version.s | v -> Printf.sprintf "%s+%s" Compiler_version.s v in get_values (config_keys (Config.target ())) @ [ "version", version; "kind", string_of_kind kind ] |> List.fold_left ~init:StringMap.empty ~f:(fun acc (k, v) -> StringMap.add k v acc) let with_kind t kind = StringMap.add "kind" (string_of_kind kind) t let prefix = "//# buildInfo:" let to_comment info = let str = entries_to_string ~sep:", " (StringMap.bindings info) in Printf.sprintf "%s%s\n" prefix str let parse_comment s = match String.drop_prefix ~prefix s with | None -> None | Some suffix -> let t = parse_entries ~sep:',' suffix |> List.fold_left ~init:StringMap.empty ~f:(fun acc (k, v) -> StringMap.add k v acc) in Some t let to_map : t -> string StringMap.t = Fun.id let of_map : string StringMap.t -> t = Fun.id exception Incompatible_build_info of { key : string ; first : (string * string option) ; second : (string * string option) } let merge target fname1 info1 fname2 info2 = if String.equal fname1 fname2 then StringMap.merge (fun k v1 v2 -> match v1, v2 with | Some v1, Some v2 when String.equal v1 v2 -> Some v1 | Some v1, Some v2 -> failwith (Printf.sprintf "%s: Duplicated build info with incompatible value. key=%s, v1=%s, v2=%s" fname1 k v1 v2) | Some x, None | None, Some x -> Some x | None, None -> assert false) info1 info2 else (* Also check that version match *) let matching_keys = "version" :: List.map ~f:config_key_name (config_keys target) in StringMap.merge (fun k v1 v2 -> match k, List.mem ~eq:String.equal k matching_keys, v1, v2 with | "kind", _, v1, v2 -> if Option.equal String.equal v1 v2 then v1 else Some (string_of_kind `Unknown) | _, true, Some v1, Some v2 when String.equal v1 v2 -> Some v1 | key, true, v1, v2 -> raise (Incompatible_build_info { key; first = fname1, v1; second = fname2, v2 }) | _, _, Some v1, Some v2 when String.equal v1 v2 -> Some v1 (* ignore info that are present on one side only or have a different value *) | _, false, Some _, Some _ -> None | _, false, None, Some _ | _, false, Some _, None -> None | _, false, None, None -> assert false) info1 info2 let configure t = let entries = StringMap.fold (fun k v acc -> match k with | "version" | "kind" -> acc | _ -> (k, v) :: acc) t [] in set_values (config_keys (Config.target ())) entries
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>