How to get a release build with debugging information when using cargo?

谁说我不能喝 提交于 2019-12-03 06:32:30

问题


The following command

$ cargo build

produces a non-optimized build with debugging information. On the contrary,

$ cargo build --release

produces an optimized build without debugging information.

Is there a way of producing an optimized build with debugging information? I need this to get meaningful profiling information.


回答1:


As shown in the Cargo documentation, modify the release profile to include debugging symbols:

[profile.release]
debug = true

See also

  • Can tests be built in release mode using Cargo?
  • How to compile and run an optimized Rust program with overflow checking enabled
  • Does Cargo support custom profiles?

Or basically any of the top search results for "rust profiling":

  • Rust Profiling with Instruments and FlameGraph on OSX: CPU/Time
  • Profiling Rust applications on Linux
  • Profiling rust code with callgrind



回答2:


Another option that I found that does not require changing Cargo.toml is to use the RUSTFLAGS environment variable:

$ RUSTFLAGS=-g cargo build --release


来源:https://stackoverflow.com/questions/38803760/how-to-get-a-release-build-with-debugging-information-when-using-cargo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!