0

I generated bindings to Microsoft SEAL C++ Library using the rust-bindgen tool.

My config:

// Generate the bindings
let bindings = bindgen::Builder::default()
    .generate_inline_functions(true)
    .derive_default(true)
    .header("./seal/src/seal/seal.h")
    .clang_arg("-I./seal/src/")
    .clang_arg("-std=c++17")
    .clang_arg("-x")
    .clang_arg("c++")
    .opaque_type("std::.*")
    .whitelist_type("seal::.*")
    .whitelist_function("seal::.*")
    .generate()
    .expect("Unable to generate bindings");

The SEAL project is compiled using cc-rs using this config:

let mut build = cc::Build::new();                
    build.cpp(true);                                 
    build.flag_if_supported("-std=c++17");           
    build.flag_if_supported("-march=native");        
    build.flag_if_supported("-fkeep-inline-functions");                                                   
    build.flag_if_supported("-fno-inline-functions");
    let base_path = Path::new("./seal/src/seal/");   
    let util_base_path = Path::new("./seal/src/seal/util/");                                              
    add_cpp_files(&mut build, base_path);            
    add_cpp_files(&mut build, util_base_path);       
    build.include("./seal/src");                     
    build.compile("seal"); 

But afterwards, when creating a new context (this is mostly SEAL-specific) using a static method I get a segmentation fault (SIGSEGV: invalid reference) which, I figured after debugging with gdb comes from when a pointer to a memory pool is copied.

I was able to instantiate multiple regular objects (stuff that didn't have a static constructor) but it doesn't seem to work for SEALContext no matter what parameters I try.

You can access my project seal-rs here. The whole thing is in the build script and clones the repo so cargo test should build and reproduce the error.

My OS is Archlinux 64bit, the compiler used is clang 7.

Belval
  • 1,236
  • 10
  • 17
  • Question should self include everything to answer the question, a link to github is not enough. If you can't include it because it's too big your question is too broad, work on a [mcve]. – Stargateur Jan 23 '19 at 08:12
  • I don't expect anyone to actually build the thing. I thought someone with bindgen experience would be able to tell me if I'm missing a flag. I'll see to it. – Belval Jan 23 '19 at 11:36
  • bindgen is not fully compatible with C++, also note that bindgen do "the best guest", there is a lot of thing not specify in the C or C++ standard, so a lot of thing could be wrong. – Stargateur Jan 23 '19 at 11:47
  • The layout test might fail but the library compiles. You can generate the bindings without layout tests by passing the proper flag. – Andrew Prentice Jan 25 '19 at 03:07
  • The auto-generated tests all passes. It's a custom test that uses the bindings that fails. – Belval Jan 25 '19 at 03:26

1 Answers1

0

This is caused by a bug in the rust-bindgen library as such I will close the question.

Belval
  • 1,236
  • 10
  • 17