Skip to content

Commit c6cd81e

Browse files
committed
WIP
1 parent 86e5ddf commit c6cd81e

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed

src/dune_rules/jsoo/jsoo_rules.ml

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,27 @@ let jsoo ~dir sctx =
194194
"js_of_ocaml"
195195
;;
196196

197+
let jsoo_memo ~dir sctx =
198+
Super_context.resolve_program_memo
199+
sctx
200+
~dir
201+
~loc:None
202+
~where:Original_path
203+
~hint:install_jsoo_hint
204+
"js_of_ocaml"
205+
;;
206+
207+
let jsoo_has_shapes ~dir sctx =
208+
let* jsoo = jsoo_memo ~dir sctx in
209+
let+ jsoo_version = Version.jsoo_version jsoo in
210+
match jsoo_version with
211+
| Some version ->
212+
(match Version.compare version (5, 8) with
213+
| Lt -> false
214+
| Gt | Eq -> true)
215+
| None -> false
216+
;;
217+
197218
type sub_command =
198219
| Compile
199220
| Link
@@ -427,15 +448,14 @@ let build_cm' sctx ~dir ~in_context ~src ~target ~config ~shapes ~sourcemap =
427448
js_of_ocaml_rule sctx ~sub_command:Compile ~dir ~flags ~spec ~target ~config ~sourcemap
428449
;;
429450

430-
let shapes_enabled = true
431-
432451
let build_cm cctx ~dir ~in_context ~src ~obj_dir ~config:config_opt =
433452
let name = with_js_ext (Path.basename src) in
434453
let target = in_obj_dir ~obj_dir ~config:config_opt [ name ] in
435454
let sctx = Compilation_context.super_context cctx in
436455
let ctx = Super_context.context sctx |> Context.build_context in
456+
let+ jsoo_has_shapes = jsoo_has_shapes ~dir sctx in
437457
let shapes =
438-
if shapes_enabled
458+
if jsoo_has_shapes
439459
then
440460
Some
441461
(let open Action_builder.O in
@@ -475,7 +495,10 @@ let setup_separate_compilation_rules sctx components =
475495
let config = Config.of_string s_config in
476496
let pkg = Lib_name.parse_string_exn (Loc.none, s_pkg) in
477497
let ctx = Super_context.context sctx in
478-
let* installed_libs = Lib.DB.installed ctx in
498+
let* installed_libs = Lib.DB.installed ctx
499+
and* jsoo_has_shapes =
500+
jsoo_has_shapes ~dir:(Context.build_context ctx).build_dir sctx
501+
in
479502
Lib.DB.find installed_libs pkg
480503
>>= (function
481504
| None -> Memo.return ()
@@ -512,7 +535,7 @@ let setup_separate_compilation_rules sctx components =
512535
in
513536
let target = in_build_dir build_context ~config [ lib_name; with_js_ext name ] in
514537
let shapes =
515-
if shapes_enabled
538+
if jsoo_has_shapes
516539
then (* FIXME: we should load shapes *)
517540
Some (Action_builder.return [])
518541
else None

src/dune_rules/jsoo/jsoo_rules.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ val build_cm
2222
-> src:Path.t
2323
-> obj_dir:Path.Build.t Obj_dir.t
2424
-> config:Config.t option
25-
-> Action.Full.t Action_builder.With_targets.t
25+
-> Action.Full.t Action_builder.With_targets.t Memo.t
2626

2727
val build_exe
2828
: Compilation_context.t

src/dune_rules/lib_rules.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ let setup_build_archives (lib : Library.t) ~top_sorted_modules ~cctx ~expander ~
485485
~obj_dir)
486486
in
487487
Memo.parallel_iter action_with_targets ~f:(fun rule ->
488+
let* rule = rule in
488489
Super_context.add_rule sctx ~dir ~loc:lib.buildable.loc rule))
489490
in
490491
Memo.when_

src/dune_rules/module_compilation.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ let build_module ?(force_write_cmi = false) ?(precompiled_cmi = false) cctx m =
316316
(* Build *.cmo.js *)
317317
let sctx = Compilation_context.super_context cctx in
318318
let dir = Compilation_context.dir cctx in
319-
let action_with_targets =
319+
let* action_with_targets =
320320
Jsoo_rules.build_cm
321321
cctx
322322
~dir

test/blackbox-tests/test-cases/jsoo/inline-tests.t/run.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ Run inline tests using node js
99
$ dune runtest
1010
inline tests (Byte)
1111
inline tests (Byte)
12+
Warning: your program contains effect handlers; you should probably run js_of_ocaml with option '--enable=effects'
1213
inline tests (Native)
1314
inline tests (Native)
14-
Warning: your program contains effect handlers; you should probably run js_of_ocaml with option '--enable=effects'
1515
inline tests (JS)
1616
inline tests (JS)
1717

0 commit comments

Comments
 (0)