Skip to content

Commit 0eab66f

Browse files
committed
read shapes for cmo.js
Signed-off-by: Hugo Heuzard <[email protected]>
1 parent feb1e46 commit 0eab66f

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

src/dune_rules/jsoo/jsoo_rules.ml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,12 @@ let jsoo_archives ~mode ctx config lib =
531531
]))
532532
;;
533533

534+
let cmo_js_of_module ~mode m =
535+
Module_name.Unique.artifact_filename
536+
(Module.obj_name m)
537+
~ext:(Js_of_ocaml.Ext.cmo ~mode)
538+
;;
539+
534540
let link_rule
535541
~mode
536542
cc
@@ -546,11 +552,6 @@ let link_rule
546552
=
547553
let sctx = Compilation_context.super_context cc in
548554
let dir = Compilation_context.dir cc in
549-
let mod_name m =
550-
Module_name.Unique.artifact_filename
551-
(Module.obj_name m)
552-
~ext:(Js_of_ocaml.Ext.cmo ~mode)
553-
in
554555
let ctx = Super_context.context sctx |> Context.build_context in
555556
let get_all =
556557
let open Action_builder.O in
@@ -576,12 +577,13 @@ let link_rule
576577
let special_units =
577578
List.concat_map to_link ~f:(function
578579
| Lib_flags.Lib_and_module.Lib _lib -> []
579-
| Module (obj_dir, m) -> [ in_obj_dir' ~obj_dir ~config:None [ mod_name m ] ])
580+
| Module (obj_dir, m) ->
581+
[ in_obj_dir' ~obj_dir ~config:None [ cmo_js_of_module ~mode m ] ])
580582
in
581583
let all_libs = List.concat_map libs ~f:(jsoo_archives ~mode ctx config) in
582584
let all_other_modules =
583585
List.map cm ~f:(fun m ->
584-
Path.build (in_obj_dir ~obj_dir ~config:None [ mod_name m ]))
586+
Path.build (in_obj_dir ~obj_dir ~config:None [ cmo_js_of_module ~mode m ]))
585587
in
586588
let std_exit =
587589
Path.build
@@ -648,14 +650,15 @@ let build_cm' sctx ~dir ~in_context ~mode ~src ~target ~config ~shapes ~sourcema
648650
~sourcemap
649651
;;
650652

651-
let build_cm cctx ~dir ~in_context ~mode ~src ~obj_dir ~config:config_opt =
653+
let build_cm cctx ~dir ~in_context ~mode ~src ~obj_dir ~deps ~config:config_opt =
652654
let name = with_js_ext ~mode (Path.basename src) in
653655
let target = in_obj_dir ~obj_dir ~config:config_opt [ name ] in
654656
let sctx = Compilation_context.super_context cctx in
655657
let ctx = Super_context.context sctx |> Context.build_context in
656658
let shapes =
657659
let open Action_builder.O in
658660
let+ libs = Resolve.Memo.read (Compilation_context.requires_link cctx)
661+
and+ deps = deps
659662
and+ config =
660663
match config_opt with
661664
| None ->
@@ -665,8 +668,10 @@ let build_cm cctx ~dir ~in_context ~mode ~src ~obj_dir ~config:config_opt =
665668
|> Action_builder.map ~f:Config.of_flags
666669
| Some config -> Action_builder.return config
667670
in
668-
Path.build (in_build_dir ctx ~config [ "stdlib"; with_js_ext ~mode "stdlib.cma" ])
669-
:: List.concat_map libs ~f:(fun lib -> jsoo_archives ~mode ctx config lib)
671+
(Path.build (in_build_dir ctx ~config [ "stdlib"; with_js_ext ~mode "stdlib.cma" ])
672+
:: List.concat_map libs ~f:(fun lib -> jsoo_archives ~mode ctx config lib))
673+
@ List.map deps ~f:(fun m ->
674+
Path.build (in_obj_dir ~obj_dir ~config:config_opt [ cmo_js_of_module ~mode m ]))
670675
in
671676
build_cm'
672677
sctx

src/dune_rules/jsoo/jsoo_rules.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ val build_cm
2222
-> mode:Js_of_ocaml.Mode.t
2323
-> src:Path.t
2424
-> obj_dir:Path.Build.t Obj_dir.t
25+
-> deps:Module.t list Action_builder.t
2526
-> config:Config.t option
2627
-> Action.Full.t Action_builder.With_targets.t
2728

src/dune_rules/lib_rules.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ let setup_build_archives (lib : Library.t) ~top_sorted_modules ~cctx ~expander ~
467467
~mode
468468
~config:(Some config)
469469
~src:(Path.build src)
470+
~deps:(Action_builder.return [])
470471
~obj_dir)
471472
in
472473
Memo.parallel_iter action_with_targets ~f:(fun rule ->

src/dune_rules/module_compilation.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,9 @@ let build_module ?(force_write_cmi = false) ?(precompiled_cmi = false) cctx m =
311311
match Obj_dir.Module.cm_file obj_dir m ~kind:(Ocaml Cmo) with
312312
| None -> Memo.return ()
313313
| Some src ->
314+
let ml_kind = Ml_kind.Impl in
315+
let dep_graph = Ml_kind.Dict.get (Compilation_context.dep_graphs cctx) ml_kind in
316+
let module_deps = Dep_graph.deps_of dep_graph m in
314317
Memo.parallel_iter Js_of_ocaml.Mode.all ~f:(fun mode ->
315318
Compilation_context.js_of_ocaml cctx
316319
|> Js_of_ocaml.Mode.Pair.select ~mode
@@ -326,6 +329,7 @@ let build_module ?(force_write_cmi = false) ?(precompiled_cmi = false) cctx m =
326329
~mode
327330
~src:(Path.build src)
328331
~obj_dir
332+
~deps:module_deps
329333
~config:None
330334
in
331335
Super_context.add_rule sctx ~dir action_with_targets)))

0 commit comments

Comments
 (0)