Add a (no_dynlink) field
This commit is contained in:
parent
cc7ea35a14
commit
d948edbc4c
|
@ -337,6 +337,9 @@ the library and you are free to expose only the modules you want.
|
||||||
built by default. This is only useful when writing libraries for the
|
built by default. This is only useful when writing libraries for the
|
||||||
OCaml toplevel
|
OCaml toplevel
|
||||||
|
|
||||||
|
- =(no_dynlink)= is to disable dynamic linking of the library. This is
|
||||||
|
for advanced use only, by default you shouldn't set this option
|
||||||
|
|
||||||
- =(kind <kind>)= is the kind of the library. The default is =normal=,
|
- =(kind <kind>)= is the kind of the library. The default is =normal=,
|
||||||
other available choices are =ppx_rewriter= and =ppx_deriver= and
|
other available choices are =ppx_rewriter= and =ppx_deriver= and
|
||||||
must be set when the library is intended to be used as a ppx
|
must be set when the library is intended to be used as a ppx
|
||||||
|
|
|
@ -1109,7 +1109,7 @@ module Gen(P : Params) = struct
|
||||||
| Cmx ->
|
| Cmx ->
|
||||||
[lib_cm_all ~dir lib Cmx])
|
[lib_cm_all ~dir lib Cmx])
|
||||||
|
|
||||||
let build_cm ?sandbox ~flags ~cm_kind ~dep_graph ~requires
|
let build_cm ?sandbox ~dynlink ~flags ~cm_kind ~dep_graph ~requires
|
||||||
~(modules : Module.t String_map.t) ~dir ~alias_module (m : Module.t) =
|
~(modules : Module.t String_map.t) ~dir ~alias_module (m : Module.t) =
|
||||||
Option.iter (Cm_kind.compiler cm_kind) ~f:(fun compiler ->
|
Option.iter (Cm_kind.compiler cm_kind) ~f:(fun compiler ->
|
||||||
Option.iter (Module.cm_source ~dir m cm_kind) ~f:(fun src ->
|
Option.iter (Module.cm_source ~dir m cm_kind) ~f:(fun src ->
|
||||||
|
@ -1172,6 +1172,7 @@ module Gen(P : Params) = struct
|
||||||
; cmt_args
|
; cmt_args
|
||||||
; Dyn Lib.include_flags
|
; Dyn Lib.include_flags
|
||||||
; As extra_args
|
; As extra_args
|
||||||
|
; if dynlink || cm_kind <> Cmx then As [] else A "-nodynlink"
|
||||||
; A "-no-alias-deps"
|
; A "-no-alias-deps"
|
||||||
; A "-I"; Path dir
|
; A "-I"; Path dir
|
||||||
; (match alias_module with
|
; (match alias_module with
|
||||||
|
@ -1181,17 +1182,19 @@ module Gen(P : Params) = struct
|
||||||
; A "-c"; Ml_kind.flag ml_kind; Dep src
|
; A "-c"; Ml_kind.flag ml_kind; Dep src
|
||||||
])))
|
])))
|
||||||
|
|
||||||
let build_module ?sandbox ~flags m ~dir ~dep_graph ~modules ~requires ~alias_module =
|
let build_module ?sandbox ~dynlink ~flags m ~dir ~dep_graph ~modules ~requires
|
||||||
|
~alias_module =
|
||||||
List.iter Cm_kind.all ~f:(fun cm_kind ->
|
List.iter Cm_kind.all ~f:(fun cm_kind ->
|
||||||
build_cm ?sandbox ~flags ~dir ~dep_graph ~modules m ~cm_kind ~requires ~alias_module)
|
build_cm ?sandbox ~dynlink ~flags ~dir ~dep_graph ~modules m ~cm_kind ~requires
|
||||||
|
~alias_module)
|
||||||
|
|
||||||
let build_modules ~flags ~dir ~dep_graph ~modules ~requires ~alias_module =
|
let build_modules ~dynlink ~flags ~dir ~dep_graph ~modules ~requires ~alias_module =
|
||||||
String_map.iter
|
String_map.iter
|
||||||
(match alias_module with
|
(match alias_module with
|
||||||
| None -> modules
|
| None -> modules
|
||||||
| Some (m : Module.t) -> String_map.remove m.name modules)
|
| Some (m : Module.t) -> String_map.remove m.name modules)
|
||||||
~f:(fun ~key:_ ~data:m ->
|
~f:(fun ~key:_ ~data:m ->
|
||||||
build_module m ~flags ~dir ~dep_graph ~modules ~requires ~alias_module)
|
build_module m ~dynlink ~flags ~dir ~dep_graph ~modules ~requires ~alias_module)
|
||||||
|
|
||||||
(* +-----------------------------------------------------------------+
|
(* +-----------------------------------------------------------------+
|
||||||
| Interpretation of [modules] fields |
|
| Interpretation of [modules] fields |
|
||||||
|
@ -1425,10 +1428,12 @@ module Gen(P : Params) = struct
|
||||||
~ppx_runtime_libraries:lib.ppx_runtime_libraries;
|
~ppx_runtime_libraries:lib.ppx_runtime_libraries;
|
||||||
List.iter (Lib_db.select_rules ~dir lib.buildable.libraries) ~f:add_rule;
|
List.iter (Lib_db.select_rules ~dir lib.buildable.libraries) ~f:add_rule;
|
||||||
|
|
||||||
build_modules ~flags ~dir ~dep_graph ~modules ~requires ~alias_module;
|
let dynlink = lib.dynlink in
|
||||||
|
build_modules ~dynlink ~flags ~dir ~dep_graph ~modules ~requires ~alias_module;
|
||||||
Option.iter alias_module ~f:(fun m ->
|
Option.iter alias_module ~f:(fun m ->
|
||||||
let flags = Ocaml_flags.default () in
|
let flags = Ocaml_flags.default () in
|
||||||
build_module m
|
build_module m
|
||||||
|
~dynlink
|
||||||
~sandbox:alias_module_build_sandbox
|
~sandbox:alias_module_build_sandbox
|
||||||
~flags:{ flags with common = flags.common @ ["-w"; "-49"] }
|
~flags:{ flags with common = flags.common @ ["-w"; "-49"] }
|
||||||
~dir
|
~dir
|
||||||
|
@ -1476,9 +1481,11 @@ module Gen(P : Params) = struct
|
||||||
let static = stubs_archive lib ~dir in
|
let static = stubs_archive lib ~dir in
|
||||||
let dynamic = dll lib ~dir in
|
let dynamic = dll lib ~dir in
|
||||||
if List.mem Mode.Native ~set:lib.modes &&
|
if List.mem Mode.Native ~set:lib.modes &&
|
||||||
List.mem Mode.Byte ~set:lib.modes then begin
|
List.mem Mode.Byte ~set:lib.modes &&
|
||||||
(* If we build for both modes, use a single invocation to build both the static
|
lib.dynlink
|
||||||
and dynamic libraries *)
|
then begin
|
||||||
|
(* If we build for both modes and support dynlink, use a single invocation to
|
||||||
|
build both the static and dynamic libraries *)
|
||||||
ocamlmklib ~sandbox:false ~custom:false ~targets:[static; dynamic]
|
ocamlmklib ~sandbox:false ~custom:false ~targets:[static; dynamic]
|
||||||
end else begin
|
end else begin
|
||||||
ocamlmklib ~sandbox:false ~custom:true ~targets:[static];
|
ocamlmklib ~sandbox:false ~custom:true ~targets:[static];
|
||||||
|
@ -1597,7 +1604,9 @@ module Gen(P : Params) = struct
|
||||||
|
|
||||||
List.iter (Lib_db.select_rules ~dir exes.buildable.libraries) ~f:add_rule;
|
List.iter (Lib_db.select_rules ~dir exes.buildable.libraries) ~f:add_rule;
|
||||||
|
|
||||||
build_modules ~flags ~dir ~dep_graph ~modules ~requires ~alias_module:None;
|
(* CR-someday jdimino: this should probably say [~dynlink:false] *)
|
||||||
|
build_modules ~dynlink:true ~flags ~dir ~dep_graph ~modules ~requires
|
||||||
|
~alias_module:None;
|
||||||
|
|
||||||
List.iter exes.names ~f:(fun name ->
|
List.iter exes.names ~f:(fun name ->
|
||||||
List.iter Mode.all ~f:(fun mode ->
|
List.iter Mode.all ~f:(fun mode ->
|
||||||
|
@ -1926,7 +1935,7 @@ module Gen(P : Params) = struct
|
||||||
; lib_archive ~dir lib ~ext:ctx.ext_lib
|
; lib_archive ~dir lib ~ext:ctx.ext_lib
|
||||||
]
|
]
|
||||||
in
|
in
|
||||||
if ctx.natdynlink_supported then
|
if ctx.natdynlink_supported && lib.dynlink then
|
||||||
files @ [ lib_archive ~dir lib ~ext:".cmxs" ]
|
files @ [ lib_archive ~dir lib ~ext:".cmxs" ]
|
||||||
else
|
else
|
||||||
files
|
files
|
||||||
|
@ -1939,7 +1948,7 @@ module Gen(P : Params) = struct
|
||||||
Path.relative dir (fn ^ ".h"))
|
Path.relative dir (fn ^ ".h"))
|
||||||
]
|
]
|
||||||
in
|
in
|
||||||
let dlls = if_ (byte && Library.has_stubs lib) [dll ~dir lib] in
|
let dlls = if_ (byte && Library.has_stubs lib && lib.dynlink) [dll ~dir lib] in
|
||||||
let execs =
|
let execs =
|
||||||
match lib.kind with
|
match lib.kind with
|
||||||
| Normal | Ppx_deriver -> []
|
| Normal | Ppx_deriver -> []
|
||||||
|
|
|
@ -413,6 +413,7 @@ module Library = struct
|
||||||
; wrapped : bool
|
; wrapped : bool
|
||||||
; optional : bool
|
; optional : bool
|
||||||
; buildable : Buildable.t
|
; buildable : Buildable.t
|
||||||
|
; dynlink : bool
|
||||||
}
|
}
|
||||||
|
|
||||||
let v1 =
|
let v1 =
|
||||||
|
@ -436,6 +437,7 @@ module Library = struct
|
||||||
field "wrapped" bool ~default:true >>= fun wrapped ->
|
field "wrapped" bool ~default:true >>= fun wrapped ->
|
||||||
field_b "optional" >>= fun optional ->
|
field_b "optional" >>= fun optional ->
|
||||||
field "self_build_stubs_archive" (option string) ~default:None >>= fun self_build_stubs_archive ->
|
field "self_build_stubs_archive" (option string) ~default:None >>= fun self_build_stubs_archive ->
|
||||||
|
field_b "no_dynlink" >>= fun no_dynlink ->
|
||||||
return
|
return
|
||||||
{ name
|
{ name
|
||||||
; public
|
; public
|
||||||
|
@ -457,6 +459,7 @@ module Library = struct
|
||||||
; wrapped
|
; wrapped
|
||||||
; optional
|
; optional
|
||||||
; buildable
|
; buildable
|
||||||
|
; dynlink = not no_dynlink
|
||||||
})
|
})
|
||||||
|
|
||||||
let vjs =
|
let vjs =
|
||||||
|
@ -503,6 +506,7 @@ module Library = struct
|
||||||
; wrapped
|
; wrapped
|
||||||
; optional
|
; optional
|
||||||
; buildable
|
; buildable
|
||||||
|
; dynlink = true
|
||||||
})
|
})
|
||||||
|
|
||||||
let has_stubs t =
|
let has_stubs t =
|
||||||
|
|
Loading…
Reference in New Issue