Reputation: 10289
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.
Upvotes: 104
Views: 55594
Reputation: 6714
If you want to use an existing profile (such as release) that normally doesn't include debug information, but add debug information just for a single build, you can use the CARGO_PROFILE_<profile_name>_DEBUG
environment variable. Example:
CARGO_PROFILE_RELEASE_DEBUG=true cargo build --release
Upvotes: 7
Reputation: 430681
As of Rust 1.57, Cargo now allows for custom profiles. This allows you to define your own profile that adds debug information:
[profile.release-with-debug]
inherits = "release"
debug = true
You 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 = true
Note that the release
profile and the bench
profile differ.
See also
Or basically any of the top search results for "rust profiling":
Upvotes: 126