snippetrustCritical
How to get a release build with debugging information when using cargo?
Viewed 0 times
withhowinformationusingreleasedebuggingwhencargobuildget
Problem
The following command
produces a non-optimized build with debugging information. On the contrary,
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.
$ cargo buildproduces a non-optimized build with debugging information. On the contrary,
$ cargo build --releaseproduces 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.
Solution
As of Rust 1.57, Cargo now allows for custom profiles. This allows you to define your own profile that adds debug information:
You can then use that profile when building:
Prior to this version, or if you always wanted to have debugging information, you can modify the
Note that the
See also
Or basically any of the top search results for "rust profiling":
[profile.release-with-debug]
inherits = "release"
debug = trueYou can then use that profile when building:
% cargo build --profile=release-with-debug
Compiling buggin v0.1.0 (/tmp/buggin)
Finished release-with-debug [optimized + debuginfo] target(s) in 0.48s
Prior to this version, or if you always wanted to have debugging information, you can modify the
release profile to include debugging symbols:[profile.release]
debug = trueNote that the
release profile and the bench profile differ.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
Code Snippets
[profile.release-with-debug]
inherits = "release"
debug = true[profile.release]
debug = trueContext
Stack Overflow Q#38803760, score: 133
Revisions (0)
No revisions yet.