aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--.gitignore2
-rw-r--r--bin/dune1
-rw-r--r--bin/main.ml4
-rw-r--r--deps/libressl.nix13
-rw-r--r--deps/merklecpp.nix22
-rw-r--r--flake.lock16
-rw-r--r--flake.nix45
-rw-r--r--lib/dune10
-rw-r--r--lib/hello.ml1
-rw-r--r--lib/merklecpp_stubs.cpp15
10 files changed, 105 insertions, 24 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..2790b52
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+result
+_build \ No newline at end of file
diff --git a/bin/dune b/bin/dune
index 0888311..f0cdc01 100644
--- a/bin/dune
+++ b/bin/dune
@@ -2,3 +2,4 @@
(public_name relational_engine)
(name main)
(libraries relational_engine))
+
diff --git a/bin/main.ml b/bin/main.ml
index 7bf6048..6fe3d69 100644
--- a/bin/main.ml
+++ b/bin/main.ml
@@ -1 +1,3 @@
-let () = print_endline "Hello, World!"
+open Relational_engine.Hello
+
+let _ = hello ()
diff --git a/deps/libressl.nix b/deps/libressl.nix
new file mode 100644
index 0000000..ad33870
--- /dev/null
+++ b/deps/libressl.nix
@@ -0,0 +1,13 @@
+{ pkgs, ... }:
+pkgs.stdenv.mkDerivation {
+ name = "libressl-lib";
+ src = ./.;
+ buildInputs = with pkgs; [libressl.dev pkg-config];
+ installPhase = ''
+ mkdir -p $out/lib
+ mkdir -p $out/include
+ libressl_path=$(${pkgs.pkg-config}/bin/pkg-config --libs ${pkgs.libressl.dev}/lib/pkgconfig/libssl.pc | awk '{sub(/^-L/, ""); sub(/ -lssl$/, ""); print}')
+ cp -r $libressl_path/* $out/lib
+ cp -r ${pkgs.libressl.dev}/include/* $out/include
+ '';
+}
diff --git a/deps/merklecpp.nix b/deps/merklecpp.nix
new file mode 100644
index 0000000..459a957
--- /dev/null
+++ b/deps/merklecpp.nix
@@ -0,0 +1,22 @@
+{ pkgs, ... }:
+pkgs.stdenv.mkDerivation rec {
+ name = "merklecpp";
+
+ src = pkgs.fetchFromGitHub {
+ owner = "microsoft";
+ repo = "merklecpp";
+ rev = "master";
+ sha256 = "jJJ6FEn+AkMknqun0GkXh5DSXsJnFbdE7U8BQ7Dd/Fw=";
+ };
+
+ prePatch = ''
+ '';
+ configurePhase = ''
+ '';
+ buildPhase = ''
+ '';
+ installPhase = ''
+ mkdir -p $out/include
+ mv merklecpp.h $out/include/merklecpp.h
+ '';
+}
diff --git a/flake.lock b/flake.lock
index 735ecfb..622ed64 100644
--- a/flake.lock
+++ b/flake.lock
@@ -35,14 +35,18 @@
},
"nixpkgs": {
"locked": {
- "lastModified": 0,
- "narHash": "sha256-v3rIhsJBOMLR8e/RNWxr828tB+WywYIoajrZKFM+0Gg=",
- "path": "/nix/store/5w3dp0m37794iffsbm9vd9f1xmmhda6i-source",
- "type": "path"
+ "lastModified": 1728888510,
+ "narHash": "sha256-nsNdSldaAyu6PE3YUA+YQLqUDJh+gRbBooMMekZJwvI=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c",
+ "type": "github"
},
"original": {
- "id": "nixpkgs",
- "type": "indirect"
+ "owner": "NixOS",
+ "ref": "nixos-unstable",
+ "repo": "nixpkgs",
+ "type": "github"
}
},
"root": {
diff --git a/flake.nix b/flake.nix
index 2d50b55..d48082d 100644
--- a/flake.nix
+++ b/flake.nix
@@ -12,6 +12,7 @@
# $ nix flake lock --update-input <input> ... --commit-lockfile
#
inputs = {
+ nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# Convenience functions for writing flakes
flake-utils.url = "github:numtide/flake-utils";
# Precisely filter files copied to the nix store
@@ -28,6 +29,10 @@
ocamlPackages = legacyPackages.ocamlPackages;
# Library functions from nixpkgs
lib = legacyPackages.lib;
+ systems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
+ forAllSystems = f: builtins.listToAttrs (map (name: { inherit name; value = f name; }) systems);
+ merklecpp = legacyPackages.callPackage ./deps/merklecpp.nix {};
+ libressl = legacyPackages.callPackage ./deps/libressl.nix {};
# Filtered sources (prevents unecessary rebuilds)
sources = {
@@ -63,26 +68,33 @@
# $ nix build
# $ nix run -- <args?>
#
- default = self.packages.${system}.relational_engine;
+ default = self.packages.${system}.relational_engine;
+
+ relational_engine = ocamlPackages.buildDunePackage {
+ pname = "relational_engine";
+ version = "0.1.0";
+ duneVersion = "3";
+ src = sources.ocaml;
- relational_engine = ocamlPackages.buildDunePackage {
- pname = "relational_engine";
- version = "0.1.0";
- duneVersion = "3";
- src = sources.ocaml;
+ env = {
+ MERKLECPP_INCLUDE_PATH="${merklecpp}/include";
+ LIBRESSL_INCLUDE_PATH="${libressl}/include";
+ LIBRESSL_LIB_PATH="${libressl}/lib";
+ };
- buildInputs = [
- # Ocaml package dependencies needed to build go here.
- ];
+ nativeInputs = [];
- strictDeps = true;
+ buildInputs = [
+ # Ocaml package dependencies needed to build go here.
+ ];
- preBuild = ''
- dune build relational_engine.opam
- '';
- };
- };
+ strictDeps = true;
+ preBuild = ''
+ dune build relational_engine.opam
+ '';
+ };
+ };
# Flake checks
#
# $ nix flake check
@@ -204,7 +216,8 @@
ocamlPackages.utop
# Libraries
ocamlPackages.menhir
- ocamlPackages.batteries
+ ocamlPackages.ctypes
+ ocamlPackages.ctypes-foreign
];
# Tools from packages
diff --git a/lib/dune b/lib/dune
index 5d95cc5..3bc492f 100644
--- a/lib/dune
+++ b/lib/dune
@@ -1,2 +1,10 @@
(library
- (name relational_engine))
+ (name relational_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=}))))
diff --git a/lib/hello.ml b/lib/hello.ml
new file mode 100644
index 0000000..1a3a138
--- /dev/null
+++ b/lib/hello.ml
@@ -0,0 +1 @@
+external hello : unit -> int = "hello_ocaml"
diff --git a/lib/merklecpp_stubs.cpp b/lib/merklecpp_stubs.cpp
new file mode 100644
index 0000000..4ce427e
--- /dev/null
+++ b/lib/merklecpp_stubs.cpp
@@ -0,0 +1,15 @@
+#include <iostream>
+#include <merklecpp.h>
+
+void cpp_normal_function() {
+ std::cout << "HELLO OCAML! :)" << std::endl;
+}
+
+extern "C" {
+#include <caml/mlvalues.h>
+#include <caml/memory.h>
+ extern value hello_ocaml(value unit){
+ cpp_normal_function();
+ return 0;
+ }
+}