From 618bc8ffa9db6aa48dd8bf250d5daaf10f766fd9 Mon Sep 17 00:00:00 2001 From: Alpha Issiaga DIALLO Date: Mon, 13 Jun 2022 12:35:08 +0200 Subject: [PATCH] Fix bigarray config (#5494) (#5526) * Fix bigarray config (#5494) This filters out "bigarray" in (libraries) on ocaml >= 5.0. Signed-off-by: Alpha DIALLO Co-authored-by: Etienne Millon Co-authored-by: David Allsopp --- src/dune_rules/lib.ml | 27 +++++++++++++++ .../test-cases/bigarray.t/a/a.ml | 3 ++ .../test-cases/bigarray.t/a/dune | 3 ++ .../test-cases/bigarray.t/b/b.ml | 5 +++ .../test-cases/bigarray.t/b/b_lib.ml | 1 + .../test-cases/bigarray.t/b/dune | 10 ++++++ .../test-cases/bigarray.t/c/c.bigarray.ml | 3 ++ .../test-cases/bigarray.t/c/c.dummy.ml | 1 + .../test-cases/bigarray.t/c/c.nobigarray.ml | 1 + .../test-cases/bigarray.t/c/dune | 9 +++++ .../test-cases/bigarray.t/dune-project | 3 ++ .../test-cases/bigarray.t/run.t | 33 +++++++++++++++++++ 12 files changed, 99 insertions(+) create mode 100644 test/blackbox-tests/test-cases/bigarray.t/a/a.ml create mode 100644 test/blackbox-tests/test-cases/bigarray.t/a/dune create mode 100644 test/blackbox-tests/test-cases/bigarray.t/b/b.ml create mode 100644 test/blackbox-tests/test-cases/bigarray.t/b/b_lib.ml create mode 100644 test/blackbox-tests/test-cases/bigarray.t/b/dune create mode 100644 test/blackbox-tests/test-cases/bigarray.t/c/c.bigarray.ml create mode 100644 test/blackbox-tests/test-cases/bigarray.t/c/c.dummy.ml create mode 100644 test/blackbox-tests/test-cases/bigarray.t/c/c.nobigarray.ml create mode 100644 test/blackbox-tests/test-cases/bigarray.t/c/dune create mode 100644 test/blackbox-tests/test-cases/bigarray.t/dune-project create mode 100644 test/blackbox-tests/test-cases/bigarray.t/run.t diff --git a/src/dune_rules/lib.ml b/src/dune_rules/lib.ml index a8b3c4558c8..cc6f72e3546 100644 --- a/src/dune_rules/lib.ml +++ b/src/dune_rules/lib.ml @@ -1173,6 +1173,23 @@ end = struct { resolved; selects; re_exports } end + let remove_library deps target = + List.filter_map deps ~f:(fun (dep : Lib_dep.t) -> + match dep with + | Re_export (_, name) | Direct (_, name) -> + Option.some_if (not (Lib_name.equal target name)) dep + | Select select -> + let choices = + List.filter_map select.choices ~f:(fun choice -> + if Lib_name.Set.mem choice.forbidden target then None + else + Some + { choice with + required = Lib_name.Set.remove choice.required target + }) + in + Some (Select { select with choices })) + let resolve_complex_deps db deps ~private_deps : resolved_deps Memo.t = let resolve_select { Lib_dep.Select.result_fn; choices; loc } = let open Memo.O in @@ -1207,6 +1224,16 @@ end = struct in let open Memo.O in let open Resolved_deps_builder in + let deps = + let ocaml_version = db.lib_config.ocaml_version in + let bigarray_in_std_libraries = + Ocaml.Version.has_bigarray_library ocaml_version + in + if bigarray_in_std_libraries then deps + else + let bigarray = Lib_name.of_string "bigarray" in + remove_library deps bigarray + in let+ builder = Memo.List.fold_left deps ~init:empty ~f:(fun acc dep -> match (dep : Lib_dep.t) with diff --git a/test/blackbox-tests/test-cases/bigarray.t/a/a.ml b/test/blackbox-tests/test-cases/bigarray.t/a/a.ml new file mode 100644 index 00000000000..5f363cba7da --- /dev/null +++ b/test/blackbox-tests/test-cases/bigarray.t/a/a.ml @@ -0,0 +1,3 @@ +let _c = Bigarray.C_layout_typ + +let () = Printf.eprintf "Welcome to a\n%!" diff --git a/test/blackbox-tests/test-cases/bigarray.t/a/dune b/test/blackbox-tests/test-cases/bigarray.t/a/dune new file mode 100644 index 00000000000..026d705e7b8 --- /dev/null +++ b/test/blackbox-tests/test-cases/bigarray.t/a/dune @@ -0,0 +1,3 @@ +(executable + (name a) + (libraries bigarray)) diff --git a/test/blackbox-tests/test-cases/bigarray.t/b/b.ml b/test/blackbox-tests/test-cases/bigarray.t/b/b.ml new file mode 100644 index 00000000000..c658de2d5d3 --- /dev/null +++ b/test/blackbox-tests/test-cases/bigarray.t/b/b.ml @@ -0,0 +1,5 @@ +let _c1 = B_lib.v + +let _c2 = Bigarray.C_layout_typ + +let () = Printf.eprintf "Welcome to b\n%!" diff --git a/test/blackbox-tests/test-cases/bigarray.t/b/b_lib.ml b/test/blackbox-tests/test-cases/bigarray.t/b/b_lib.ml new file mode 100644 index 00000000000..66c0f9056f5 --- /dev/null +++ b/test/blackbox-tests/test-cases/bigarray.t/b/b_lib.ml @@ -0,0 +1 @@ +let v = Bigarray.C_layout_typ diff --git a/test/blackbox-tests/test-cases/bigarray.t/b/dune b/test/blackbox-tests/test-cases/bigarray.t/b/dune new file mode 100644 index 00000000000..5f4811db28d --- /dev/null +++ b/test/blackbox-tests/test-cases/bigarray.t/b/dune @@ -0,0 +1,10 @@ +(library + (name b_lib) + (libraries + (re_export bigarray)) + (modules b_lib)) + +(executable + (name b) + (libraries b_lib) + (modules b)) diff --git a/test/blackbox-tests/test-cases/bigarray.t/c/c.bigarray.ml b/test/blackbox-tests/test-cases/bigarray.t/c/c.bigarray.ml new file mode 100644 index 00000000000..fa19a403c52 --- /dev/null +++ b/test/blackbox-tests/test-cases/bigarray.t/c/c.bigarray.ml @@ -0,0 +1,3 @@ +let _c = Bigarray.C_layout_typ + +let () = Printf.eprintf "Welcome to c WITH bigarray support\n%!" diff --git a/test/blackbox-tests/test-cases/bigarray.t/c/c.dummy.ml b/test/blackbox-tests/test-cases/bigarray.t/c/c.dummy.ml new file mode 100644 index 00000000000..7c51afbe0a7 --- /dev/null +++ b/test/blackbox-tests/test-cases/bigarray.t/c/c.dummy.ml @@ -0,0 +1 @@ +let () = Printf.eprintf "Welcome to c with nothing inferred\n%!" diff --git a/test/blackbox-tests/test-cases/bigarray.t/c/c.nobigarray.ml b/test/blackbox-tests/test-cases/bigarray.t/c/c.nobigarray.ml new file mode 100644 index 00000000000..cfb46f4b387 --- /dev/null +++ b/test/blackbox-tests/test-cases/bigarray.t/c/c.nobigarray.ml @@ -0,0 +1 @@ +let () = Printf.eprintf "Welcome to c WITHOUT bigarray support\n%!" diff --git a/test/blackbox-tests/test-cases/bigarray.t/c/dune b/test/blackbox-tests/test-cases/bigarray.t/c/dune new file mode 100644 index 00000000000..db8a8f26215 --- /dev/null +++ b/test/blackbox-tests/test-cases/bigarray.t/c/dune @@ -0,0 +1,9 @@ +(executable + (name c) + (libraries + (select + c.ml + from + (!bigarray -> c.nobigarray.ml) + (bigarray -> c.bigarray.ml) + (-> c.dummy.ml)))) diff --git a/test/blackbox-tests/test-cases/bigarray.t/dune-project b/test/blackbox-tests/test-cases/bigarray.t/dune-project new file mode 100644 index 00000000000..ce21dd8268b --- /dev/null +++ b/test/blackbox-tests/test-cases/bigarray.t/dune-project @@ -0,0 +1,3 @@ +(lang dune 3.0) + +(implicit_transitive_deps false) diff --git a/test/blackbox-tests/test-cases/bigarray.t/run.t b/test/blackbox-tests/test-cases/bigarray.t/run.t new file mode 100644 index 00000000000..59fa72d786a --- /dev/null +++ b/test/blackbox-tests/test-cases/bigarray.t/run.t @@ -0,0 +1,33 @@ +This tests the support for the bigarray atom in the dune libraries stanza. + +History: +- OCaml 4.05 ([ocaml/ocaml#997](https://github.com/ocaml/ocaml/pull/997) and +[ocaml/ocaml#1077](https://github.com/ocaml/ocaml/pull/1077)) add +`Unix.map_file` allowing the `map_file` functions in `Bigarray` to be +deprecated. Bigarray remains a separate library. +- OCaml 4.07 ([ocaml/ocaml#1685](https://github.com/ocaml/ocaml/pull/1685)) +adds `Stdlib.Bigarray`, but without the `map_file` functions (since these +required `Unix.file_descr`. The separate library remains with those +functions (but still marked as deprecated). Code can be updated to use +Unix.map_file and then Stdlib.Bigarray and not require the separate library +at all, but the separate remains compatible with OCaml 4.06. +- OCaml 4.08 ([ocaml/ocaml#2263](https://github.com/ocaml/ocaml/pull/2263)) +deletes the `map_file` functions completely, requiring _all_ code to be +updated to use `Unix.map_file`, if appropriate. From this release, it is +unnecessary to link with the separate Bigarray library. +- OCaml 5.00 ([ocaml/ocaml#10896](https://github.com/ocaml/ocaml/pull/10896) +removes the separate Bigarray library. + +Code may be written which is designed to support both OCaml 4.06 and earlier and +also OCaml 5.0+. In such cases, it is appropriate to have `(libraries bigarray)` +even though there is no Bigarray library in OCaml 5. + +This test uses `(libraries bigarray)` (the program uses `Bigarray`) + $ dune exec a/a.exe + Welcome to a +This test uses `(libraries (re_export bigarray))` similarly + $ dune exec b/b.exe + Welcome to b +This test uses a `(select )` construct and should always select bigarray support + $ dune exec c/c.exe + Welcome to c WITH bigarray support