@@ -316,6 +316,15 @@ let wasmoo ~dir sctx =
316316 " wasm_of_ocaml"
317317;;
318318
319+ let jsoo_has_shapes jsoo_version =
320+ match jsoo_version with
321+ | Some version ->
322+ (match Version. compare version (6 , 1 ) with
323+ | Lt -> false
324+ | Gt | Eq -> true )
325+ | None -> false
326+ ;;
327+
319328type sub_command =
320329 | Compile
321330 | Link
@@ -522,6 +531,12 @@ let jsoo_archives ~mode ctx config lib =
522531 ]))
523532;;
524533
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+
525540let link_rule
526541 ~mode
527542 cc
@@ -537,11 +552,6 @@ let link_rule
537552 =
538553 let sctx = Compilation_context. super_context cc in
539554 let dir = Compilation_context. dir cc in
540- let mod_name m =
541- Module_name.Unique. artifact_filename
542- (Module. obj_name m)
543- ~ext: (Js_of_ocaml.Ext. cmo ~mode )
544- in
545555 let ctx = Super_context. context sctx |> Context. build_context in
546556 let get_all =
547557 let open Action_builder.O in
@@ -567,12 +577,13 @@ let link_rule
567577 let special_units =
568578 List. concat_map to_link ~f: (function
569579 | Lib_flags.Lib_and_module. Lib _lib -> []
570- | 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 ] ])
571582 in
572583 let all_libs = List. concat_map libs ~f: (jsoo_archives ~mode ctx config) in
573584 let all_other_modules =
574585 List. map cm ~f: (fun m ->
575- 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 ]))
576587 in
577588 let std_exit =
578589 Path. build
@@ -606,8 +617,25 @@ let link_rule
606617 ~sourcemap
607618;;
608619
609- let build_cm' sctx ~dir ~in_context ~mode ~src ~target ~config ~sourcemap =
610- let spec = Command.Args. Dep src in
620+ let build_cm' sctx ~dir ~in_context ~mode ~src ~target ~config ~shapes ~sourcemap =
621+ let spec =
622+ Command.Args. (
623+ S
624+ [ Dep src
625+ ; Dyn
626+ (let open Action_builder.O in
627+ let * jsoo_version =
628+ let * jsoo = jsoo ~dir sctx in
629+ Action_builder. of_memo @@ Version. jsoo_version jsoo
630+ in
631+ let + shapes =
632+ match jsoo_has_shapes jsoo_version with
633+ | false -> Action_builder. return []
634+ | true -> shapes
635+ in
636+ S (List. map shapes ~f: (fun s -> S [ A " --load-shape" ; Dep s ])))
637+ ])
638+ in
611639 let flags = in_context.Js_of_ocaml.In_context. flags in
612640 js_of_ocaml_rule
613641 sctx
@@ -622,17 +650,38 @@ let build_cm' sctx ~dir ~in_context ~mode ~src ~target ~config ~sourcemap =
622650 ~sourcemap
623651;;
624652
625- let build_cm sctx ~dir ~in_context ~mode ~src ~obj_dir ~config =
653+ let build_cm cctx ~dir ~in_context ~mode ~src ~obj_dir ~deps ~ config : config_opt =
626654 let name = with_js_ext ~mode (Path. basename src) in
627- let target = in_obj_dir ~obj_dir ~config [ name ] in
655+ let target = in_obj_dir ~obj_dir ~config: config_opt [ name ] in
656+ let sctx = Compilation_context. super_context cctx in
657+ let ctx = Super_context. context sctx |> Context. build_context in
658+ let shapes =
659+ let open Action_builder.O in
660+ let + libs = Resolve.Memo. read (Compilation_context. requires_link cctx)
661+ and + deps = deps
662+ and + config =
663+ match config_opt with
664+ | None ->
665+ let flags = in_context.Js_of_ocaml.In_context. flags in
666+ js_of_ocaml_flags sctx ~dir ~mode flags
667+ |> Action_builder. bind ~f: (fun (x : _ Js_of_ocaml.Flags.t ) -> x.compile)
668+ |> Action_builder. map ~f: Config. of_flags
669+ | Some config -> Action_builder. return config
670+ in
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 ]))
675+ in
628676 build_cm'
629677 sctx
630678 ~dir
631679 ~in_context
632680 ~mode
633681 ~src
634682 ~target
635- ~config: (Option. map config ~f: Action_builder. return)
683+ ~shapes
684+ ~config: (Option. map config_opt ~f: Action_builder. return)
636685 ~sourcemap: Js_of_ocaml.Sourcemap. Inline
637686;;
638687
@@ -649,6 +698,11 @@ let setup_separate_compilation_rules sctx components =
649698 | None -> Memo. return ()
650699 | Some pkg ->
651700 let info = Lib. info pkg in
701+ let requires =
702+ let open Resolve.Memo.O in
703+ let * reqs = Lib. requires pkg in
704+ Lib. closure ~linking: false reqs
705+ in
652706 let lib_name = Lib_name. to_string (Lib. name pkg) in
653707 let * archives =
654708 let archives = (Lib_info. archives info).byte in
@@ -679,6 +733,23 @@ let setup_separate_compilation_rules sctx components =
679733 let target =
680734 in_build_dir build_context ~config [ lib_name; with_js_ext ~mode name ]
681735 in
736+ let shapes =
737+ let open Action_builder.O in
738+ let + requires = Resolve.Memo. read requires in
739+ let l =
740+ List. concat_map requires ~f: (fun lib ->
741+ jsoo_archives ~mode build_context config lib)
742+ in
743+ match lib_name with
744+ | "stdlib" -> l
745+ | _ ->
746+ Path. build
747+ (in_build_dir
748+ build_context
749+ ~config
750+ [ " stdlib" ; with_js_ext ~mode " stdlib.cma" ])
751+ :: l
752+ in
682753 build_cm'
683754 sctx
684755 ~dir
@@ -688,6 +759,7 @@ let setup_separate_compilation_rules sctx components =
688759 ~target
689760 ~config: (Some (Action_builder. return config))
690761 ~sourcemap: Js_of_ocaml.Sourcemap. Inline
762+ ~shapes
691763 |> Super_context. add_rule sctx ~dir )))
692764;;
693765
0 commit comments