this repo has no description

fix: add missing jsoo_runtime js

ArthurW 09ae6b5a d5eef5d3

+40 -4
+40 -4
bin/x_ocaml.ml
··· 29 } 30 (globalThis));|} 31 32 - type t = { name : string; incl : Cmd.t; cma : string; ppx : bool } 33 34 let jsoo_compile ~effects t temp_file = 35 let toplevel = if t.ppx then Cmd.empty else Cmd.v "--toplevel" in ··· 40 in 41 let r = get_result @@ OS.Cmd.run_out cmd in 42 Format.printf "%s%!" r; 43 - Result.get_ok @@ Bos.OS.File.read temp_file 44 45 let jsoo_export_cma ~effects t = 46 or_fail ··· 48 (fun temp_file _ () -> jsoo_compile ~effects t temp_file) 49 () 50 51 let ocamlfind_includes lib = 52 get_result 53 @@ OS.Cmd.run_out 54 Cmd.( 55 v "ocamlfind" % "query" % lib % "-i-format" % "-predicates" % "byte") 56 57 let ocamlfind_cma ~predicate lib = 58 get_result ··· 78 | [ cma ] -> 79 let incl = ocamlfind_includes lib in 80 let incl = or_fail @@ Cmd.of_string incl in 81 - Some { incl; cma; ppx; name = lib } 82 | cmas -> 83 fatal 84 (Format.asprintf "expected one cma for %s, got %i" lib ··· 129 try 130 List.iter 131 (fun t -> 132 - Format.printf "%s@." t.name; 133 let js = jsoo_export_cma ~effects t in 134 output js) 135 all;
··· 29 } 30 (globalThis));|} 31 32 + type t = { 33 + name : string; 34 + incl : Cmd.t; 35 + runtime : string option; 36 + cma : string; 37 + ppx : bool; 38 + } 39 40 let jsoo_compile ~effects t temp_file = 41 let toplevel = if t.ppx then Cmd.empty else Cmd.v "--toplevel" in ··· 46 in 47 let r = get_result @@ OS.Cmd.run_out cmd in 48 Format.printf "%s%!" r; 49 + let jsoo_runtime = 50 + match t.runtime with 51 + | None -> "" 52 + | Some runtime_file -> 53 + let contents = 54 + Result.get_ok 55 + @@ Bos.OS.File.read (Result.get_ok @@ Fpath.of_string runtime_file) 56 + in 57 + "(function(joo_global_object){" ^ contents ^ "}(globalThis));\n" 58 + in 59 + let temp = Result.get_ok @@ Bos.OS.File.read temp_file in 60 + jsoo_runtime ^ temp 61 62 let jsoo_export_cma ~effects t = 63 or_fail ··· 65 (fun temp_file _ () -> jsoo_compile ~effects t temp_file) 66 () 67 68 + let ocamlfind_path lib = 69 + get_result @@ OS.Cmd.run_out Cmd.(v "ocamlfind" % "query" % lib) 70 + 71 let ocamlfind_includes lib = 72 get_result 73 @@ OS.Cmd.run_out 74 Cmd.( 75 v "ocamlfind" % "query" % lib % "-i-format" % "-predicates" % "byte") 76 + 77 + let ocamlfind_jsoo_runtime lib = 78 + get_result 79 + @@ OS.Cmd.run_out 80 + Cmd.( 81 + v "ocamlfind" % "query" % lib % "-format" % "%(jsoo_runtime)" 82 + % "-predicates" % "byte") 83 84 let ocamlfind_cma ~predicate lib = 85 get_result ··· 105 | [ cma ] -> 106 let incl = ocamlfind_includes lib in 107 let incl = or_fail @@ Cmd.of_string incl in 108 + let runtime = 109 + match ocamlfind_jsoo_runtime lib with 110 + | "" -> None 111 + | runtime -> 112 + let path = ocamlfind_path lib in 113 + let runtime = path ^ "/" ^ runtime in 114 + Format.printf "jsoo_runtime(%s) = %S@." lib runtime; 115 + Some runtime 116 + in 117 + Some { incl; runtime; cma; ppx; name = lib } 118 | cmas -> 119 fatal 120 (Format.asprintf "expected one cma for %s, got %i" lib ··· 165 try 166 List.iter 167 (fun t -> 168 + Format.printf "export %s@." t.name; 169 let js = jsoo_export_cma ~effects t in 170 output js) 171 all;