From 8c640a262969ef44cd8bc0e0abe95e2a54f4c3f5 Mon Sep 17 00:00:00 2001 From: Marcos Magueta Date: Thu, 5 Mar 2026 23:42:15 -0300 Subject: ocaml re-migration --- lib/core_functions.ml | 11 +++++++++++ lib/core_types.ml | 3 +++ lib/dune | 40 ++++++++++++++++++++++++++++++++++++++++ lib/interop.ml | 9 +++++++++ 4 files changed, 63 insertions(+) create mode 100644 lib/core_functions.ml create mode 100644 lib/core_types.ml create mode 100644 lib/dune create mode 100644 lib/interop.ml (limited to 'lib') diff --git a/lib/core_functions.ml b/lib/core_functions.ml new file mode 100644 index 0000000..083e0cf --- /dev/null +++ b/lib/core_functions.ml @@ -0,0 +1,11 @@ +module Types = Types_generated + +module Functions (F : Ctypes.FOREIGN) = struct + open F + + let compute_hash = + foreign "compute_hash" + (F.(@->) (Ctypes.ptr Ctypes.char) + (F.(@->) Ctypes.string (F.returning Ctypes.void))) + +end diff --git a/lib/core_types.ml b/lib/core_types.ml new file mode 100644 index 0000000..45f5720 --- /dev/null +++ b/lib/core_types.ml @@ -0,0 +1,3 @@ +module Types (F : Ctypes.TYPE) = struct + let hash_size = F.constant "HASH_SIZE" F.int +end diff --git a/lib/dune b/lib/dune new file mode 100644 index 0000000..1397a97 --- /dev/null +++ b/lib/dune @@ -0,0 +1,40 @@ +(library + (name relational_engine) + (libraries + ctypes + ctypes-foreign + data-encoding + lwt + lwt.unix + lwt-exit + ppx_protocol_conv_xml_light + sexplib) + (preprocess + (pps ppx_deriving.show ppx_sexp_conv ppx_protocol_conv)) + (c_library_flags + (-L %{env:LIBRELATIONAL_ENGINE_LIB_PATH=}) + (-lrelational_engine)) + ;; (foreign_stubs + ;; (language cxx) + ;; (names merklecpp_stubs) + ;; (flags + ;; (:standard -lssl -lcrypto) + ;; (-L %{env:LIBRESSL_LIB_PATH=}) + ;; (-I %{env:LIBRESSL_INCLUDE_PATH=}) + ;; (-I %{env:MERKLECPP_INCLUDE_PATH=}))) + (ctypes + (external_library_name relational_engine) + (headers + (include %{env:LIBRELATIONAL_ENGINE_INCLUDE_PATH=}/library.h)) + (build_flags_resolver + (vendored + (c_flags -L %{env:LIBRELATIONAL_ENGINE_LIB_PATH=}))) + (type_description + (instance Types) + (functor core_types)) + (function_description + (concurrency unlocked) + (instance Functions) + (functor core_functions)) + (generated_types Types_generated) + (generated_entry_point C))) diff --git a/lib/interop.ml b/lib/interop.ml new file mode 100644 index 0000000..3b7a3d2 --- /dev/null +++ b/lib/interop.ml @@ -0,0 +1,9 @@ +open Ctypes + +module Sha256 = struct + let compute_hash content = + let size_with_null_terminator = C.Types.hash_size + 1 in + let buf = Ctypes.allocate_n char ~count:size_with_null_terminator in + let () = C.Functions.compute_hash buf (Bytes.to_string content) in + Ctypes.coerce (ptr char) Ctypes.string buf +end -- cgit v1.2.3