dtolnay / cxx

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

Conditional Inclusion from External Libraries #1285

Open cgubbin opened 10 months ago

cgubbin commented 10 months ago

I am trying to compile a C++ module into an existing Rust codebase. My C++ code depends on a large external library, but only uses a small subset of that libraries exposed features.

When I try to compile my code using cxx I get warnings about missing headers. These come from files in the external library, but all the missing headers are conditionally included. For example:

#ifdef WITH_TBB
#  include <tbb/blocked_range.h>
#endif

My library does not set these flags, and does not use the missing modules.

I appreciate that by default cxx has no way of knowing whether these flags are set, so probably can't tell whether I do or do not require these components and is conservatively assuming everything is necessary.

Is there a way to tell cxx certain conditional imports are not required? Or do I need to try and install all the missing modules?