forked from dbuenzli/brr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
B0.ml
188 lines (162 loc) · 6.88 KB
/
B0.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
open B0_kit.V000
(* OCaml library names *)
let js_of_ocaml_toplevel = B0_ocaml.libname "js_of_ocaml-toplevel"
let js_of_ocaml_compiler_runtime =
B0_ocaml.libname "js_of_ocaml-compiler.runtime"
let brr = B0_ocaml.libname "brr"
let brr_ocaml_poke = B0_ocaml.libname "brr.ocaml_poke"
let brr_ocaml_poke_ui = B0_ocaml.libname "brr.ocaml_poke_ui"
let brr_poke = B0_ocaml.libname "brr.poke"
let brr_poked = B0_ocaml.libname "brr.poked"
(* Units *)
let brr_lib =
let srcs = Fpath.[ `Dir (v "src") ] in
let requires = [js_of_ocaml_compiler_runtime] in
B0_ocaml.lib brr ~doc:"Brr JavaScript FFI and browser API" ~srcs ~requires
let brr_ocaml_poke_lib =
let srcs = Fpath.[ `Dir (v "src/ocaml_poke") ] in
let requires = [brr] in
let doc = "OCaml poke objects interaction" in
B0_ocaml.lib brr_ocaml_poke ~doc ~srcs ~requires
let brr_ocaml_poke_ui_lib =
let srcs = Fpath.[ `Dir (v "src/ocaml_poke_ui") ] in
let requires = [brr; brr_ocaml_poke] in
let doc = "OCaml poke user interface (toplevel)" in
B0_ocaml.lib brr_ocaml_poke_ui ~doc ~srcs ~requires
let brr_poke_lib =
let srcs = Fpath.[ `Dir (v "src/poke") ] in
let requires =
[js_of_ocaml_compiler_runtime; js_of_ocaml_toplevel; brr]
in
let doc = "Poke explicitely" in
B0_ocaml.lib brr_poke ~doc ~srcs ~requires
let brr_poked_lib =
let srcs = Fpath.[ `Dir (v "src/poked") ] in
let requires = [brr_poke] in
let doc = "Poke by side effect" in
B0_ocaml.lib brr_poked ~doc ~srcs ~requires
(* Web extension *)
let console =
let srcs = Fpath.[ `Dir (v "src/console");
`X (v "src/console/ocaml_console.js"); (* GNGNGNGN *)
`X (v "src/console/devtools.js");
`X (v "src/console/highlight.pack.js");
(* FIXME we want something like ext_js *) ]
in
let requires = [brr; brr_ocaml_poke; brr_ocaml_poke_ui] in
let comp_mode = `Whole and source_map = Some `Inline in
let comp = Cmd.(arg "--pretty") in
let meta = B0_jsoo.meta ~requires ~comp ~comp_mode ~source_map () in
let doc = "Browser developer tool OCaml console" in
B0_jsoo.web "ocaml_console" ~doc ~srcs ~meta
let poke =
let srcs = Fpath.[ `File (v "test/poke.ml"); `File (v "test/base.css") ] in
let requires = [brr; brr_poked] in
let meta = B0_jsoo.meta ~requires ~toplevel:true () in
let doc = "OCaml console test" in
B0_jsoo.web "poke" ~doc ~srcs ~meta
let top =
let srcs = Fpath.[ `File (v "test/top.ml");
(* FIXME js_of_ocaml chokes `File "src/console/highlight.pack.js"; *)
`File (v "src/console/ocaml_console.css") ] in
let requires =
[ js_of_ocaml_compiler_runtime;
brr; brr_ocaml_poke_ui; brr_poke; brr_ocaml_poke]
in
let comp_mode = `Whole in
let meta = B0_jsoo.meta ~requires ~comp_mode ~toplevel:true () in
let doc = "In page toplevel test" in
B0_jsoo.web "top" ~doc ~srcs ~meta
(* Tests and samples *)
let test_assets = Fpath.[ `File (v "test/base.css") ]
let test ?(requires = [brr]) n ~doc =
let srcs = `File (Fpath.v (Fmt.str "test/%s.ml" n)) :: test_assets in
let meta = B0_jsoo.meta ~requires () in
B0_jsoo.web n ~doc ~srcs ~meta
let test_module ?doc top m requires =
let test = Fmt.str "test_%s" (String.Ascii.uncapitalize m) in
let doc = Fmt.str "Test %s.%s module" top m in
let srcs = `File (Fpath.v (Fmt.str "test/%s.ml" test)) :: test_assets in
let comp = Cmd.(arg "--pretty") in
let meta = B0_jsoo.meta ~requires ~comp () in
B0_jsoo.web test ~doc ~srcs ~meta
let hello = test "test_hello" ~doc:"Brr console hello size"
let test_base64 = test_module "Brr" "Base64" [brr]
let test_c2d = test_module "Brr_canvas" "C2d" [brr]
let test_clipboard = test_module "Brr_io" "Clipboard" [brr]
let test_console = test_module "Brr" "Console" [brr]
let test_file = test_module "Brr" "File" [brr]
let test_geo = test_module "Brr_io" "Geolocation" [brr]
let test_gl = test_module "Brr_canvas" "Gl" [brr]
let test_history = test_module "Brr" "History" [brr]
let test_media = test_module "Brr_io" "Media" [brr]
let test_notif = test_module "Brr_io" "Notification" [brr]
let test_webaudio = test_module "Brr_webaudio" "Audio" [brr]
let test_webcrypto = test_module "Brr_webcrypto" "Crypto" [brr]
let test_webmidi = test_module "Brr_webmidi" "Midi" [brr]
let test_webgpu = test_module "Brr_webgpu" "Gpu" [brr]
let test_worker = test_module "Brr" "Worker" [brr]
let min =
let srcs = Fpath.[ `File (v "test/min.ml"); `File (v "test/min.html") ] in
let requires = [brr] in
let meta = B0_jsoo.meta ~requires () in
B0_jsoo.web "min" ~doc:"Brr minimal web page" ~srcs ~meta
let nop =
let srcs = Fpath.[ `File (v "test/nop.ml") ] in
let meta = B0_jsoo.meta ~requires:[] () in
B0_jsoo.web "nop" ~doc:"js_of_ocaml nop web page" ~srcs ~meta
(* Packs *)
let test_pack = (* FIXME add stuff in b0 *)
let us = [ test_console ] in
let meta = B0_meta.(empty |> tag test) in
B0_pack.v ~locked:false "test" ~doc:"Brr test suite" ~meta us
let jsoo_toplevels =
(* FIXME this is wrong and make that nice to write *)
let tops = B0_unit.has_meta B0_jsoo.toplevel in
let us = List.filter tops (B0_unit.list ()) in
let doc = "Units with toplevel (slow to build)" in
B0_pack.v ~locked:false "tops" ~doc us
let default =
let meta =
let open B0_meta in
empty
|> add authors ["The brr programmers"]
|> add maintainers ["Daniel Bünzli <daniel.buenzl [email protected]>"]
|> add homepage "https://erratique.ch/software/brr"
|> add online_doc "https://erratique.ch/software/brr/doc/"
|> add licenses ["ISC"; "BSD-3-Clause"]
|> add repo "git+https://erratique.ch/repos/brr.git"
|> add issues "https://github.com/dbuenzli/brr/issues"
|> add description_tags
[ "reactive"; "declarative"; "frp"; "front-end"; "browser";
"org:erratique"]
|> add B0_opam.Meta.build
{|[["ocaml" "pkg/pkg.ml" "build" "--dev-pkg" "%{dev}%"]]|}
|> tag B0_opam.tag
|> add B0_opam.Meta.depends
[ "ocaml", {|>= "4.08.0"|};
"ocamlfind", {|build|};
"ocamlbuild", {|build|};
"topkg", {|build & >= "1.0.3"|};
"js_of_ocaml-compiler", {|>= "4.1.0"|};
"js_of_ocaml-toplevel", {|>= "4.1.0"|};
]
in
B0_pack.v "default" ~doc:"brr package" ~meta ~locked:true @@
B0_unit.list ()
(* Cmdlets *)
let update_console =
B0_cmdlet.v ~doc:"Update dev console" "update-dev-console" @@ fun env args ->
B0_cmdlet.exit_of_result @@
(* FIXME so much path boilerplate. Summon units/packs to be build
and get info directly. *)
let b0_dir = B0_cmdlet.Env.b0_dir env in
let variant = "user" in
let build_dir = B0_dir.build_dir ~b0_dir ~variant in
let unit_dir = B0_dir.unit_build_dir ~build_dir ~name:"ocaml_console" in
let src = Fpath.(unit_dir / "ocaml_console.js") in
let dst = Fpath.(v "src" / "console" / "ocaml_console.js") in
let dst = B0_cmdlet.in_scope_dir env dst in
let cmd = Cmd.(arg "b0" % "-u" % "ocaml_console" % "-u" % "poke") in
Result.bind (Os.Cmd.run cmd) @@ fun () ->
Os.File.copy ~force:true ~make_path:false ~src dst