dtolnay / cxx

Safe interop between Rust and C++
https://cxx.rs
Apache License 2.0
5.88k stars 333 forks source link

Duplicaste String, Slice etc in cxx.h, and lib.rs.h #1045

Open leejw51crypto opened 2 years ago

leejw51crypto commented 2 years ago

in using multiple bridge files, some classes are redundant. it's surrounded by CXXBRIDGE1_RUST_STRING etc.

is it possible to remove this redundancy?

str4d commented 2 years ago

If you're using cxxbridge to generate lib.rs.h, you need to add the flag --include rust/cxx.h which will notify cxxbridge that you have this header available and not duplicate the definitions in the generated headers or source files.

lukesneeringer commented 2 years ago

I stumbled on this issue and have basically the same need. I'm confused by the answer though -- where exactly do I put this flag?

I tried:

cxx_build::bridge(&filename)
  .flag("--include rust/cxx.h")
  .flag_if_supported("-std=c++17")
  .compile(name.as_str());

...and that didn't work. So I'm missing something...