英文:
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:
-
Is this profile causing the C++ library to be compiled with debug flags, and if so, what level? I would assume default?
-
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:
-
Is this profile causing the C++ library to be compiled with debug flags, and if so, what level? I would assume default?
-
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_LEVEL
和DEBUG
),并为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
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论