'Does Cargo support custom profiles?

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.



Solution 1:[1]

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

Solution 2:[2]

As of Rust v1.57.0, custom profiles 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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Shepmaster