8

I often want to compile in release mode with debug = true so that I can read the generated assembly a bit easier. I am currently doing this:

[profile.release]
debug = true

but I don't want any debug symbols in my final release build. I'd like to do something like:

[profile.custom]
debug = true
opt-level = 3
rpath = false
lto = true
debug-assertions = false
codegen-units = 1
panic = 'unwind'

And then run

cargo build --custom

I've read the documentation to no avail.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Maik Klein
  • 15,548
  • 27
  • 101
  • 197
  • 3
    You can create a custom Cargo.toml and use it like this: `cargo build --manifest-path ./Cargo-custom.toml`. But it requires you specify dependencies in both files. – wimh Jan 29 '17 at 11:39

2 Answers2

8

As of Rust v1.57.0, the custom profiles feature is now stable.

Add a profile section, specify a base profile to inherit from, and tweak as you see fit:

[profile.production]
inherits = "release"
lto = true

Specify the profile to use via the --profile <name> flag to cargo.

Colonel Thirty Two
  • 23,953
  • 8
  • 45
  • 85
2

Does Cargo support custom profiles?

No, stable releases of Cargo do not support this. It is available as an unstable nightly feature.

If you are using a nightly version of Cargo, you can create custom profiles in your Cargo.toml:

cargo-features = ["named-profiles"]

[profile.release-lto]
inherits = "release"
lto = true

And then use them:

cargo +nightly build --profile release-lto -Z unstable-options
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366