Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CBindingGen to conveniently generate bindings to the SEAL C functions #20

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sloede
Copy link
Member

@sloede sloede commented Mar 6, 2021

This is still WIP as it does not fully work yet. The main problem is that the SEAL C headers also include C++ code and thus need to be parsed as C++, which currently seems to prevent CBindingGen from working (see related: analytech-solutions/CBindingGen.jl#27)

@coveralls
Copy link

coveralls commented Mar 6, 2021

Pull Request Test Coverage Report for Build 627256776

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 98.366%

Totals Coverage Status
Change from base Build 625226578: 0.0%
Covered Lines: 662
Relevant Lines: 673

💛 - Coveralls

@krrutkow
Copy link

@sloede I am still awaiting the Julia registry curators to register the package (https://github.com/analytech-solutions/C.jl), but I got this working against a near-zero-effort experimental branch of it (https://github.com/krrutkow/C.jl/tree/cxx-experiment). Here is the branch demonstrating it working (https://github.com/krrutkow/SEAL.jl/tree/use-cjl). C.jl is still very bleeding edge for platforms other than 64-bit Mac/Linux and in Julia 1.5 (1.6 seems stellar though), but it is the replacement for the CBinding*.jl packages.

Example of the new bindings placed directly into src/SEAL.jl:

module libsealc
  #
  cxx`-std=c++17 $(clang_args) -L$(dirname(SEAL_jll.get_libsealc_path())) -lsealc`
  #
  cxx"""
    #include <seal/c/defines.h>
    #include <seal/c/batchencoder.h>
    #include <seal/c/sealcontext.h>
    //
    #include <seal/c/valcheck.h>
    #include <seal/c/version.h>
  """j
end

@sloede
Copy link
Member Author

sloede commented Mar 12, 2021

@krrutkow This is great news! I am looking forward to seeing your new package in action!

In C.jl, will there also be an option to save the generated bindings to a file, like you allowed with CBindingGen.jl? This might be useful in some cases, as e.g. in P4est.jl we discovered that sometimes external libraries depend on "standard" header files that are provided only be external packages (in this case Xcode on macOS). Thus in this case it would be necessary to pre-generate the bindings and then only load the corresponding version locally.

@krrutkow
Copy link

It is possible to store the generated code to file by writing the expression returned by @macroexpand cxx"..." to a file. That is actually how libclang bindings are generated for C.jl, but library paths are baked into that code and need to be sanitized. The C.jl string macros essentially build up a header file, so it is recommended to guard the cxx"..." expressions in if/else blocks to get the desired header file. Something like this (notional) code:

cxx`...`

@static if hasDep
  cxx"#include <dep/header.h>"s
else
  cxx"#include <mock-dep/header.h>"s
end

cxx"""
  #include <mylib/header.h>
"""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants