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