diff --git a/src/context.ml b/src/context.ml index 2c5f0882..fd311ec1 100644 --- a/src/context.ml +++ b/src/context.ml @@ -31,6 +31,7 @@ type t = ; findlib : Findlib.t ; arch_sixtyfour : bool ; opam_var_cache : (string, string) Hashtbl.t + ; natdynlink_supported : bool ; ocamlc_config : (string * string) list ; version : string ; stdlib_dir : Path.t @@ -197,6 +198,7 @@ let create ~(kind : Kind.t) ~path ~env ~name ~merlin = in let get_path var = Path.absolute (get var) in let stdlib_dir = get_path "standard_library" in + let natdynlink_supported = Path.exists (Path.relative stdlib_dir "dynlink.cmxa") in return { name ; kind @@ -221,6 +223,8 @@ let create ~(kind : Kind.t) ~path ~env ~name ~merlin = ; opam_var_cache + ; natdynlink_supported + ; stdlib_dir ; ocamlc_config = String_map.bindings ocamlc_config ; version = get "version" diff --git a/src/context.mli b/src/context.mli index 5b1003d1..c4469b9c 100644 --- a/src/context.mli +++ b/src/context.mli @@ -70,6 +70,9 @@ type t = ; opam_var_cache : (string, string) Hashtbl.t + ; (** Native dynlink *) + natdynlink_supported : bool + ; (** Output of [ocamlc -config] *) ocamlc_config : (string * string) list ; version : string diff --git a/src/gen_rules.ml b/src/gen_rules.ml index 89775730..56a9d62a 100644 --- a/src/gen_rules.ml +++ b/src/gen_rules.ml @@ -1407,29 +1407,30 @@ module Gen(P : Params) = struct List.iter Mode.all ~f:(fun mode -> build_lib lib ~flags ~dir ~mode ~modules ~dep_graph); - Option.iter ctx.ocamlopt ~f:(fun ocamlopt -> - let src = lib_archive lib ~dir ~ext:(Mode.compiled_lib_ext Native) in - let dst = lib_archive lib ~dir ~ext:".cmxs" in - let build = - Build.run - (Dep ocamlopt) - [ Ocaml_flags.get flags Native - ; A "-shared"; A "-linkall" - ; A "-I"; Path dir - ; A "-o"; Target dst - ; Dep src - ] - in - let build = - if Library.has_stubs lib then - Build.path (stubs_archive ~dir lib) - >>> - build - else - build - in - add_rule build - ); + if ctx.natdynlink_supported then + Option.iter ctx.ocamlopt ~f:(fun ocamlopt -> + let src = lib_archive lib ~dir ~ext:(Mode.compiled_lib_ext Native) in + let dst = lib_archive lib ~dir ~ext:".cmxs" in + let build = + Build.run + (Dep ocamlopt) + [ Ocaml_flags.get flags Native + ; A "-shared"; A "-linkall" + ; A "-I"; Path dir + ; A "-o"; Target dst + ; Dep src + ] + in + let build = + if Library.has_stubs lib then + Build.path (stubs_archive ~dir lib) + >>> + build + else + build + in + add_rule build + ); let flags = match alias_module with @@ -1833,10 +1834,16 @@ module Gen(P : Params) = struct (match ctx.ocamlopt with | None -> [] | Some _ -> - [ lib_archive ~dir lib ~ext:".cmxa" - ; lib_archive ~dir lib ~ext:ctx.ext_lib - ; lib_archive ~dir lib ~ext:".cmxs" - ]) + let files = + [ lib_archive ~dir lib ~ext:".cmxa" + ; lib_archive ~dir lib ~ext:ctx.ext_lib + ] + in + if ctx.natdynlink_supported then + files @ [ lib_archive ~dir lib ~ext:".cmxs" ] + else + files + ) ; (match lib.js_of_ocaml with | None -> [] | Some { javascript_files = l; _ } ->