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

s3rvac picture s3rvac · Aug 6, 2016 · Viewed 18.6k times · Source

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.

Answer

Shepmaster picture Shepmaster · Aug 6, 2016

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

[profile.release]
debug = true

Note that the release profile and the bench profile differ.

See also

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