aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMarcos Magueta <maguetamarcos@gmail.com>2026-03-05 23:42:15 -0300
committerMarcos Magueta <maguetamarcos@gmail.com>2026-03-05 23:42:15 -0300
commit8c640a262969ef44cd8bc0e0abe95e2a54f4c3f5 (patch)
tree84f9ddd9e41236fb7a6f540aab07e65db9bc93cb /lib
parent295c6a5a1f2b0db9d756ffe7bf413553a0c02737 (diff)
downloadSakura-8c640a262969ef44cd8bc0e0abe95e2a54f4c3f5.tar.gz
Sakura-8c640a262969ef44cd8bc0e0abe95e2a54f4c3f5.zip
ocaml re-migration
Diffstat (limited to '')
-rw-r--r--lib/core_functions.ml11
-rw-r--r--lib/core_types.ml3
-rw-r--r--lib/dune40
-rw-r--r--lib/interop.ml9
4 files changed, 63 insertions, 0 deletions
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