From 13b0eb9f2badd40bf963d679c49da8bc9179977b Mon Sep 17 00:00:00 2001 From: David Allsopp Date: Fri, 16 Jun 2017 11:54:14 +0200 Subject: [PATCH] Convert link_flags to the ordered set DSL --- doc/jbuild.rst | 3 +++ src/gen_rules.ml | 12 +++++++----- src/jbuild.ml | 6 +++--- src/jbuild.mli | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/doc/jbuild.rst b/doc/jbuild.rst index d00b7fd7..ccb6290a 100644 --- a/doc/jbuild.rst +++ b/doc/jbuild.rst @@ -226,6 +226,9 @@ binary at the same place as where ``ocamlc`` was found, or when there is a - ``(libraries ())`` specifies the library dependencies. See the section about `Library dependencies`_ for more details +- ``(link_flags )`` specifies additional flags to pass to the linker. + This field supports ``(:include ...)`` forms + - ``(modules )`` specifies which modules in the current directory Jbuilder should consider when building this executable. Modules not listed here will be ignored and cannot be used inside the executable described by diff --git a/src/gen_rules.ml b/src/gen_rules.ml index 90b54088..295f7797 100644 --- a/src/gen_rules.ml +++ b/src/gen_rules.ml @@ -418,10 +418,10 @@ module Gen(P : Params) = struct let build_exe ~js_of_ocaml ~flags ~dir ~requires ~name ~mode ~modules ~dep_graph ~link_flags ~force_custom_bytecode = let exe_ext = Mode.exe_ext mode in - let mode, link_flags, compiler = + let mode, link_custom, compiler = match force_custom_bytecode, Context.compiler ctx mode with - | false, Some compiler -> (mode, link_flags, compiler) - | _ -> (Byte, "-custom" :: link_flags, ctx.ocamlc) + | false, Some compiler -> (mode, [], compiler) + | _ -> (Byte, ["-custom"], ctx.ocamlc) in let dep_graph = Ml_kind.Dict.get dep_graph Impl in let exe = Path.relative dir (name ^ exe_ext) in @@ -441,13 +441,15 @@ module Gen(P : Params) = struct SC.add_rule sctx (libs_and_cm &&& + Build.fanout (Ocaml_flags.get flags mode) + (SC.expand_and_eval_set ~dir link_flags ~standard:[]) >>> Build.run ~context:ctx (Dep compiler) - [ Dyn (fun (_, flags) -> As flags) + [ Dyn (fun (_, (flags,_)) -> As flags) ; A "-o"; Target exe - ; As link_flags + ; Dyn (fun (_, (_, link_flags)) -> As (link_custom @ link_flags)) ; Dyn (fun ((libs, _), _) -> Lib.link_flags libs ~mode) ; Dyn (fun ((_, cm_files), _) -> Deps cm_files) ]); diff --git a/src/jbuild.ml b/src/jbuild.ml index aac30e32..52af9fae 100644 --- a/src/jbuild.ml +++ b/src/jbuild.ml @@ -635,15 +635,15 @@ module Executables = struct type t = { names : string list ; link_executables : bool - ; link_flags : string list + ; link_flags : Ordered_set_lang.Unexpanded.t ; modes : Mode.Dict.Set.t ; buildable : Buildable.t } let common_v1 pkgs names public_names ~multi = Buildable.v1 >>= fun buildable -> - field "link_executables" bool ~default:true >>= fun link_executables -> - field "link_flags" (list string) ~default:[] >>= fun link_flags -> + field "link_executables" bool ~default:true >>= fun link_executables -> + field_oslu "link_flags" >>= fun link_flags -> map_validate (field "modes" Mode.Dict.Set.t ~default:Mode.Dict.Set.all) ~f:(fun modes -> if Mode.Dict.Set.is_empty modes then diff --git a/src/jbuild.mli b/src/jbuild.mli index e0b7582e..3bf19fd1 100644 --- a/src/jbuild.mli +++ b/src/jbuild.mli @@ -170,7 +170,7 @@ module Executables : sig type t = { names : string list ; link_executables : bool - ; link_flags : string list + ; link_flags : Ordered_set_lang.Unexpanded.t ; modes : Mode.Dict.Set.t ; buildable : Buildable.t }