Search code examples
c++rustdebug-information

When compiling a Rust library with C++ extensions in debug mode, is the C++ code compiled with debug flags too?


I have a Rust project with lot of C++ under the hood, that's built the usual way (I link the c++ files with cc:Build::new() and generate individual bindings to a C API with bindgen::Builder::default()).

I'm trying to understand the source of performance degradation when I build the project with a profile that extends release but has debug=True. Two questions:

  1. Is this profile causing the C++ library to be compiled with debug flags, and if so, what level? I would assume default?

  2. If I wanted to use split-debuginfo (haven't yet figured out what the right way to do this is), AND if the answer to 1. is "no", how would I go about ensuring that the executable with the debug info does have debug flags for the C++ library, while the release executable does not?


Solution

  • Neither cc::Build::new() nor bindgen::Builder::default() read the environment, they both compile and generate everything the same no matter which optimization level you specify (or which profile debug vs release) you build in.

    To build with debuginfo on debug and without it on release you have to check the relevant environment variables (OPT_LEVEL and DEBUG sepecifically) and include the respectively necessary flags for cc.