scipr-lab / libsnark

C++ library for zkSNARKs
Other
1.81k stars 579 forks source link

CMake build's install is a bit iffy #100

Open copumpkin opened 6 years ago

copumpkin commented 6 years ago

I'm not sure which of the scipr-lab repositories to file this against, so apologies if I'm sending this to the wrong place.

I'm packaging libsnark in nixpkgs and have had to patch over several weird issues in the CMake build in order to get a working package out of it.

Here's what I've found so far:

  1. libfqfft's CMakeLists.txt only calls add_subdirectory(libfqfft) if IS_LIBFQFFT_PARENT is set, which libsnark obviously doesn't set. This prevents libfqfft headers from getting installed when installing libsnark.
  2. libzm.a from ate-pairing never gets installed. The depends CMakeLists.txt adds a library for it, but never adds install instructions for it, so libzm.a just sits in the depends build directory and never makes it to the install target. This prevents any downstream libraries depending on libsnark from getting a bunch of symbols they need from ate-pairing, unless they manually depend on the libsnark build directory.
  3. libff's headers (I already filed a bug against that repo, but figured I'd mention it here too) seem to #include "depends/..." stuff from ate-pairing, which breaks horribly when talking about installed libraries. I was able to make it all work by manually installing the ate-pairing headers and patching them to #include angle-bracketed versions of the headers, but that doesn't seem like it should be necessary.

cc @madars

hasinitg commented 6 years ago

Hi @copumpkin,

I also faced the first issue that you have mentioned above, when trying to use libsnark as a library inside a library that I am creating. May I know how did you fix it please? Thank you. Hasini.

howardwu commented 6 years ago

I recommend adding libsnark as a native dependency to your development environment. I've made a tutorial repo that includes a development environment with libsnark imported in this fashion: https://github.com/howardwu/libsnark-tutorial

hasinitg commented 6 years ago

Hi @howardwu,

Thank you for the quick reply.I appreciate it. I have followed your tutorial (as I have mentioned in another issue as well) and it works perfectly fine when I add libsnark as a native dependency. But my goal is to create a library of my own (say libX) which uses libsnark as a library and call libX from a program written in Go. That is why I can not use libnark as a native dependency and looking further for using it as a linked library.

Thank you. Hasini.

howardwu commented 6 years ago

The main issue with linking libsnark is that it makes timely deployment of fixes and updates to libsnark cumbersome. I see how a linked library can be useful in your case. The make install components remain intact in libff and libfqfft. Would adding a boolean flag to link these dependencies in the libsnark compilation process resolve your issue?

hasinitg commented 6 years ago

Yes, that would be very helpful. Thank you.

howardwu commented 6 years ago

I've added a flag, which when toggled, will use installed libff and libfqfft libraries rather than using them as native dependencies. (https://github.com/scipr-lab/libsnark/commit/74eda8ae599b4a5bcf583d23491de47f530d5195)

To use this feature, from the build folder, run:

cmake -DUSE_LINKED_LIBRARIES=ON ..

Note: You will need to make install both libff and libfqfft in accordance to their respective build instructions.

Tested on Ubuntu 14.04.