Skip to content

Commit

Permalink
[WIP] Setup Pybind for placeholder C++ code (#38)
Browse files Browse the repository at this point in the history
* Add Pybind11 as  submodule

* Add placeholder C++ code
  • Loading branch information
codeboy5 authored Apr 6, 2020
1 parent 08e4712 commit a90fecf
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 7 deletions.
7 changes: 5 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "libsnark"]
path = libsnark
[submodule "third_party/pybind11"]
path = third_party/pybind11
url = https://github.com/pybind/pybind11.git
[submodule "third_party/libsnark"]
path = third_party/libsnark
url = https://github.com/scipr-lab/libsnark.git
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required( VERSION 3.3.0 )
project(PyZPK)

add_subdirectory(third_party/pybind11)
pybind11_add_module(PyZPK src/main.cpp)
13 changes: 11 additions & 2 deletions build.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ sudo apt-get install libboost-all-dev
# Updating libprocps to run the cmake (requirement)
sudo apt-get install libprocps-dev

rm -r libsnark
rm -r third_party/libsnark
rm -r third_party/pybind11
#Sync & Initialization of libsnark
git submodule sync
git submodule init
Expand All @@ -15,10 +16,18 @@ git submodule update --init --recursive
git submodule foreach --recursive git reset --hard


cd libsnark
cd third_party/libsnark
mkdir build
cd build

cmake ..

make

cd ../../..
mkdir build
cd build

cmake ..

make
15 changes: 12 additions & 3 deletions build_MacOS.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ brew list cmake || brew install cmake
brew list gmp || brew install gmp
brew list boost || brew install boost
brew list gcc || brew install gcc
bre list pkg-config || brew install pkg-config
brew list pkg-config || brew install pkg-config

# Removing old directory
rm -rf libsnark
rm -rf third_party/libsnark
rm -rf third_party/pybind11

#Sync & Initialization of libsnark
git submodule sync
Expand All @@ -19,7 +20,7 @@ git submodule intit
# Reset all submodules
git submodule foreach --recursive git reset --hard

cd libsnark
cd third_party/libsnark
mkdir build
cd build

Expand All @@ -36,3 +37,11 @@ cmake -DWITH_PROCPS=OFF -DWITH_SUPERCOP=OFF ..


make

cd ../../..
mkdir build
cd build

cmake ..

make
35 changes: 35 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <pybind11/pybind11.h>

int add(int i, int j) {
return i + j;
}

namespace py = pybind11;

PYBIND11_MODULE(PyZPK, m) {
m.doc() = R"pbdoc(
Pybind11 example plugin
-----------------------
.. currentmodule:: PyZPK
.. autosummary::
:toctree: _generate
add
subtract
)pbdoc";

m.def("add", &add, R"pbdoc(
Add two numbers
Some other explanation about the add function.
)pbdoc");

m.def("subtract", [](int i, int j) { return i - j; }, R"pbdoc(
Subtract two numbers
Some other explanation about the subtract function.
)pbdoc");

#ifdef VERSION_INFO
m.attr("__version__") = VERSION_INFO;
#else
m.attr("__version__") = "dev";
#endif
}
1 change: 1 addition & 0 deletions third_party/pybind11
Submodule pybind11 added at 023487

0 comments on commit a90fecf

Please sign in to comment.