Skip to content

Commit fec8a08

Browse files
Octachrondra27
authored andcommitted
use the compiler META files when available
Signed-off-by: David Allsopp <david.allsopp@metastack.com>
1 parent a515b1b commit fec8a08

4 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/dune_rules/context.ml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,14 @@ let create ~(kind : Kind.t) ~path ~env ~env_nodes ~name ~merlin ~targets
482482
(vars, ocfg)
483483
| Error msg -> Error (Ocamlc_config, msg)))
484484
in
485-
let findlib_paths = ocamlpath @ default_ocamlpath in
485+
let stdlib_dir = Path.of_string (Ocaml_config.standard_library ocfg) in
486486
let version = Ocaml.Version.of_ocaml_config ocfg in
487+
let default_ocamlpath =
488+
if Ocaml.Version.has_META_files version then
489+
stdlib_dir :: default_ocamlpath
490+
else default_ocamlpath
491+
in
492+
let findlib_paths = ocamlpath @ default_ocamlpath in
487493
let env =
488494
(* See comment in ansi_color.ml for setup_env_for_colors. For versions
489495
where OCAML_COLOR is not supported, but 'color' is in OCAMLPARAM, use
@@ -547,7 +553,6 @@ let create ~(kind : Kind.t) ~path ~env ~env_nodes ~name ~merlin ~targets
547553
(Option.map findlib_config ~f:Findlib.Config.env))
548554
|> Env.extend_env (Env_nodes.extra_env ~profile env_nodes)
549555
in
550-
let stdlib_dir = Path.of_string (Ocaml_config.standard_library ocfg) in
551556
let natdynlink_supported = Ocaml_config.natdynlink_supported ocfg in
552557
let arch_sixtyfour = Ocaml_config.word_size ocfg = 64 in
553558
let* ocamlopt = get_ocaml_tool "ocamlopt" in

src/dune_rules/findlib/meta.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ let main_modules names =
159159
List.map ~f:String.capitalize_ascii names
160160
|> String.concat ~sep:" " |> rule "main_modules" [] Set
161161

162-
let builtins ~stdlib_dir ~version:ocaml_version =
162+
let pre_ocaml_5_builtins ~stdlib_dir ~version:ocaml_version =
163163
let version = version "[distributed with OCaml]" in
164164
let simple name ?(labels = false) ?dir ?archive_name ?kind ?exists_if_ext deps
165165
=
@@ -302,6 +302,11 @@ let builtins ~stdlib_dir ~version:ocaml_version =
302302
(Lib_name.package_name name, simplify t)))
303303
|> Package.Name.Map.of_list_exn
304304

305+
let builtins ~stdlib_dir ~version =
306+
if Ocaml.Version.has_META_files version then
307+
Memo.return Package.Name.Map.empty
308+
else pre_ocaml_5_builtins ~stdlib_dir ~version
309+
305310
let string_of_action = function
306311
| Set -> "="
307312
| Add -> "+="

src/ocaml/version.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ let has_bigarray_library version = version < (5, 0, 0)
4747
let supports_alerts version = version >= (4, 8, 0)
4848

4949
let has_sandboxed_otherlibs version = version >= (5, 0, 0)
50+
51+
let has_META_files version = version >= (5, 0, 0)

src/ocaml/version.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,6 @@ val supports_alerts : t -> bool
7171
(** Whether [dynlink], [str] and [unix] are in subdirectories of the standard
7272
library *)
7373
val has_sandboxed_otherlibs : t -> bool
74+
75+
(** Whether the compiler distributes META files independently of ocamlfind *)
76+
val has_META_files : t -> bool

0 commit comments

Comments
 (0)