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

huangapple go评论52阅读模式
英文:

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 a 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?

英文:

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?

答案1

得分: 2

以下是翻译好的内容:

"cc::Build::new()"和"bindgen::Builder::default()"都不会读取环境变量,无论你指定了哪个优化级别(或者是调试(debug)还是发布(release)配置),它们都会以相同的方式进行编译和生成。

要在调试(debug)时构建带有调试信息(debuginfo),而在发布(release)时不带调试信息,你需要检查相关的环境变量(特别是OPT_LEVELDEBUG),并为cc包括相应的必要标志。

英文:

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.

huangapple
  • 本文由 发表于 2023年2月8日 15:53:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75382743.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定