Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 703
s3rvac Avatar asked Aug 06 '16 11:08

s3rvac


People also ask

What is difference between debug and release build?

Major differences are the debug apk and the release apk: For debug builds the apk will be signed with the default debug signing keys with debug flag enabled. For release apk you will have to explicitly specify the apk to sign with and the debug flag will be turned off so that it cannot be debugged.

What does cargo build -- Release do?

Cargo has two main profiles: the dev profile Cargo uses when you run cargo build and the release profile Cargo uses when you run cargo build --release . The dev profile is defined with good defaults for development, and the release profile has good defaults for release builds.

Is release with debug info slower?

So building with debug information is slower.


2 Answers

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

  • 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
like image 102
Shepmaster Avatar answered Oct 06 '22 21:10

Shepmaster


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

$ RUSTFLAGS=-g cargo build --release 
like image 33
s3rvac Avatar answered Oct 06 '22 19:10

s3rvac