Move the addition of <lib>.a dependencies to Lib.archive_files (#493)

Move the addition of <lib>.a dependencies to Lib.archive_files

And refactor a bit the code
This commit is contained in:
Jérémie Dimino 2018-02-07 19:21:11 +00:00 committed by Rudi Grinberg
parent c7b0d708c2
commit 763feda683
5 changed files with 52 additions and 45 deletions

View File

@ -352,22 +352,24 @@ Add it to your jbuild file to remove this warning.
else
fun x -> x
in
let objs (cm, _, _, _) =
if mode = Mode.Byte then
[]
else
List.map ~f:(Path.change_extension ~ext:ctx.ext_obj) cm
let artifacts ~ext modules =
List.map modules ~f:(Module.obj_file ~obj_dir ~ext)
in
let register_native_objs_deps build =
match mode with
| Byte -> build
| Native ->
build >>>
Build.dyn_paths (Build.arr (artifacts ~ext:ctx.ext_obj))
in
SC.add_rule sctx
(Build.fanout4
(top_sorted_modules >>^ List.map ~f:(fun m ->
Module.cm_file m ~obj_dir (Mode.cm_kind mode)))
(register_native_objs_deps top_sorted_modules
>>^ artifacts ~ext:(Cm_kind.ext (Mode.cm_kind mode)))
(SC.expand_and_eval_set sctx ~scope ~dir lib.c_library_flags ~standard:[])
(Ocaml_flags.get flags mode)
(SC.expand_and_eval_set sctx ~scope ~dir lib.library_flags ~standard:[])
>>>
Build.dyn_paths (Build.arr objs)
>>>
Build.run ~context:ctx (Ok compiler)
~extra_targets:(
match mode with
@ -681,47 +683,50 @@ Add it to your jbuild file to remove this warning.
| _ -> (Byte, ["-custom"], ctx.ocamlc)
in
let exe = Path.relative dir (name ^ exe_ext) in
let libs_and_cm =
Build.fanout
(requires
>>> Build.dyn_paths (Build.arr (Lib.archive_files ~mode ~ext_lib:ctx.ext_lib)))
(top_sorted_modules >>^ List.map ~f:(fun m ->
Module.cm_file m ~obj_dir (Mode.cm_kind mode)))
let artifacts ~ext modules =
List.map modules ~f:(Module.obj_file ~obj_dir ~ext)
in
let objs (libs, cm) =
if mode = Mode.Byte then
[]
else
let libs =
let f = function
| Lib.Internal (dir, lib) -> Some (Path.relative dir (lib.name ^ ctx.ext_lib))
| External _ -> None
in
List.filter_map ~f libs
in
libs @ List.map ~f:(Path.change_extension ~ext:ctx.ext_obj) cm
let modules_and_cm_files =
Build.memoize "cm files"
(top_sorted_modules >>^ fun modules ->
(modules,
artifacts modules ~ext:(Cm_kind.ext (Mode.cm_kind mode))))
in
let register_native_objs_deps build =
match mode with
| Byte -> build
| Native ->
build >>>
Build.dyn_paths (Build.arr (fun (modules, _) ->
artifacts modules ~ext:ctx.ext_obj))
in
SC.add_rule sctx
(Build.fanout3
(libs_and_cm >>> Build.dyn_paths (Build.arr objs))
(Build.fanout4
requires
(register_native_objs_deps modules_and_cm_files >>^ snd)
(Ocaml_flags.get flags mode)
(SC.expand_and_eval_set sctx ~scope ~dir link_flags ~standard:[])
>>>
Build.dyn_paths (Build.arr (fun (libs, _, _, _) ->
Lib.archive_files libs ~mode ~ext_lib:ctx.ext_lib))
>>>
Build.run ~context:ctx
(Ok compiler)
[ Dyn (fun (_, flags,_) -> As flags)
[ Dyn (fun (_, _, flags,_) -> As flags)
; A "-o"; Target exe
; Dyn (fun (_, _, link_flags) -> As (link_custom @ link_flags))
; Dyn (fun ((libs, _), _, _) -> Lib.link_flags libs ~mode
~stdlib_dir:ctx.stdlib_dir)
; Dyn (fun ((_, cm_files), _, _) -> Deps cm_files)
; Dyn (fun (_, _, _, link_flags) ->
As (link_custom @ link_flags))
; Dyn (fun (libs, _, _, _) ->
Lib.link_flags libs ~mode ~stdlib_dir:ctx.stdlib_dir)
; Dyn (fun (_, cm_files, _, _) -> Deps cm_files)
]);
if mode = Mode.Byte then
let rules = Js_of_ocaml_rules.build_exe sctx ~dir ~js_of_ocaml ~src:exe in
let libs_and_cm_and_flags =
libs_and_cm
(requires &&& (modules_and_cm_files >>^ snd))
&&&
SC.expand_and_eval_set sctx ~scope ~dir js_of_ocaml.flags ~standard:(Js_of_ocaml_rules.standard ())
SC.expand_and_eval_set sctx ~scope ~dir js_of_ocaml.flags
~standard:(Js_of_ocaml_rules.standard ())
in
SC.add_rules sctx (List.map rules ~f:(fun r -> libs_and_cm_and_flags >>> r))

View File

@ -77,6 +77,11 @@ let archive_files ts ~mode ~ext_lib =
let l =
[Path.relative dir (lib.name ^ Mode.compiled_lib_ext mode)]
in
let l =
match mode with
| Byte -> l
| Native -> Path.relative dir (lib.name ^ ext_lib) :: l
in
if Jbuild.Library.has_stubs lib then
Jbuild.Library.stubs_archive lib ~dir ~ext_lib :: l
else

View File

@ -21,6 +21,8 @@ val c_include_flags : t list -> stdlib_dir:Path.t -> _ Arg_spec.t
val link_flags : t list -> mode:Mode.t -> stdlib_dir:Path.t -> _ Arg_spec.t
(** All the library archive files (.a, .cmxa, _stubs.a, ...) that
should be linked in when linking an executable. *)
val archive_files : t list -> mode:Mode.t -> ext_lib:string -> Path.t list
val jsoo_runtime_files : t list -> Path.t list

View File

@ -835,14 +835,9 @@ module PP = struct
add_rule sctx
(libs
>>>
Build.dyn_paths (Build.arr (fun libs ->
List.rev_append
(Lib.archive_files ~mode ~ext_lib:ctx.ext_lib libs)
(List.filter_map libs ~f:(function
| Lib.Internal (dir, lib) ->
Some (Path.relative dir (lib.name ^ ctx.ext_lib))
| External _ ->
None))))
Build.dyn_paths
(Build.arr
(Lib.archive_files ~mode ~ext_lib:ctx.ext_lib))
>>>
Build.run ~context:ctx (Ok compiler)
[ A "-o" ; Target target

View File

@ -15,6 +15,7 @@
ocamlc lib/.x.objs/x__Y.{cmi,cmo,cmt}
js_of_ocaml .js/js_of_ocaml/js_of_ocaml.cma.js
js_of_ocaml .js/stdlib/stdlib.cma.js
js_of_ocaml bin/technologic.bc.runtime.js
ocamlopt lib/.x.objs/x__Y.{cmx,o}
js_of_ocaml lib/.x.objs/x__Y.cmo.js
ocamlc lib/.x.objs/x.{cmi,cmo,cmt}
@ -23,7 +24,6 @@
ocamlc bin/.technologic.eobjs/z.{cmi,cmo,cmt}
ocamlopt lib/x.{a,cmxa}
js_of_ocaml lib/x.cma.js
js_of_ocaml bin/technologic.bc.runtime.js
js_of_ocaml bin/.technologic.eobjs/z.cmo.js
ocamlc bin/.technologic.eobjs/technologic.{cmi,cmo,cmt}
ocamlopt lib/x.cmxs