add shims with dune magic for 4.08 compat

This commit is contained in:
Simon Cruanes 2019-03-16 11:55:58 -05:00
parent 2d538e64e5
commit 4747ecc8d8
7 changed files with 58 additions and 11 deletions

View file

@ -1,6 +1,6 @@
QTEST_PREAMBLE='' QTEST_PREAMBLE=''
DONTTEST=../src/iterLabels.ml ../src/mkflags.ml DONTTEST=../src/iterLabels.ml ../src/mkflags.ml ../src/mkshims.ml ../src/bigarray/mkshims.ml
QTESTABLE=$(filter-out $(DONTTEST), \ QTESTABLE=$(filter-out $(DONTTEST), \
$(wildcard ../src/*.ml) \ $(wildcard ../src/*.ml) \
$(wildcard ../src/*.mli) \ $(wildcard ../src/*.mli) \

View file

@ -3,6 +3,8 @@
(** {1 Simple and Efficient Iterators} *) (** {1 Simple and Efficient Iterators} *)
open Iter_shims_
(** Iter abstract iterator type *) (** Iter abstract iterator type *)
type 'a t = ('a -> unit) -> unit type 'a t = ('a -> unit) -> unit

View file

@ -3,7 +3,7 @@
(** {1 Interface and Helpers for bigarrays} *) (** {1 Interface and Helpers for bigarrays} *)
open! Bigarray open! IterBigarrayShims_
let of_bigarray b yield = let of_bigarray b yield =
let len = Bigarray.Array1.dim b in let len = Bigarray.Array1.dim b in
@ -16,7 +16,7 @@ let mmap filename =
let fd = Unix.openfile filename [Unix.O_RDONLY] 0 in let fd = Unix.openfile filename [Unix.O_RDONLY] 0 in
let len = Unix.lseek fd 0 Unix.SEEK_END in let len = Unix.lseek fd 0 Unix.SEEK_END in
let _ = Unix.lseek fd 0 Unix.SEEK_SET in let _ = Unix.lseek fd 0 Unix.SEEK_SET in
let b = Bigarray.Array1.map_file fd Bigarray.char Bigarray.c_layout false len in let b = bigarray_map_file fd Bigarray.char Bigarray.c_layout false len in
try try
of_bigarray b yield; of_bigarray b yield;
Unix.close fd Unix.close fd

View file

@ -3,8 +3,18 @@
(name iter_bigarray) (name iter_bigarray)
(public_name iter.bigarray) (public_name iter.bigarray)
(libraries iter bigarray) (libraries iter bigarray)
(modules IterBigarray IterBigarrayShims_)
(wrapped false) (wrapped false)
(optional) (optional)
(flags :standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string) (flags :standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string)
(ocamlopt_flags :standard (:include ../flambda.flags)) (ocamlopt_flags :standard (:include ../flambda.flags)))
)
(executable
(name mkshims)
(modules mkshims)
(libraries dune.configurator))
(rule
(targets IterBigarrayShims_.ml)
(deps mkshims.exe)
(action (with-stdout-to %{targets} (run ./mkshims.exe))))

17
src/bigarray/mkshims.ml Normal file
View file

@ -0,0 +1,17 @@
module C = Configurator.V1
let shims_pre_408 = "
open! Bigarray
let bigarray_map_file = Bigarray.Array1.map_file
"
let shims_post_408 = "
let bigarray_map_file fd ty lay b len =
Unix.map_file fd ty lay b [| len |] |> Bigarray.array1_of_genarray
"
let () =
C.main ~name:"mkshims" (fun c ->
let version = C.ocaml_config_var_exn c "version" in
let major, minor = Scanf.sscanf version "%u.%u" (fun maj min -> maj, min) in
print_endline (if (major, minor) >= (4,8) then shims_post_408 else shims_post_408))

View file

@ -2,17 +2,24 @@
(targets flambda.flags) (targets flambda.flags)
(deps mkflags.ml) (deps mkflags.ml)
(mode fallback) (mode fallback)
(action (action (run ocaml ./mkflags.ml)))
(run ocaml ./mkflags.ml))
) (executable
(name mkshims)
(modules mkshims)
(libraries dune.configurator))
(rule
(targets Iter_shims_.ml)
(deps mkshims.exe)
(action (with-stdout-to %{targets} (run ./mkshims.exe))))
(library (library
(name iter) (name iter)
(public_name iter) (public_name iter)
(wrapped false) (wrapped false)
(modules Iter IterLabels) (modules Iter IterLabels Iter_shims_)
(flags :standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string -nolabels) (flags :standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string -nolabels)
(ocamlopt_flags :standard (:include flambda.flags)) (ocamlopt_flags :standard (:include flambda.flags))
(libraries bytes result) (libraries bytes result))
)

11
src/mkshims.ml Normal file
View file

@ -0,0 +1,11 @@
module C = Configurator.V1
let shims_pre_408 = "module Pervasives = Pervasives"
let shims_post_408 = "module Pervasives = Stdlib"
let () =
C.main ~name:"mkshims" (fun c ->
let version = C.ocaml_config_var_exn c "version" in
let major, minor = Scanf.sscanf version "%u.%u" (fun maj min -> maj, min) in
print_endline (if (major, minor) >= (4,8) then shims_post_408 else shims_post_408))