more robust detection of lwt's version

This commit is contained in:
Simon Cruanes 2026-04-02 10:32:52 -04:00
parent 9c6245e88d
commit 31cc90abb4
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 31 additions and 12 deletions

View file

@ -9,6 +9,7 @@
Opentelemetry_client
-open
Opentelemetry_atomic)
(modules :standard \ gen_types_)
(optional) ; lwt
(libraries
opentelemetry.util
@ -26,18 +27,13 @@
lwt.unix)
(synopsis "Lwt-specific helpers for opentelemetry-client"))
(rule
(enabled_if
(and
%{lib-available:lwt}
(>= %{version:lwt} 6.0)))
(action
(copy types_.ml.6 types_.ml)))
(executable
(name gen_types_)
(modules gen_types_))
(rule
(enabled_if
(and
%{lib-available:lwt}
(< %{version:lwt} 6.0)))
(enabled_if %{lib-available:lwt})
(deps types_.ml.5 types_.ml.6)
(target types_.ml)
(action
(copy types_.ml.5 types_.ml)))
(run ./gen_types_.exe %{version:lwt})))

View file

@ -0,0 +1,23 @@
let copy_file src dst =
let ic = open_in src in
let oc = open_out dst in
let buf = Bytes.create 1024 in
(try
while true do
let n = input ic buf 0 (Bytes.length buf) in
if n = 0 then raise End_of_file;
output oc buf 0 n
done
with End_of_file -> ());
close_in ic;
close_out oc
let () =
let version = Sys.argv.(1) in
let major =
try Scanf.sscanf version "%d.%s" (fun maj _ -> maj) with _ -> 0
in
if major >= 6 then
copy_file "types_.ml.6" "types_.ml"
else
copy_file "types_.ml.5" "types_.ml"