From abcf4a22c0f37bb515672707ec388fb5bee177f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Kr=C3=BCger?= Date: Fri, 16 Sep 2022 20:39:36 +0100 Subject: [PATCH] Manifest: Add ctypes support --- dune-project | 1 + manifest/manifest.ml | 66 +++++++++++++++++++++++++++++++++++++++++-- manifest/manifest.mli | 24 ++++++++++++++++ 3 files changed, 88 insertions(+), 3 deletions(-) diff --git a/dune-project b/dune-project index f153562b1fb6..943f80e34e3b 100644 --- a/dune-project +++ b/dune-project @@ -1,6 +1,7 @@ (lang dune 3.0) (formatting (enabled_for ocaml)) (cram enable) +(using ctypes 0.1) (package (name internal-devtools)) (package (name octez-accuser-PtKathma)) (package (name octez-accuser-PtLimaPt)) diff --git a/manifest/manifest.ml b/manifest/manifest.ml index f441894a179b..a02d8b9dc4ef 100644 --- a/manifest/manifest.ml +++ b/manifest/manifest.ml @@ -185,8 +185,8 @@ module Dune = struct ?(preprocess = Stdlib.List.[]) ?(preprocessor_deps = Stdlib.List.[]) ?(virtual_modules = Stdlib.List.[]) ?default_implementation ?implements ?modules ?modules_without_implementation ?modes ?foreign_stubs - ?c_library_flags ?(private_modules = Stdlib.List.[]) ?js_of_ocaml - (names : string list) = + ?c_library_flags ?(ctypes = E) ?(private_modules = Stdlib.List.[]) + ?js_of_ocaml (names : string list) = [ V [ @@ -271,6 +271,7 @@ module Dune = struct S "names" :: of_atom_list x.names; ] ); (opt c_library_flags @@ fun x -> [S "c_library_flags"; of_atom_list x]); + ctypes; ]; ] @@ -769,6 +770,59 @@ module Flags = struct let include_ f = {standard = false; rest = Dune.[S ":include"; S f]} end +module Ctypes = struct + type description = {instance : string; functor_ : string} + + type t = { + external_library_name : string; + include_header : string; + extra_search_dir : string; + type_description : description; + function_description : description; + generated_types : string; + generated_entry_point : string; + } + + let to_dune desc = + Dune. + [ + S "ctypes"; + [S "external_library_name"; S desc.external_library_name]; + [ + S "build_flags_resolver"; + [ + S "vendored"; + [ + S "c_flags"; + S ":standard"; + S "-Wno-discarded-qualifiers"; + S ("-I" ^ desc.extra_search_dir); + ]; + [ + S "c_library_flags"; + S ":standard"; + S ("-l" ^ desc.external_library_name); + S ("-L" ^ desc.extra_search_dir); + ]; + ]; + ]; + [S "headers"; [S "include"; S desc.include_header]]; + [ + S "type_description"; + [S "instance"; S desc.type_description.instance]; + [S "functor"; S desc.type_description.functor_]; + ]; + [ + S "function_description"; + [S "concurrency"; S "unlocked"]; + [S "instance"; S desc.function_description.instance]; + [S "functor"; S desc.function_description.functor_]; + ]; + [S "generated_types"; S desc.generated_types]; + [S "generated_entry_point"; S desc.generated_entry_point]; + ] +end + module Env : sig (* See manifest.mli for documentation *) @@ -945,6 +999,7 @@ module Target = struct cram : bool; license : string option; extra_authors : string list; + ctypes : Ctypes.t option; } and preprocessor = PPS of t * string list | Staged_PPS of t list @@ -1071,6 +1126,7 @@ module Target = struct ?dune:Dune.s_expr -> ?flags:Flags.t -> ?foreign_stubs:Dune.foreign_stubs -> + ?ctypes:Ctypes.t -> ?implements:t option -> ?inline_tests:inline_tests -> ?js_compatible:bool -> @@ -1157,7 +1213,7 @@ module Target = struct let internal make_kind ?all_modules_except ?bisect_ppx ?c_library_flags ?(conflicts = []) ?(dep_files = []) ?(dep_globs = []) ?(deps = []) - ?(dune = Dune.[]) ?flags ?foreign_stubs ?implements ?inline_tests + ?(dune = Dune.[]) ?flags ?foreign_stubs ?ctypes ?implements ?inline_tests ?js_compatible ?js_of_ocaml ?documentation ?(linkall = false) ?modes ?modules ?(modules_without_implementation = []) ?(npm_deps = []) ?ocaml ?opam ?opam_bug_reports ?opam_doc ?opam_homepage @@ -1474,6 +1530,7 @@ module Target = struct cram; license; extra_authors; + ctypes; } let public_lib ?internal_name = @@ -2007,6 +2064,7 @@ let generate_dune (internal : Target.internal) = | None -> Dune.E | Some docs -> Dune.(S "documentation" :: docs) in + let ctypes = Option.map Ctypes.to_dune internal.ctypes in Dune.( executable_or_library kind @@ -2030,6 +2088,7 @@ let generate_dune (internal : Target.internal) = ?modes:internal.modes ?foreign_stubs:internal.foreign_stubs ?c_library_flags:internal.c_library_flags + ?ctypes ~private_modules:internal.private_modules ?js_of_ocaml:internal.js_of_ocaml :: documentation :: create_empty_files :: internal.dune) @@ -2401,6 +2460,7 @@ let generate_dune_project_files () = Format.fprintf fmt "(lang dune %s)@." dune_lang_version ; Format.fprintf fmt "(formatting (enabled_for ocaml))@." ; Format.fprintf fmt "(cram enable)@." ; + Format.fprintf fmt "(using ctypes 0.1)@." ; ( Target.iter_internal_by_opam @@ fun package internals -> let has_public_target = List.exists diff --git a/manifest/manifest.mli b/manifest/manifest.mli index 369a428c7c8d..e03651424b16 100644 --- a/manifest/manifest.mli +++ b/manifest/manifest.mli @@ -485,6 +485,29 @@ module Flags : sig val disabled_warnings_to_string : int list -> string end +module Ctypes : sig + type description = {instance : string; functor_ : string} + + (** Dune Ctypes stanza description *) + type t = { + external_library_name : string; + (** Base name of the shared object or library archive that you want to + link against *) + include_header : string; (** Header file to include *) + extra_search_dir : string; + (** The C compiler and linker will look in this directory to find header + files and libraries. *) + type_description : description; + (** Module information for the type stub descriptions *) + function_description : description; + (** Module information for the function stub descriptions *) + generated_types : string; + (** Module in which the generated stub types are placed *) + generated_entry_point : string; + (* Output module name of the final generated stub module *) + } +end + (** Preprocessors. *) type preprocessor @@ -666,6 +689,7 @@ type 'a maker = ?dune:Dune.s_expr -> ?flags:Flags.t -> ?foreign_stubs:Dune.foreign_stubs -> + ?ctypes:Ctypes.t -> ?implements:target -> ?inline_tests:inline_tests -> ?js_compatible:bool -> -- GitLab